class Funky::Video

Attributes

counters[RW]

Public Class Methods

find(video_id) click to toggle source

Fetches the data from Facebook's HTML and instantiates the data into a single Funky::Video object. It can accept one only video ID.

@example Getting a video

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

@return [Funky::Video] the data scraped from Facebook's HTML

and encapsulated into a Funky::Video object.
# 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
  raise CountersNotFound, "View count not found with video ID #{video_id}" unless counters[:view_count]
  new counters.merge(id: video_id)
end
find_by_url!(url) click to toggle source

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.

@example Getting a video by url

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

@return [Funky::Video] the data scraped from Facebook's HTML

and encapsulated into a Funky::Video object.
# File lib/funky/video.rb, line 132
def self.find_by_url!(url)
  url = URL.new(url)
  find(url.video_id)
end
where(id:) click to toggle source

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.

@example Getting one video

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

@example Getting multiple videos

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

@return [Array<Funky::Video>] multiple instances of Funky::Video objects

containing data obtained by Facebook's APIs.
# File lib/funky/video.rb, line 103
def self.where(id:)
  return nil unless id
  instantiate_collection(fetch_and_parse_data Array(id))
end

Private Class Methods

fields() click to toggle source
# File lib/funky/video.rb, line 139
def self.fields
  [
    'created_time',
    'description',
    'length',
    'from',
    'picture'
  ]
end

Public Instance Methods

comment_count() click to toggle source

@return [Integer] the total number of comments for the video.

# File lib/funky/video.rb, line 76
def comment_count
  data[:comment_count]
end
count_comments() click to toggle source

@return [Integer] the total number of comments for the video.

# File lib/funky/video.rb, line 41
def count_comments
  data[:comments][:summary][:total_count]
end
count_likes() click to toggle source

see developers.facebook.com/docs/graph-api/reference/video/ @return [Integer] the total number of likes for the video.

# File lib/funky/video.rb, line 36
def count_likes
  data[:likes][:summary][:total_count]
end
count_reactions() click to toggle source

@return [Integer] the total number of reactions for the video.

# File lib/funky/video.rb, line 46
def count_reactions
  data[:reactions][:summary][:total_count]
end
created_time() click to toggle source

@return [DateTime] the created time of the video.

# File lib/funky/video.rb, line 14
def created_time
  datetime = data[:created_time]
  DateTime.parse datetime if datetime
end
description() click to toggle source

@return [String] the description of the video.

# File lib/funky/video.rb, line 20
def description
  data[:description].to_s
end
length() click to toggle source

@return [Float] the length (duration) of the video.

# File lib/funky/video.rb, line 25
def length
  data[:length]
end
like_count() click to toggle source

@return [Integer] the total number of likes for the video.

# File lib/funky/video.rb, line 71
def like_count
  data[:like_count]
end
page_id() click to toggle source

@return [String] the id of Facebook page for the video.

# File lib/funky/video.rb, line 61
def page_id
  data.fetch(:from)[:id]
end
page_name() click to toggle source

@return [String] the name of Facebook page for the video.

# File lib/funky/video.rb, line 56
def page_name
  data.fetch(:from)[:name]
end
page_url() click to toggle source

@return [String] the url of Facebook page for the video.

# File lib/funky/video.rb, line 66
def page_url
  "https://www.facebook.com/#{page_id}"
end
picture() click to toggle source

@return [String] the picture URL of the video.

# File lib/funky/video.rb, line 51
def picture
  data[:picture]
end
share_count() click to toggle source

@return [Integer] the total number of shares for the video.

# File lib/funky/video.rb, line 81
def share_count
  data[:share_count]
end
title() click to toggle source

@return [String] the title of the video.

# File lib/funky/video.rb, line 30
def title
  data[:title].to_s
end
view_count() click to toggle source

@return [Integer] the total number of views for the video.

# File lib/funky/video.rb, line 86
def view_count
  data[:view_count]
end