Class: Funky::Video

Inherits:
Object
  • Object
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Video

Returns a new instance of Video


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

def initialize(data)
  @data = data
end

Instance Attribute Details

#countersObject

Returns the value of attribute counters


7
8
9
# File 'lib/funky/video.rb', line 7

def counters
  @counters
end

#dataObject (readonly)

Returns the value of attribute data


6
7
8
# File 'lib/funky/video.rb', line 6

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.

Examples:

Getting a video

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

Returns:

  • (Funky::Video)

    the data scraped from Facebook's HTML and encapsulated into a Funky::Video object.


88
89
90
91
# File 'lib/funky/video.rb', line 88

def self.find(video_id)
  counters = @@html_parser.parse html: @@html_page.get(video_id: video_id)
  new counters.merge(id: 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>]

Returns:

  • (Array<Funky::Video>)

    multiple instances of Funky::Video objects containing data obtained by Facebook's APIs.


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

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

Instance Method Details

#comment_countInteger

Returns the total number of comments for the video.

Returns:

  • (Integer)

    the total number of comments for the video.


48
49
50
# File 'lib/funky/video.rb', line 48

def comment_count
  data[:comment_count]
end

#created_timeDateTime

Returns the created time of the video.

Returns:

  • (DateTime)

    the created time of the video.


22
23
24
25
# File 'lib/funky/video.rb', line 22

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

#descriptionString

Returns the description of the video.

Returns:

  • (String)

    the description of the video.


28
29
30
# File 'lib/funky/video.rb', line 28

def description
  data[:description]
end

#idString

Returns the video ID.

Returns:

  • (String)

    the video ID.


17
18
19
# File 'lib/funky/video.rb', line 17

def id
  data[:id]
end

#lengthFloat

Returns the length (duration) of the video.

Returns:

  • (Float)

    the length (duration) of the video.


33
34
35
# File 'lib/funky/video.rb', line 33

def length
  data[:length]
end

#like_countInteger

Returns the total number of likes for the video.

Returns:

  • (Integer)

    the total number of likes for the video.


43
44
45
# File 'lib/funky/video.rb', line 43

def like_count
  data[:like_count]
end

#pictureString

Returns the picture URL of the video.

Returns:

  • (String)

    the picture URL of the video.


38
39
40
# File 'lib/funky/video.rb', line 38

def picture
  data[:picture]
end

#share_countInteger

Returns the total number of shares for the video.

Returns:

  • (Integer)

    the total number of shares for the video.


53
54
55
# File 'lib/funky/video.rb', line 53

def share_count
  data[:share_count]
end

#view_countInteger

Returns the total number of views for the video.

Returns:

  • (Integer)

    the total number of views for the video.


58
59
60
# File 'lib/funky/video.rb', line 58

def view_count
  data[:view_count]
end