Module: TwitchAPI
- Defined in:
- lib/twitchy/twitch_api.rb
Constant Summary collapse
- @@PREFIX =
"https://api.twitch.tv/kraken/"
Class Method Summary collapse
- .get_follow_data(user) ⇒ Object
- .get_stream_data(streamer) ⇒ Object
- .get_stream_status(streamers) ⇒ Object
- .get_streamers_for_game(game, limit: 10, offset: 0) ⇒ Object
- .get_videos(streamer, limit: 10, offset: 0, highlights: false) ⇒ Object
Class Method Details
.get_follow_data(user) ⇒ Object
8 9 10 11 12 |
# File 'lib/twitchy/twitch_api.rb', line 8 def self.get_follow_data(user) catch_exception(OpenURI::HTTPError) do get_as_struct("users/#{user}/follows/channels").follows end end |
.get_stream_data(streamer) ⇒ Object
23 24 25 26 27 |
# File 'lib/twitchy/twitch_api.rb', line 23 def self.get_stream_data(streamer) catch_exception(OpenURI::HTTPError) do get_as_struct("streams/#{streamer}").stream end end |
.get_stream_status(streamers) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/twitchy/twitch_api.rb', line 14 def self.get_stream_status(streamers) query = "streams?channel=#{streamers.join(",")}" catch_exception(OpenURI::HTTPError, default: {}) do get_as_struct(query).streams.map do |s| [s.channel.name, s] end.to_h end end |
.get_streamers_for_game(game, limit: 10, offset: 0) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/twitchy/twitch_api.rb', line 40 def self.get_streamers_for_game(game, limit: 10, offset: 0) catch_exception(OpenURI::HTTPError) do query = "streams?game=#{URI.encode(game)}&limit=#{limit}&offset=#{offset}" get_as_struct(query).streams.map{|s| s.channel.name} end end |
.get_videos(streamer, limit: 10, offset: 0, highlights: false) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/twitchy/twitch_api.rb', line 29 def self.get_videos(streamer, limit: 10, offset: 0, highlights: false) catch_exception(OpenURI::HTTPError) do query = "channels/#{streamer}/videos"\ "?broadcasts=#{!highlights}"\ "&limit=#{limit}&offset=#{offset}" get_as_struct(query).videos.each do |v| v.recorded_at = DateTime.parse(v.recorded_at) end end end |