class Odnoklassniki::REST::Mediatopic::Content
Constants
- AUDIO_LINK_PATTERN
- EMBEDABLE_LINK_PATTERN
- LINK_TYPE
- PHOTO_TYPE
- TEXT_TYPE
- VIDEO_LINK_PATTERN
Attributes
options[RW]
Public Class Methods
new(options={})
click to toggle source
Options: text: string with message to OK (default: ”) images: Array of File (default: []) account_type: :group/:personal (default: :personal)
# File lib/odnoklassniki/rest/mediatopic/content.rb, line 18 def initialize(options={}) @options = Odnoklassniki::Utils._symbolize_kyes(options) end
Public Instance Methods
images()
click to toggle source
# File lib/odnoklassniki/rest/mediatopic/content.rb, line 34 def images @images ||= [uploaded_images].compact end
link()
click to toggle source
# File lib/odnoklassniki/rest/mediatopic/content.rb, line 29 def link @link ||= \ external_url.blank? ? nil : {type: LINK_TYPE, url: external_url} end
message()
click to toggle source
# File lib/odnoklassniki/rest/mediatopic/content.rb, line 22 def message @message ||= { type: TEXT_TYPE, text: (text || '') } end
Private Instance Methods
_symbalize_keys(hash)
click to toggle source
# File lib/odnoklassniki/rest/mediatopic/content.rb, line 86 def _symbalize_keys(hash) symbolized = {} hash.each do |k, v| symbolized[k.to_sym] = v end hash end
embedable_url?(url)
click to toggle source
# File lib/odnoklassniki/rest/mediatopic/content.rb, line 74 def embedable_url?(url) url =~ EMBEDABLE_LINK_PATTERN end
external_url()
click to toggle source
# File lib/odnoklassniki/rest/mediatopic/content.rb, line 78 def external_url return unless resource.external_url? return resource.external_url unless shorten_links? @publication.links.where(original_url: resource.external_url) .first_or_create.short_or_generate end
has_single_embedable_link?()
click to toggle source
# File lib/odnoklassniki/rest/mediatopic/content.rb, line 58 def has_single_embedable_link? has_single_link? && embedable_url?(urls[0]) end
has_single_link?()
click to toggle source
# File lib/odnoklassniki/rest/mediatopic/content.rb, line 62 def has_single_link? urls.count == 1 end
image_id_key()
click to toggle source
# File lib/odnoklassniki/rest/mediatopic/content.rb, line 40 def image_id_key @image_id_key ||= options[:account_type] == :group ? :id : :photoId end
photoalbum()
click to toggle source
# File lib/odnoklassniki/rest/mediatopic/content.rb, line 54 def photoalbum @photoalbum ||= Photoalbum.new(account) end
text()
click to toggle source
# File lib/odnoklassniki/rest/mediatopic/content.rb, line 66 def text @text ||= options[:text] end
uploaded_images()
click to toggle source
# File lib/odnoklassniki/rest/mediatopic/content.rb, line 44 def uploaded_images return if options[:images].blank? photos = options[:images].map do |photo| {image_id_key => photoalbum.upload(photo)} end {type: PHOTO_TYPE, list: photos} end
urls()
click to toggle source
# File lib/odnoklassniki/rest/mediatopic/content.rb, line 70 def urls @urls ||= ::Twitter::Extractor.extract_urls(text) end