lib/yt/annotations/end_screen.rb in yt-annotations-1.4.1 vs lib/yt/annotations/end_screen.rb in yt-annotations-1.4.2

- old
+ new

@@ -2,19 +2,27 @@ module Yt module Annotations # An end screen annotation shows in the last 5 to seconds of the video. class EndScreen < Base - # @param [Hash] data the Hash representation of the XML data returned by + # @param [Hash] json the Hash representation of the XML data returned by # YouTube for each end screen of a video. def initialize(json = {}) - @text = json['title']['runs'][0]['text'] + @text = text_in json @starts_at = json['startMs'].to_i / 1000.0 @ends_at = ends_at_in json @link = to_link json end private + + def text_in(json) + if json['title']['runs'].nil? + json['title']['simpleText'] + else + json['title']['runs'][0]['text'] + end + end def ends_at_in(json) json['endMs'].to_i / 1000.0 end