Class: YoutubeCaptions::Info

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/youtube-captions/info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:) ⇒ Info

Returns a new instance of Info.



8
9
10
# File 'lib/youtube-captions/info.rb', line 8

def initialize(id:)
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/youtube-captions/info.rb', line 7

def id
  @id
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
# File 'lib/youtube-captions/info.rb', line 12

def call
  youtube_html = self.class.get("#{YoutubeCaptions::YOUTUBE_VIDEO_URL}#{id}")
  match_data = youtube_html.match(YoutubeCaptions::CAPTIONABLE_REGEX)
  return raise NoCaptionsAvailableError.new("No captions available") unless match_data

  JSON.parse(match_data[1])
end