Class: SparkApi::Models::Video

Inherits:
Base
  • Object
show all
Extended by:
Subresource
Includes:
Concerns::Destroyable, Concerns::Savable, Media
Defined in:
lib/spark_api/models/video.rb

Constant Summary collapse

SUPPORTED_VIDEO_TYPES =

Some youtube URLS are youtu.be instead of youtube

%w[vimeo youtu].freeze

Constants included from Paginate

Paginate::DEFAULT_PAGE_SIZE

Instance Attribute Summary

Attributes inherited from Base

#attributes, #errors, #parent

Instance Method Summary collapse

Methods included from Subresource

build_subclass, find_by_id, find_by_listing_key, parse_date_start_and_end_times

Methods included from Concerns::Savable

#create!, #params_for_save, #post_data, #save, #save!, #update!, #update_attributes

Methods included from Concerns::Destroyable

#destroy, #destroy!, #destroyed?, included

Methods included from Media

#automatic?, #private?, #public?

Methods inherited from Base

connection, #connection, count, element_name, element_name=, first, get, #id, #initialize, #load, #method_missing, #parse_id, path, #path, #persisted?, prefix, prefix=, #resource_pluralized, #resource_uri, #respond_to?, #to_param, #to_partial_path

Methods included from Paginate

#collect, #paginate, #per_page

Methods included from Dirty

#changed, #changed?, #changed_attributes, #changes, #dirty_attributes, #previous_changes

Constructor Details

This class inherits a constructor from SparkApi::Models::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SparkApi::Models::Base

Instance Method Details

#branded?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/spark_api/models/video.rb', line 12

def branded?
  attributes['Type'] == 'branded'
end

#descriptionObject



24
25
26
# File 'lib/spark_api/models/video.rb', line 24

def description
  attributes['Name']
end

#display_imageObject

gets the thumbnail to be shown on supported (Vimeo and Youtube) videos YouTube provides a predictable url for each video’s images for Vimeo, a get request is necessary



44
45
46
47
48
49
50
51
52
53
# File 'lib/spark_api/models/video.rb', line 44

def display_image
  url = self.video_link
  if url
    if(url.include?('youtube'))
      youtube_thumbnail_url
    else 
      vimeo_thumbnail_url
    end
  end
end

#is_supported_type?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
# File 'lib/spark_api/models/video.rb', line 31

def is_supported_type?
  # Unfortunately there are so many formats of vimeo videos that we canot support all vimeo videos
  # Therefore, we need to do a little more checking here and validate that we can get video codes out of the urls
  (self.ObjectHtml.include?('youtu') && youtube_video_code.present?) || (self.ObjectHtml.include?('vimeo') && vimeo_video_code.present?)
end

#is_valid_iframe?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/spark_api/models/video.rb', line 37

def is_valid_iframe?
  self.ObjectHtml.include?('<iframe') && self.ObjectHtml.include?('</iframe>')
end

#unbranded?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/spark_api/models/video.rb', line 16

def unbranded?
  attributes['Type'] == 'unbranded'
end

#urlObject



20
21
22
# File 'lib/spark_api/models/video.rb', line 20

def url
  attributes['ObjectHtml']
end


55
56
57
58
59
60
61
62
63
# File 'lib/spark_api/models/video.rb', line 55

def video_link
  return nil unless is_supported_type?

  if self.ObjectHtml.include?('youtu')
      youtube_link
  elsif self.ObjectHtml.include?('vimeo')
      vimeo_link
  end
end