Class: Funky::Video
- Inherits:
-
GraphRootNode
- Object
- GraphRootNode
- Funky::Video
- Defined in:
- lib/funky/video.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#counters ⇒ Object
Returns the value of attribute counters.
Attributes inherited from GraphRootNode
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.
-
#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 ⇒ String
The url of Facebook page for the video.
-
#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.
Methods inherited from GraphRootNode
Constructor Details
This class inherits a constructor from Funky::GraphRootNode
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 |
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.
95 96 97 98 |
# File 'lib/funky/video.rb', line 95 def self.find(video_id) counters = @@html_parser.parse html: @@html_page.get(video_id: video_id), 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.
110 111 112 113 |
# File 'lib/funky/video.rb', line 110 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.
82 83 84 85 |
# File 'lib/funky/video.rb', line 82 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.
55 56 57 |
# File 'lib/funky/video.rb', line 55 def comment_count data[:comment_count] end |
#created_time ⇒ DateTime
Returns the created time of the video.
14 15 16 17 |
# File 'lib/funky/video.rb', line 14 def created_time datetime = data[:created_time] DateTime.parse datetime if datetime end |
#description ⇒ String
Returns the description of the video.
20 21 22 |
# File 'lib/funky/video.rb', line 20 def description data[:description] end |
#length ⇒ Float
Returns the length (duration) of the video.
25 26 27 |
# File 'lib/funky/video.rb', line 25 def length data[:length] end |
#like_count ⇒ Integer
Returns the total number of likes for the video.
50 51 52 |
# File 'lib/funky/video.rb', line 50 def like_count data[:like_count] end |
#page_id ⇒ String
Returns the id of Facebook page for the video.
40 41 42 |
# File 'lib/funky/video.rb', line 40 def page_id data.fetch(:from)[:id] end |
#page_name ⇒ String
Returns the name of Facebook page for the video.
35 36 37 |
# File 'lib/funky/video.rb', line 35 def page_name data.fetch(:from)[:name] end |
#page_url ⇒ String
Returns the url of Facebook page for the video.
45 46 47 |
# File 'lib/funky/video.rb', line 45 def page_url "https://www.facebook.com/#{page_id}" end |
#picture ⇒ String
Returns the picture URL of the video.
30 31 32 |
# File 'lib/funky/video.rb', line 30 def picture data[:picture] end |
#share_count ⇒ Integer
Returns the total number of shares for the video.
60 61 62 |
# File 'lib/funky/video.rb', line 60 def share_count data[:share_count] end |
#view_count ⇒ Integer
Returns the total number of views for the video.
65 66 67 |
# File 'lib/funky/video.rb', line 65 def view_count data[:view_count] end |