Class: Twitch::Client
Constant Summary
Constants included
from Adapters
Adapters::DEFAULT_ADAPTER
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#auth(code) ⇒ Object
-
#blockUser(username, target) ⇒ Object
-
#editChannel(channel, status, game) ⇒ Object
TODO: Add ability to set delay, which is only available for partered channels.
-
#followChannel(username, channel) ⇒ Object
-
#getBadges(channel) ⇒ Object
-
#getBlocks(username, options = {}) ⇒ Object
-
#getChannel(channel) ⇒ Object
-
#getChannelTeams(channel) ⇒ Object
-
#getChannelVideos(channel, options = {}) ⇒ Object
-
#getChatLinks(channel) ⇒ Object
-
#getEditors(channel) ⇒ Object
-
#getEmoticons ⇒ Object
-
#getFeaturedStreams(options = {}) ⇒ Object
-
#getFollowed(username) ⇒ Object
-
#getFollowing(channel) ⇒ Object
-
#getFollowStatus(username, channel) ⇒ Object
-
#getIngests ⇒ Object
-
#getLink ⇒ Object
-
#getRoot ⇒ Object
-
#getStream(stream_name) ⇒ Object
-
#getStreams(options = {}) ⇒ Object
-
#getSubscribed(channel) ⇒ Object
-
#getSummeraizedStreams(options = {}) ⇒ Object
-
#getTeam(team_id) ⇒ Object
-
#getTeams ⇒ Object
-
#getTopGames(options = {}) ⇒ Object
-
#getTopVideos(options = {}) ⇒ Object
-
#getUser(user) ⇒ Object
-
#getVideo(video_id) ⇒ Object
-
#getYourChannel ⇒ Object
-
#getYourFollowedStreams(options = {}) ⇒ Object
-
#getYourFollowedVideos(options = {}) ⇒ Object
-
#getYourUser ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#isSubscribed(username, channel, options = {}) ⇒ Object
-
#isSubscribedToChannel(username, channel) ⇒ Object
-
#resetKey(channel) ⇒ Object
-
#runCommercial(channel, length = 30) ⇒ Object
-
#searchChannels(options = {}) ⇒ Object
-
#searchGames(options = {}) ⇒ Object
-
#searchStreams(options = {}) ⇒ Object
-
#unblockUser(username, target) ⇒ Object
Methods included from Adapters
#get_adapter
Methods included from Request
#buildQueryString, #delete, #get, #post, #put
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/twitch/client.rb', line 9
def initialize(options = {})
@client_id = options[:client_id] || nil
@secret_key = options[:secret_key] || nil
@redirect_uri = options[:redirect_uri] || nil
@scope = options[:scope] || nil
@access_token = options[:access_token] || nil
@adapter = get_adapter(options[:adapter] || nil)
@base_url = "https://api.twitch.tv/kraken"
end
|
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
22
23
24
|
# File 'lib/twitch/client.rb', line 22
def adapter
@adapter
end
|
#base_url ⇒ Object
Returns the value of attribute base_url.
21
22
23
|
# File 'lib/twitch/client.rb', line 21
def base_url
@base_url
end
|
#redirect_url ⇒ Object
Returns the value of attribute redirect_url.
21
22
23
|
# File 'lib/twitch/client.rb', line 21
def redirect_url
@redirect_url
end
|
#scope ⇒ Object
Returns the value of attribute scope.
21
22
23
|
# File 'lib/twitch/client.rb', line 21
def scope
@scope
end
|
Instance Method Details
#auth(code) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/twitch/client.rb', line 36
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
|
#blockUser(username, target) ⇒ Object
272
273
274
275
276
277
|
# File 'lib/twitch/client.rb', line 272
def blockUser(username, target)
return false if !@access_token
path = "/users/#{username}/blocks/#{target}?oauth_token=#{@access_token}"
url = @base_url + path
put(url)
end
|
#editChannel(channel, status, game) ⇒ Object
TODO: Add ability to set delay, which is only available for partered channels
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/twitch/client.rb', line 101
def editChannel(channel, status, game)
return false if !@access_token
path = "/channels/#{channel}/?oauth_token=#{@access_token}"
url = @base_url + path
data = {
:channel =>{
:game => game,
:status => status
}
}
put(url, data)
end
|
#followChannel(username, channel) ⇒ Object
121
122
123
124
125
126
|
# File 'lib/twitch/client.rb', line 121
def followChannel(username, channel)
return false if !@access_token
path = "/users/#{username}/follows/channels/#{channel}?oauth_token=#{@access_token}"
url = @base_url + path
put(url)
end
|
#getBadges(channel) ⇒ Object
294
295
296
297
298
|
# File 'lib/twitch/client.rb', line 294
def getBadges(channel)
path = "/chat/#{channel}/badges"
url = @base_url + path;
get(url)
end
|
#getBlocks(username, options = {}) ⇒ Object
265
266
267
268
269
270
|
# File 'lib/twitch/client.rb', line 265
def getBlocks(username, options = {})
query = buildQueryString(options)
path = "/users/#{username}/blocks?oauth_token=#{@access_token}"
url = @base_url + path + query
get(url)
end
|
#getChannel(channel) ⇒ Object
80
81
82
83
84
|
# File 'lib/twitch/client.rb', line 80
def getChannel(channel)
path = "/channels/"
url = @base_url + path + channel;
get(url)
end
|
#getChannelTeams(channel) ⇒ Object
144
145
146
147
148
149
|
# File 'lib/twitch/client.rb', line 144
def getChannelTeams(channel)
return false if !@access_token
path = "/channels/#{channel}/teams?oauth_token=#{@access_token}"
url = @base_url + path;
get(url)
end
|
#getChannelVideos(channel, options = {}) ⇒ Object
228
229
230
231
232
233
|
# File 'lib/twitch/client.rb', line 228
def getChannelVideos(channel, options = {})
query = buildQueryString(options)
path = "/channels/#{channel}/videos"
url = @base_url + path + query
get(url)
end
|
#getChatLinks(channel) ⇒ Object
288
289
290
291
292
|
# File 'lib/twitch/client.rb', line 288
def getChatLinks(channel)
path = "/chat/"
url = @base_url + path + channel;
get(url)
end
|
#getEditors(channel) ⇒ Object
93
94
95
96
97
98
|
# File 'lib/twitch/client.rb', line 93
def getEditors(channel)
return false if !@access_token
path = "/channels/#{channel}/editors?oauth_token=#{@access_token}"
url = @base_url + path;
get(url)
end
|
#getEmoticons ⇒ Object
300
301
302
303
304
|
# File 'lib/twitch/client.rb', line 300
def getEmoticons()
path = "/chat/emoticons"
url = @base_url + path;
get(url)
end
|
#getFeaturedStreams(options = {}) ⇒ Object
172
173
174
175
176
177
|
# File 'lib/twitch/client.rb', line 172
def getFeaturedStreams(options = {})
query = buildQueryString(options)
path = "/streams/featured"
url = @base_url + path + query
get(url)
end
|
#getFollowed(username) ⇒ Object
314
315
316
317
318
|
# File 'lib/twitch/client.rb', line 314
def getFollowed(username)
path = "/users/#{username}/follows/channels"
url = @base_url + path;
get(url)
end
|
#getFollowing(channel) ⇒ Object
308
309
310
311
312
|
# File 'lib/twitch/client.rb', line 308
def getFollowing(channel)
path = "/channels/#{channel}/follows"
url = @base_url + path;
get(url)
end
|
#getFollowStatus(username, channel) ⇒ Object
320
321
322
323
324
|
# File 'lib/twitch/client.rb', line 320
def getFollowStatus(username, channel)
path = "/users/#{username}/follows/channels/#{channel}/?oauth_token=#{@access_token}"
url = @base_url + path;
get(url)
end
|
#getIngests ⇒ Object
328
329
330
331
332
|
# File 'lib/twitch/client.rb', line 328
def getIngests()
path = "/ingests"
url = @base_url + path
get(url)
end
|
#getLink ⇒ Object
30
31
32
33
34
|
# File 'lib/twitch/client.rb', line 30
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
|
#getRoot ⇒ Object
336
337
338
339
340
|
# File 'lib/twitch/client.rb', line 336
def getRoot()
path = "/?oauth_token=#{@access_token}"
url = @base_url + path
get(url)
end
|
#getStream(stream_name) ⇒ Object
153
154
155
156
157
|
# File 'lib/twitch/client.rb', line 153
def getStream(stream_name)
path = "/stream/#{stream_name}"
url = @base_url + path;
get(url)
end
|
#getStreams(options = {}) ⇒ Object
165
166
167
168
169
170
|
# File 'lib/twitch/client.rb', line 165
def getStreams(options = {})
query = buildQueryString(options)
path = "/streams"
url = @base_url + path + query
get(url)
end
|
#getSubscribed(channel) ⇒ Object
344
345
346
347
348
349
|
# File 'lib/twitch/client.rb', line 344
def getSubscribed(channel)
return false if !@access_token
path = "/channels/#{channel}/subscriptions?oauth_token=#{@access_token}"
url = @base_url + path
get(url)
end
|
#getSummeraizedStreams(options = {}) ⇒ Object
179
180
181
182
183
184
|
# File 'lib/twitch/client.rb', line 179
def getSummeraizedStreams(options = {})
query = buildQueryString(options)
path = "/streams/summary"
url = @base_url + path + query
get(url)
end
|
#getTeam(team_id) ⇒ Object
72
73
74
75
76
|
# File 'lib/twitch/client.rb', line 72
def getTeam(team_id)
path = "/teams/"
url = @base_url + path + team_id;
get(url)
end
|
#getTeams ⇒ Object
65
66
67
68
69
|
# File 'lib/twitch/client.rb', line 65
def getTeams
path = "/teams/"
url = @base_url + path;
get(url)
end
|
#getTopGames(options = {}) ⇒ Object
196
197
198
199
200
201
|
# File 'lib/twitch/client.rb', line 196
def getTopGames(options = {})
query = buildQueryString(options)
path = "/games/top"
url = @base_url + path + query
get(url)
end
|
#getTopVideos(options = {}) ⇒ Object
256
257
258
259
260
261
|
# File 'lib/twitch/client.rb', line 256
def getTopVideos(options = {})
query = buildQueryString(options)
path = "/videos/top"
url = @base_url + path + query
get(url)
end
|
#getUser(user) ⇒ Object
50
51
52
53
54
|
# File 'lib/twitch/client.rb', line 50
def getUser(user)
path = "/users/"
url = @base_url + path + user;
get(url)
end
|
#getVideo(video_id) ⇒ Object
235
236
237
238
239
|
# File 'lib/twitch/client.rb', line 235
def getVideo(video_id)
path = "/videos/#{video_id}/"
url = @base_url + path
get(url)
end
|
#getYourChannel ⇒ Object
86
87
88
89
90
91
|
# File 'lib/twitch/client.rb', line 86
def getYourChannel
return false if !@access_token
path = "/channel?oauth_token=#{@access_token}"
url = @base_url + path;
get(url)
end
|
#getYourFollowedStreams(options = {}) ⇒ Object
186
187
188
189
190
191
192
|
# File 'lib/twitch/client.rb', line 186
def getYourFollowedStreams(options = {})
return false if !@access_token
query = buildQueryString(options)
path = "/streams/followed?oauth_token=#{@access_token}"
url = @base_url + path + query
get(url)
end
|
#getYourFollowedVideos(options = {}) ⇒ Object
248
249
250
251
252
253
254
|
# File 'lib/twitch/client.rb', line 248
def getYourFollowedVideos(options ={})
return false if !@access_token
query = buildQueryString(options)
path = "/videos/followed?oauth_token=#{@access_token}"
url = @base_url + path + query
get(url)
end
|
#getYourUser ⇒ Object
56
57
58
59
60
61
|
# File 'lib/twitch/client.rb', line 56
def getYourUser
return false if !@access_token
path = "/user?oauth_token=#{@access_token}"
url = @base_url + path
get(url)
end
|
#isSubscribed(username, channel, options = {}) ⇒ Object
241
242
243
244
245
246
|
# File 'lib/twitch/client.rb', line 241
def isSubscribed(username, channel, options = {})
query = buildQueryString(options)
path = "/users/#{username}/subscriptions/#{channel}?oauth_token=#{@access_token}"
url = @base_url + path + query
get(url)
end
|
#isSubscribedToChannel(username, channel) ⇒ Object
351
352
353
354
355
356
|
# File 'lib/twitch/client.rb', line 351
def isSubscribedToChannel(username, channel)
return false if !@access_token
path = "/channels/#{channel}/subscriptions/#{username}?oauth_token=#{@access_token}"
url = @base_url + path
get(url)
end
|
#resetKey(channel) ⇒ Object
114
115
116
117
118
119
|
# File 'lib/twitch/client.rb', line 114
def resetKey(channel)
return false if !@access_token
path = "/channels/#{channel}/stream_key?oauth_token=#{@access_token}"
url = @base_url + path
delete(url)
end
|
#runCommercial(channel, length = 30) ⇒ Object
135
136
137
138
139
140
141
142
|
# File 'lib/twitch/client.rb', line 135
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
|
#searchChannels(options = {}) ⇒ Object
205
206
207
208
209
210
|
# File 'lib/twitch/client.rb', line 205
def searchChannels(options = {})
query = buildQueryString(options)
path = "/search/channels"
url = @base_url + path + query
get(url)
end
|
#searchGames(options = {}) ⇒ Object
219
220
221
222
223
224
|
# File 'lib/twitch/client.rb', line 219
def searchGames(options = {})
query = buildQueryString(options)
path = "/search/games"
url = @base_url + path + query
get(url)
end
|
#searchStreams(options = {}) ⇒ Object
212
213
214
215
216
217
|
# File 'lib/twitch/client.rb', line 212
def searchStreams(options = {})
query = buildQueryString(options)
path = "/search/streams"
url = @base_url + path + query
get(url)
end
|
#unblockUser(username, target) ⇒ Object
279
280
281
282
283
284
|
# File 'lib/twitch/client.rb', line 279
def unblockUser(username, target)
return false if !@access_token
path = "/users/#{username}/blocks/#{target}?oauth_token=#{@access_token}"
url = @base_url + path
delete(url)
end
|