Class: Funky::Video
- Inherits:
-
Object
- Object
- Funky::Video
- Defined in:
- lib/funky/video.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#counters ⇒ Object
Returns the value of attribute counters.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
-
.find(video_id) ⇒ Funky::Video
Fetches the data from Facebook’s HTML and instantiates the data into a single Funky::Video object.
-
.find_by_url!(url) ⇒ Funky::Video
Similar to #find, but it finds the video by url instead of video id.
-
.where(id:) ⇒ Array<Funky::Video>
Fetches the data from Facebook’s APIs and instantiates the data into an Array of Funky::Video objects.
Instance Method Summary collapse
-
#comment_count ⇒ Integer
The total number of comments for the video.
-
#created_time ⇒ DateTime
The created time of the video.
-
#description ⇒ String
The description of the video.
-
#id ⇒ String
The video ID.
-
#initialize(data) ⇒ Video
constructor
A new instance of Video.
-
#length ⇒ Float
The length (duration) of the video.
-
#like_count ⇒ Integer
The total number of likes for the video.
-
#page_id ⇒ String
The id of Facebook page for the video.
-
#page_name ⇒ String
The name of Facebook page for the video.
- #page_url ⇒ Object
-
#picture ⇒ String
The picture URL of the video.
-
#share_count ⇒ Integer
The total number of shares for the video.
-
#view_count ⇒ Integer
The total number of views for the video.
Constructor Details
#initialize(data) ⇒ Video
Returns a new instance of Video.
13 14 15 |
# File 'lib/funky/video.rb', line 13 def initialize(data) @data = data end |
Instance Attribute Details
#counters ⇒ Object
Returns the value of attribute counters.
8 9 10 |
# File 'lib/funky/video.rb', line 8 def counters @counters end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/funky/video.rb', line 7 def data @data end |
Class Method Details
.find(video_id) ⇒ Funky::Video
Fetches the data from Facebook’s HTML and instantiates the data into a single Funky::Video object. It can accept one only video ID.
103 104 105 106 |
# File 'lib/funky/video.rb', line 103 def self.find(video_id) counters = @@html_parser.parse html: @@html_page.get(video_id: video_id) new counters.merge(id: video_id) end |
.find_by_url!(url) ⇒ Funky::Video
Similar to #find, but it finds the video by url instead of video id. Fetches the data from Facebook’s HTML and instantiates the data into a single Funky::Video object. It can accept one only video url.
118 119 120 121 |
# File 'lib/funky/video.rb', line 118 def self.find_by_url!(url) url = URL.new(url) find(url.video_id) end |
.where(id:) ⇒ Array<Funky::Video>
Fetches the data from Facebook’s APIs and instantiates the data into an Array of Funky::Video objects. It can accept one video ID or an array of multiple video IDs.
90 91 92 93 |
# File 'lib/funky/video.rb', line 90 def self.where(id:) return nil unless id instantiate_collection(fetch_and_parse_data Array(id)) end |
Instance Method Details
#comment_count ⇒ Integer
Returns the total number of comments for the video.
63 64 65 |
# File 'lib/funky/video.rb', line 63 def comment_count data[:comment_count] end |
#created_time ⇒ DateTime
Returns the created time of the video.
23 24 25 26 |
# File 'lib/funky/video.rb', line 23 def created_time datetime = data[:created_time] DateTime.parse datetime if datetime end |
#description ⇒ String
Returns the description of the video.
29 30 31 |
# File 'lib/funky/video.rb', line 29 def description data[:description] end |
#id ⇒ String
Returns the video ID.
18 19 20 |
# File 'lib/funky/video.rb', line 18 def id data[:id] end |
#length ⇒ Float
Returns the length (duration) of the video.
34 35 36 |
# File 'lib/funky/video.rb', line 34 def length data[:length] end |
#like_count ⇒ Integer
Returns the total number of likes for the video.
58 59 60 |
# File 'lib/funky/video.rb', line 58 def like_count data[:like_count] end |
#page_id ⇒ String
Returns the id of Facebook page for the video.
49 50 51 |
# File 'lib/funky/video.rb', line 49 def page_id data.fetch(:from)[:id] end |
#page_name ⇒ String
Returns the name of Facebook page for the video.
44 45 46 |
# File 'lib/funky/video.rb', line 44 def page_name data.fetch(:from)[:name] end |
#page_url ⇒ Object
53 54 55 |
# File 'lib/funky/video.rb', line 53 def page_url "https://www.facebook.com/#{page_id}" end |
#picture ⇒ String
Returns the picture URL of the video.
39 40 41 |
# File 'lib/funky/video.rb', line 39 def picture data[:picture] end |
#share_count ⇒ Integer
Returns the total number of shares for the video.
68 69 70 |
# File 'lib/funky/video.rb', line 68 def share_count data[:share_count] end |
#view_count ⇒ Integer
Returns the total number of views for the video.
73 74 75 |
# File 'lib/funky/video.rb', line 73 def view_count data[:view_count] end |