Class: Twitch::Client
Constant Summary
Constants included
from Adapters
Adapters::DEFAULT_ADAPTER
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#auth(code) ⇒ Object
-
#badges(channel) ⇒ Object
-
#block_user(username, target) ⇒ Object
-
#blocks(username, options = {}) ⇒ Object
-
#channel(channel = nil) ⇒ Object
-
#channel_teams(channel) ⇒ Object
-
#channel_videos(channel, options = {}) ⇒ Object
-
#chat_links(channel) ⇒ Object
-
#edit_channel(channel, status, game) ⇒ Object
TODO: Add ability to set delay, which is only available for partered channels.
-
#editors(channel) ⇒ Object
-
#emoticons ⇒ Object
-
#featured_streams(options = {}) ⇒ Object
-
#follow_channel(username, channel) ⇒ Object
-
#follow_status(username, channel) ⇒ Object
-
#followed(username) ⇒ Object
-
#followed_streams(options = {}) ⇒ Object
(also: #your_followed_streams)
-
#followed_videos(options = {}) ⇒ Object
(also: #your_followed_videos)
-
#following(channel) ⇒ Object
-
#ingests ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#link ⇒ Object
-
#reset_key(channel) ⇒ Object
-
#root ⇒ Object
-
#run_commercial(channel, length = 30) ⇒ Object
-
#search_channels(options = {}) ⇒ Object
-
#search_games(options = {}) ⇒ Object
-
#search_streams(options = {}) ⇒ Object
-
#stream(stream_name) ⇒ Object
-
#streams(options = {}) ⇒ Object
-
#subscribed(channel) ⇒ Object
-
#subscribed?(username, channel, options = {}) ⇒ Boolean
-
#subscribed_to_channel(username, channel) ⇒ Object
-
#summarized_streams(options = {}) ⇒ Object
-
#team(team_id) ⇒ Object
-
#teams ⇒ Object
-
#top_games(options = {}) ⇒ Object
-
#top_videos(options = {}) ⇒ Object
-
#unblock_user(username, target) ⇒ Object
-
#user(user = nil) ⇒ Object
-
#video(video_id) ⇒ Object
-
#your_channel ⇒ Object
-
#your_user ⇒ Object
Methods included from Adapters
#get_adapter
Methods included from Request
#build_query_string, #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
|
#badges(channel) ⇒ Object
342
343
344
345
346
347
|
# File 'lib/twitch/client.rb', line 342
def badges(channel)
path = "/chat/#{channel}/badges"
url = @base_url + path;
get(url)
end
|
#block_user(username, target) ⇒ Object
317
318
319
320
321
322
323
|
# File 'lib/twitch/client.rb', line 317
def block_user(username, target)
return false unless @access_token
path = "/users/#{username}/blocks/#{target}?oauth_token=#{@access_token}"
url = @base_url + path
put(url)
end
|
#blocks(username, options = {}) ⇒ Object
308
309
310
311
312
313
314
315
|
# File 'lib/twitch/client.rb', line 308
def blocks(username, options = {})
options[:oauth_token] = @access_token
query = build_query_string(options)
path = "/users/#{username}/blocks"
url = @base_url + path + query
get(url)
end
|
#channel(channel = nil) ⇒ Object
87
88
89
90
91
92
93
94
|
# File 'lib/twitch/client.rb', line 87
def channel(channel = nil)
return your_channel unless channel
path = "/channels/"
url = @base_url + path + channel;
get(url)
end
|
#channel_teams(channel) ⇒ Object
163
164
165
166
167
168
169
170
|
# File 'lib/twitch/client.rb', line 163
def channel_teams(channel)
return false unless @access_token
path = "/channels/#{channel}/teams?oauth_token=#{@access_token}"
url = @base_url + path;
get(url)
end
|
#channel_videos(channel, options = {}) ⇒ Object
262
263
264
265
266
267
268
|
# File 'lib/twitch/client.rb', line 262
def channel_videos(channel, options = {})
query = build_query_string(options)
path = "/channels/#{channel}/videos"
url = @base_url + path + query
get(url)
end
|
#chat_links(channel) ⇒ Object
335
336
337
338
339
340
|
# File 'lib/twitch/client.rb', line 335
def chat_links(channel)
path = "/chat/"
url = @base_url + path + channel;
get(url)
end
|
#edit_channel(channel, status, game) ⇒ Object
TODO: Add ability to set delay, which is only available for partered channels
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/twitch/client.rb', line 115
def edit_channel(channel, status, game)
return false unless @access_token
path = "/channels/#{channel}/?oauth_token=#{@access_token}"
url = @base_url + path
data = {
:channel =>{
:game => game,
:status => status
}
}
put(url, data)
end
|
#editors(channel) ⇒ Object
105
106
107
108
109
110
111
112
|
# File 'lib/twitch/client.rb', line 105
def editors(channel)
return false unless @access_token
path = "/channels/#{channel}/editors?oauth_token=#{@access_token}"
url = @base_url + path;
get(url)
end
|
#emoticons ⇒ Object
349
350
351
352
353
354
|
# File 'lib/twitch/client.rb', line 349
def emoticons()
path = "/chat/emoticons"
url = @base_url + path;
get(url)
end
|
#featured_streams(options = {}) ⇒ Object
196
197
198
199
200
201
202
|
# File 'lib/twitch/client.rb', line 196
def featured_streams(options = {})
query = build_query_string(options)
path = "/streams/featured"
url = @base_url + path + query
get(url)
end
|
#follow_channel(username, channel) ⇒ Object
137
138
139
140
141
142
143
|
# File 'lib/twitch/client.rb', line 137
def follow_channel(username, channel)
return false unless @access_token
path = "/users/#{username}/follows/channels/#{channel}?oauth_token=#{@access_token}"
url = @base_url + path
put(url)
end
|
#follow_status(username, channel) ⇒ Object
372
373
374
375
376
377
|
# File 'lib/twitch/client.rb', line 372
def follow_status(username, channel)
path = "/users/#{username}/follows/channels/#{channel}/?oauth_token=#{@access_token}"
url = @base_url + path;
get(url)
end
|
#followed(username) ⇒ Object
365
366
367
368
369
370
|
# File 'lib/twitch/client.rb', line 365
def followed(username)
path = "/users/#{username}/follows/channels"
url = @base_url + path;
get(url)
end
|
#followed_streams(options = {}) ⇒ Object
Also known as:
your_followed_streams
212
213
214
215
216
217
218
219
220
221
|
# File 'lib/twitch/client.rb', line 212
def followed_streams(options = {})
return false unless @access_token
options[:oauth_token] = @access_token
query = build_query_string(options)
path = "/streams/followed"
url = @base_url + path + query
get(url)
end
|
#followed_videos(options = {}) ⇒ Object
Also known as:
your_followed_videos
286
287
288
289
290
291
292
293
294
295
|
# File 'lib/twitch/client.rb', line 286
def followed_videos(options ={})
return false unless @access_token
options[:oauth_token] = @access_token
query = build_query_string(options)
path = "/videos/followed"
url = @base_url + path + query
get(url)
end
|
#following(channel) ⇒ Object
358
359
360
361
362
363
|
# File 'lib/twitch/client.rb', line 358
def following(channel)
path = "/channels/#{channel}/follows"
url = @base_url + path;
get(url)
end
|
#ingests ⇒ Object
381
382
383
384
385
386
|
# File 'lib/twitch/client.rb', line 381
def ingests()
path = "/ingests"
url = @base_url + path
get(url)
end
|
#link ⇒ Object
30
31
32
33
34
|
# File 'lib/twitch/client.rb', line 30
def link
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
|
#reset_key(channel) ⇒ Object
129
130
131
132
133
134
135
|
# File 'lib/twitch/client.rb', line 129
def reset_key(channel)
return false unless @access_token
path = "/channels/#{channel}/stream_key?oauth_token=#{@access_token}"
url = @base_url + path
delete(url)
end
|
#root ⇒ Object
390
391
392
393
394
395
|
# File 'lib/twitch/client.rb', line 390
def root()
path = "/?oauth_token=#{@access_token}"
url = @base_url + path
get(url)
end
|
#run_commercial(channel, length = 30) ⇒ Object
153
154
155
156
157
158
159
160
161
|
# File 'lib/twitch/client.rb', line 153
def run_commercial(channel, length = 30)
return false unless @access_token
path = "/channels/#{channel}/commercial?oauth_token=#{@access_token}"
url = @base_url + path
post(url, {
:length => length
})
end
|
#search_channels(options = {}) ⇒ Object
236
237
238
239
240
241
242
|
# File 'lib/twitch/client.rb', line 236
def search_channels(options = {})
query = build_query_string(options)
path = "/search/channels"
url = @base_url + path + query
get(url)
end
|
#search_games(options = {}) ⇒ Object
252
253
254
255
256
257
258
|
# File 'lib/twitch/client.rb', line 252
def search_games(options = {})
query = build_query_string(options)
path = "/search/games"
url = @base_url + path + query
get(url)
end
|
#search_streams(options = {}) ⇒ Object
244
245
246
247
248
249
250
|
# File 'lib/twitch/client.rb', line 244
def search_streams(options = {})
query = build_query_string(options)
path = "/search/streams"
url = @base_url + path + query
get(url)
end
|
#stream(stream_name) ⇒ Object
174
175
176
177
178
179
|
# File 'lib/twitch/client.rb', line 174
def stream(stream_name)
path = "/stream/#{stream_name}"
url = @base_url + path;
get(url)
end
|
#streams(options = {}) ⇒ Object
188
189
190
191
192
193
194
|
# File 'lib/twitch/client.rb', line 188
def streams(options = {})
query = build_query_string(options)
path = "/streams"
url = @base_url + path + query
get(url)
end
|
#subscribed(channel) ⇒ Object
399
400
401
402
403
404
405
406
|
# File 'lib/twitch/client.rb', line 399
def subscribed(channel)
return false unless @access_token
path = "/channels/#{channel}/subscriptions?oauth_token=#{@access_token}"
url = @base_url + path
get(url)
end
|
#subscribed?(username, channel, options = {}) ⇒ Boolean
277
278
279
280
281
282
283
284
|
# File 'lib/twitch/client.rb', line 277
def subscribed?(username, channel, options = {})
options[:oauth_token] = @access_token
query = build_query_string(options)
path = "/users/#{username}/subscriptions/#{channel}"
url = @base_url + path + query
get(url)
end
|
#subscribed_to_channel(username, channel) ⇒ Object
408
409
410
411
412
413
414
415
|
# File 'lib/twitch/client.rb', line 408
def subscribed_to_channel(username, channel)
return false unless @access_token
path = "/channels/#{channel}/subscriptions/#{username}?oauth_token=#{@access_token}"
url = @base_url + path
get(url)
end
|
#summarized_streams(options = {}) ⇒ Object
204
205
206
207
208
209
210
|
# File 'lib/twitch/client.rb', line 204
def summarized_streams(options = {})
query = build_query_string(options)
path = "/streams/summary"
url = @base_url + path + query
get(url)
end
|
#team(team_id) ⇒ Object
78
79
80
81
82
83
|
# File 'lib/twitch/client.rb', line 78
def team(team_id)
path = "/teams/"
url = @base_url + path + team_id;
get(url)
end
|
#teams ⇒ Object
70
71
72
73
74
75
|
# File 'lib/twitch/client.rb', line 70
def teams
path = "/teams/"
url = @base_url + path;
get(url)
end
|
#top_games(options = {}) ⇒ Object
226
227
228
229
230
231
232
|
# File 'lib/twitch/client.rb', line 226
def top_games(options = {})
query = build_query_string(options)
path = "/games/top"
url = @base_url + path + query
get(url)
end
|
#top_videos(options = {}) ⇒ Object
298
299
300
301
302
303
304
|
# File 'lib/twitch/client.rb', line 298
def top_videos(options = {})
query = build_query_string(options)
path = "/videos/top"
url = @base_url + path + query
get(url)
end
|
#unblock_user(username, target) ⇒ Object
325
326
327
328
329
330
331
|
# File 'lib/twitch/client.rb', line 325
def unblock_user(username, target)
return false unless @access_token
path = "/users/#{username}/blocks/#{target}?oauth_token=#{@access_token}"
url = @base_url + path
delete(url)
end
|
#user(user = nil) ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/twitch/client.rb', line 50
def user(user = nil)
return your_user unless user
path = "/users/"
url = @base_url + path + user;
get(url)
end
|
#video(video_id) ⇒ Object
270
271
272
273
274
275
|
# File 'lib/twitch/client.rb', line 270
def video(video_id)
path = "/videos/#{video_id}/"
url = @base_url + path
get(url)
end
|
#your_channel ⇒ Object
96
97
98
99
100
101
102
103
|
# File 'lib/twitch/client.rb', line 96
def your_channel
return false unless @access_token
path = "/channel?oauth_token=#{@access_token}"
url = @base_url + path;
get(url)
end
|
#your_user ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'lib/twitch/client.rb', line 59
def your_user
return false unless @access_token
path = "/user?oauth_token=#{@access_token}"
url = @base_url + path
get(url)
end
|