Class: Funky::Video

Inherits:
GraphRootNode show all
Defined in:
lib/funky/video.rb

Constant Summary collapse

@@html_page =
HTML::Page.new
@@html_parser =
HTML::Parser.new

Instance Attribute Summary collapse

Attributes inherited from GraphRootNode

#data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GraphRootNode

#id, #initialize

Constructor Details

This class inherits a constructor from Funky::GraphRootNode

Instance Attribute Details

#countersObject

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.

Examples:

Getting a video

Funky::Video.find('10153834590672139') # => #<Funky::Video>


116
117
118
119
# File 'lib/funky/video.rb', line 116

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.

Examples:

Getting a video by url

url = 'https://www.facebook.com/video.php?v=203203106739575'
Funky::Video.find_by_url!(url) # => #<Funky::Video>


131
132
133
134
# File 'lib/funky/video.rb', line 131

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.

Examples:

Getting one video

id = '10153834590672139'
Funky::Video.where(id: id) # => [#<Funky::Video>]

Getting multiple videos

ids = ['10154439119663508', '10153834590672139']
Funky::Video.where(id: ids) # => [#<Funky::Video>, #<Funky::Video>]


103
104
105
106
# File 'lib/funky/video.rb', line 103

def self.where(id:)
  return nil unless id
  instantiate_collection(fetch_and_parse_data Array(id))
end

Instance Method Details

#comment_countInteger



76
77
78
# File 'lib/funky/video.rb', line 76

def comment_count
  data[:comment_count]
end

#count_commentsInteger



41
42
43
# File 'lib/funky/video.rb', line 41

def count_comments
  data[:comments][:summary][:total_count]
end

#count_likesInteger



36
37
38
# File 'lib/funky/video.rb', line 36

def count_likes
  data[:likes][:summary][:total_count]
end

#count_reactionsInteger



46
47
48
# File 'lib/funky/video.rb', line 46

def count_reactions
  data[:reactions][:summary][:total_count]
end

#created_timeDateTime



14
15
16
17
# File 'lib/funky/video.rb', line 14

def created_time
  datetime = data[:created_time]
  DateTime.parse datetime if datetime
end

#descriptionString



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

def description
  data[:description].to_s
end

#lengthFloat



25
26
27
# File 'lib/funky/video.rb', line 25

def length
  data[:length]
end

#like_countInteger



71
72
73
# File 'lib/funky/video.rb', line 71

def like_count
  data[:like_count]
end

#page_idString



61
62
63
# File 'lib/funky/video.rb', line 61

def page_id
  data.fetch(:from)[:id]
end

#page_nameString



56
57
58
# File 'lib/funky/video.rb', line 56

def page_name
  data.fetch(:from)[:name]
end

#page_urlString



66
67
68
# File 'lib/funky/video.rb', line 66

def page_url
  "https://www.facebook.com/#{page_id}"
end

#pictureString



51
52
53
# File 'lib/funky/video.rb', line 51

def picture
  data[:picture]
end

#share_countInteger



81
82
83
# File 'lib/funky/video.rb', line 81

def share_count
  data[:share_count]
end

#titleString



30
31
32
# File 'lib/funky/video.rb', line 30

def title
  data[:title].to_s
end

#view_countInteger



86
87
88
# File 'lib/funky/video.rb', line 86

def view_count
  data[:view_count]
end