Class: Twitch
- Inherits:
-
Object
- Object
- Twitch
- Defined in:
- lib/twitch.rb
Instance Method Summary collapse
- #auth(code) ⇒ Object
- #editChannel(status, game) ⇒ Object
-
#getChannel(channel) ⇒ Object
Channel.
-
#getChannelVideos(channel, options = {}) ⇒ Object
Videos.
- #getFeaturedStreams(options = {}) ⇒ Object
- #getLink ⇒ Object
-
#getStream(stream_name) ⇒ Object
Streams.
- #getStreams(options = {}) ⇒ Object
- #getSummeraizedStreams(options = {}) ⇒ Object
- #getTeam(team_id) ⇒ Object
-
#getTeams ⇒ Object
Teams.
-
#getTopGames(options = {}) ⇒ Object
Games.
-
#getUser(user) ⇒ Object
User.
- #getVideo(video_id) ⇒ Object
- #getYourChannel ⇒ Object
- #getYourFollowedStreams ⇒ Object
- #getYourUser ⇒ Object
-
#initialize(options = {}) ⇒ Twitch
constructor
A new instance of Twitch.
- #runCommercial(channel, length = 30) ⇒ Object
- #searchGames(options = {}) ⇒ Object
-
#searchStreams(options = {}) ⇒ Object
Search.
Constructor Details
#initialize(options = {}) ⇒ Twitch
Returns a new instance of Twitch.
5 6 7 8 9 10 11 12 13 |
# File 'lib/twitch.rb', line 5 def initialize( = {}) @client_id = [:client_id] || nil @secret_key = [:secret_key] || nil @redirect_uri = [:redirect_uri] || nil @scope = [:scope] || nil @access_token = [:access_token] || nil @base_url = "https://api.twitch.tv/kraken" end |
Instance Method Details
#auth(code) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/twitch.rb', line 23 def auth(code) path = "/oauth2/token" url = @base_url + path post(url, { :client_id => @client_id, :client_secret => @secret_key, :grant_type => "authorization_code", :redirect_uri => @redirect_uri, :code => code }) end |
#editChannel(status, game) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/twitch.rb', line 80 def editChannel(status, game) return false if !@access_token path = "/channels/dustinlakin/?oauth_token=#{@access_token}" url = @base_url + path data = { :channel =>{ :game => game, :status => status } } put(url, data) end |
#getChannel(channel) ⇒ Object
Channel
67 68 69 70 71 |
# File 'lib/twitch.rb', line 67 def getChannel(channel) path = "/channels/" url = @base_url + path + channel; get(url) end |
#getChannelVideos(channel, options = {}) ⇒ Object
Videos
170 171 172 173 174 175 |
# File 'lib/twitch.rb', line 170 def getChannelVideos(channel, = {}) query = buildQueryString() path = "/channels/#{channel}/videos" url = @base_url + path + query get(url) end |
#getFeaturedStreams(options = {}) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/twitch.rb', line 123 def getFeaturedStreams( = {}) query = buildQueryString() path = "/streams/featured" url = @base_url + path + query get(url) end |
#getLink ⇒ Object
17 18 19 20 21 |
# File 'lib/twitch.rb', line 17 def getLink scope = "" @scope.each { |s| scope += s + '+' } link = "https://api.twitch.tv/kraken/oauth2/authorize?response_type=code&client_id=#{@client_id}&redirect_uri=#{@redirect_uri}&scope=#{scope}" end |
#getStream(stream_name) ⇒ Object
Streams
104 105 106 107 108 |
# File 'lib/twitch.rb', line 104 def getStream(stream_name) path = "/stream/#{stream_name}" url = @base_url + path; get(url) end |
#getStreams(options = {}) ⇒ Object
116 117 118 119 120 121 |
# File 'lib/twitch.rb', line 116 def getStreams( = {}) query = buildQueryString() path = "/streams" url = @base_url + path + query get(url) end |
#getSummeraizedStreams(options = {}) ⇒ Object
130 131 132 133 134 135 |
# File 'lib/twitch.rb', line 130 def getSummeraizedStreams( = {}) query = buildQueryString() path = "/streams/summary" url = @base_url + path + query get(url) end |
#getTeam(team_id) ⇒ Object
59 60 61 62 63 |
# File 'lib/twitch.rb', line 59 def getTeam(team_id) path = "/teams/" url = @base_url + path + team_id; get(url) end |
#getTeams ⇒ Object
Teams
52 53 54 55 56 |
# File 'lib/twitch.rb', line 52 def getTeams path = "/teams/" url = @base_url + path; get(url) end |
#getTopGames(options = {}) ⇒ Object
Games
145 146 147 148 149 150 |
# File 'lib/twitch.rb', line 145 def getTopGames( = {}) query = buildQueryString() path = "/games/top" url = @base_url + path + query get(url) end |
#getUser(user) ⇒ Object
User
37 38 39 40 41 |
# File 'lib/twitch.rb', line 37 def getUser(user) path = "/users/" url = @base_url + path + user; get(url) end |
#getVideo(video_id) ⇒ Object
177 178 179 180 181 |
# File 'lib/twitch.rb', line 177 def getVideo(video_id) path = "/videos/#{video_id}/" url = @base_url + path get(url) end |
#getYourChannel ⇒ Object
73 74 75 76 77 78 |
# File 'lib/twitch.rb', line 73 def getYourChannel return false if !@access_token path = "/channel?oauth_token=#{@access_token}" url = @base_url + path; get(url) end |
#getYourFollowedStreams ⇒ Object
137 138 139 140 141 |
# File 'lib/twitch.rb', line 137 def getYourFollowedStreams path = "/streams/followed?oauth_token=#{@access_token}" url = @base_url + path get(url) end |
#getYourUser ⇒ Object
43 44 45 46 47 48 |
# File 'lib/twitch.rb', line 43 def getYourUser return false if !@access_token path = "/user?oauth_token=#{@access_token}" url = @base_url + path get(url) end |
#runCommercial(channel, length = 30) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/twitch.rb', line 93 def runCommercial(channel, length = 30) return false if !@access_token path = "/channels/#{channel}/commercial?oauth_token=#{@access_token}" url = @base_url + path post(url, { :length => length }) end |
#searchGames(options = {}) ⇒ Object
161 162 163 164 165 166 |
# File 'lib/twitch.rb', line 161 def searchGames( = {}) query = buildQueryString() path = "/search/games" url = @base_url + path + query get(url) end |
#searchStreams(options = {}) ⇒ Object
Search
154 155 156 157 158 159 |
# File 'lib/twitch.rb', line 154 def searchStreams( = {}) query = buildQueryString() path = "/search/streams" url = @base_url + path + query get(url) end |