kappa 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +6 -0
- data/LICENSE +19 -0
- data/README.md +285 -285
- data/lib/kappa.rb +15 -15
- data/lib/kappa/channel.rb +214 -214
- data/lib/kappa/configuration.rb +88 -88
- data/lib/kappa/connection.rb +139 -139
- data/lib/kappa/errors.rb +43 -43
- data/lib/kappa/game.rb +216 -216
- data/lib/kappa/id_equality.rb +17 -17
- data/lib/kappa/images.rb +44 -44
- data/lib/kappa/proxy.rb +32 -32
- data/lib/kappa/query.rb +22 -22
- data/lib/kappa/status.rb +16 -16
- data/lib/kappa/stream.rb +288 -288
- data/lib/kappa/team.rb +132 -132
- data/lib/kappa/user.rb +159 -159
- data/lib/kappa/version.rb +3 -3
- data/lib/kappa/video.rb +229 -229
- metadata +18 -16
data/.yardopts
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2013 Chris Schmich
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,285 +1,285 @@
|
|
1
|
-
# <img src="https://raw.github.com/schmich/kappa/master/assets/kappa.png" /> Kappa
|
2
|
-
|
3
|
-
Kappa is the Ruby library for interfacing with the [Twitch.tv API](https://github.com/justintv/Twitch-API).
|
4
|
-
|
5
|
-
[![Gem Version](https://badge.fury.io/rb/kappa.png)](http://rubygems.org/gems/kappa)
|
6
|
-
[![Build Status](https://secure.travis-ci.org/schmich/kappa.png)](http://travis-ci.org/schmich/kappa)
|
7
|
-
[![Dependency Status](https://gemnasium.com/schmich/kappa.png)](https://gemnasium.com/schmich/kappa)
|
8
|
-
[![Coverage Status](https://coveralls.io/repos/schmich/kappa/badge.png?branch=master)](https://coveralls.io/r/schmich/kappa?branch=master)
|
9
|
-
[![Code Climate](https://codeclimate.com/github/schmich/kappa.png)](https://codeclimate.com/github/schmich/kappa)
|
10
|
-
|
11
|
-
## Getting Started
|
12
|
-
|
13
|
-
```bash
|
14
|
-
gem install kappa
|
15
|
-
```
|
16
|
-
|
17
|
-
```ruby
|
18
|
-
require 'kappa'
|
19
|
-
|
20
|
-
frag = Twitch.channels.get('lethalfrag')
|
21
|
-
puts frag.streaming?
|
22
|
-
```
|
23
|
-
|
24
|
-
```ruby
|
25
|
-
gem 'kappa', '~> 1.0'
|
26
|
-
```
|
27
|
-
|
28
|
-
## Configuration
|
29
|
-
|
30
|
-
When making requests to Twitch, you must specify a client ID for your application.
|
31
|
-
If you do not specify a client ID, Twitch reserves the right to rate-limit your application
|
32
|
-
without warning.
|
33
|
-
|
34
|
-
Your client ID can be specified through configuration, for example:
|
35
|
-
|
36
|
-
```ruby
|
37
|
-
Twitch.configure do |config|
|
38
|
-
config.client_id = 'sc2daily-v1.0.0'
|
39
|
-
end
|
40
|
-
```
|
41
|
-
|
42
|
-
See the [`Twitch.configure`](http://rdoc.info/gems/kappa/Twitch#configure-class_method) documentation.
|
43
|
-
|
44
|
-
## Examples
|
45
|
-
|
46
|
-
Get the featured streams on the Twitch.tv homepage:
|
47
|
-
|
48
|
-
```ruby
|
49
|
-
Twitch.streams.featured do |stream|
|
50
|
-
channel = stream.channel
|
51
|
-
puts "#{channel.display_name}: #{stream.viewer_count} viewers"
|
52
|
-
puts "#{channel.status}"
|
53
|
-
puts '-' * 80
|
54
|
-
end
|
55
|
-
```
|
56
|
-
|
57
|
-
See if certain users are streaming:
|
58
|
-
|
59
|
-
```ruby
|
60
|
-
users = ['destiny', 'followgrubby', 'incontroltv']
|
61
|
-
Twitch.streams.find(:channel => users) do |stream|
|
62
|
-
puts "#{stream.channel.name} is streaming #{stream.game_name}."
|
63
|
-
end
|
64
|
-
```
|
65
|
-
|
66
|
-
Get the most popular games being streamed:
|
67
|
-
|
68
|
-
```ruby
|
69
|
-
Twitch.games.top(:limit => 3) do |game|
|
70
|
-
print "#{game.name}: "
|
71
|
-
print "#{game.viewer_count} viewers in "
|
72
|
-
puts "#{game.channel_count} channels"
|
73
|
-
end
|
74
|
-
```
|
75
|
-
|
76
|
-
Get streams for a particular game:
|
77
|
-
|
78
|
-
```ruby
|
79
|
-
Twitch.streams.find(:game => 'League of Legends') do |stream|
|
80
|
-
next if stream.viewer_count < 1000
|
81
|
-
puts "#{stream.channel.display_name}: #{stream.viewer_count}"
|
82
|
-
end
|
83
|
-
```
|
84
|
-
|
85
|
-
Get info for a single user:
|
86
|
-
|
87
|
-
```ruby
|
88
|
-
user = Twitch.users.get('lethalfrag')
|
89
|
-
stream = user.stream
|
90
|
-
|
91
|
-
puts user.display_name
|
92
|
-
if stream
|
93
|
-
puts "Streaming #{stream.game_name} at #{stream.url}"
|
94
|
-
else
|
95
|
-
puts 'Not streaming.'
|
96
|
-
end
|
97
|
-
```
|
98
|
-
|
99
|
-
Get the followers of a channel:
|
100
|
-
|
101
|
-
```ruby
|
102
|
-
channel = Twitch.channels.get('day9tv')
|
103
|
-
channel.followers do |user|
|
104
|
-
puts user.display_name
|
105
|
-
end
|
106
|
-
```
|
107
|
-
|
108
|
-
## Resources
|
109
|
-
|
110
|
-
### <a id="channels"></a>Channels
|
111
|
-
|
112
|
-
Channels serve as the home location for a [user's](#users) content. Channels have a [stream](#streams),
|
113
|
-
can run commercials, store [videos](#videos), display information and status, and have a customized page
|
114
|
-
including banners and backgrounds. See the [`Channel`](http://rdoc.info/gems/kappa/Twitch/V2/Channel) documentation.
|
115
|
-
|
116
|
-
```ruby
|
117
|
-
c = Twitch.channels.get('destiny')
|
118
|
-
c.nil? # => false (channel exists)
|
119
|
-
c.stream # => #<Kappa::V2::Stream> (current live stream)
|
120
|
-
c.url # => "http://www.twitch.tv/destiny"
|
121
|
-
c.status # => "Destiny - Diamond I ADC - Number 1 Draven player..."
|
122
|
-
c.teams # => [#<Kappa::V2::Team>]
|
123
|
-
c.videos # => [#<Kappa::V2::Video>, ...]
|
124
|
-
c.followers # => [#<Kappa::V2::User>, ...]
|
125
|
-
```
|
126
|
-
|
127
|
-
### <a id="streams"></a>Streams
|
128
|
-
|
129
|
-
Streams are video broadcasts that are currently live. They belong to a [user](#users) and are part of a
|
130
|
-
[channel](#channels). See the [`Stream`](http://rdoc.info/gems/kappa/Twitch/V2/Stream) and
|
131
|
-
[`Streams`](http://rdoc.info/gems/kappa/Twitch/V2/Streams) documentation.
|
132
|
-
|
133
|
-
```ruby
|
134
|
-
s = Twitch.streams.get('idrajit')
|
135
|
-
s.nil? # => false (currently live)
|
136
|
-
s.game_name # => "StarCraft II: Heart of the Swarm"
|
137
|
-
s.viewer_count # => 7267
|
138
|
-
s.channel.url # => "http://www.twitch.tv/idrajit"
|
139
|
-
```
|
140
|
-
|
141
|
-
### <a id="users"></a>Users
|
142
|
-
|
143
|
-
These are members of the Twitch community who have a Twitch account. If broadcasting, they can own a
|
144
|
-
[stream](#streams) that they can broadcast on their [channel](#channels). If mainly viewing, they might
|
145
|
-
follow or subscribe to channels. See the [`User`](http://rdoc.info/gems/kappa/Twitch/V2/User) documentation.
|
146
|
-
|
147
|
-
```ruby
|
148
|
-
u = Twitch.users.get('snoopeh')
|
149
|
-
u.nil? # => false (user exists)
|
150
|
-
u.channel # => #<Kappa::V2::Channel>
|
151
|
-
u.following.map(&:name) # => ["national_esl1", "dreamhacklol", "riotgames"]
|
152
|
-
```
|
153
|
-
|
154
|
-
### <a id="videos"></a>Videos
|
155
|
-
|
156
|
-
Videos are broadcasts or highlights owned by a [channel](#channels). Broadcasts are unedited videos that are saved
|
157
|
-
after a streaming session. Highlights are videos edited from broadcasts by the channel's owner. See the
|
158
|
-
[`Video`](http://rdoc.info/gems/kappa/Twitch/V2/Video) and [`Videos`](http://rdoc.info/gems/kappa/Twitch/V2/Videos)
|
159
|
-
documentation.
|
160
|
-
|
161
|
-
```ruby
|
162
|
-
v = Twitch.videos.get('a395995729')
|
163
|
-
v.nil? # => false (video exists)
|
164
|
-
v.title # => "DreamHack Open Stockholm 26-27 April"
|
165
|
-
v.game_name # => "StarCraft II: Heart of the Swarm"
|
166
|
-
v.recorded_at # => 2013-04-26 18:33:48 UTC
|
167
|
-
v.view_count # => 12506
|
168
|
-
```
|
169
|
-
|
170
|
-
### <a id="teams"></a>Teams
|
171
|
-
|
172
|
-
Teams are an organization of [channels](#channels). See the [`Team`](http://rdoc.info/gems/kappa/Twitch/V2/Team)
|
173
|
-
documentation.
|
174
|
-
|
175
|
-
```ruby
|
176
|
-
t = Twitch.teams.get('teamliquid')
|
177
|
-
t.nil? # => false (team exists)
|
178
|
-
t.display_name # => "TeamLiquid"
|
179
|
-
t.info # => "TeamLiquid is awesome. and esports. video games. \n\n"
|
180
|
-
t.updated_at # => 2013-05-24 00:17:10 UTC
|
181
|
-
```
|
182
|
-
|
183
|
-
### <a id="games"></a>Games
|
184
|
-
|
185
|
-
Games are categories (e.g. League of Legends, Diablo 3) used by [streams](#streams) and [channels](#channels).
|
186
|
-
Games can be searched for by query. See the [`Game`](http://rdoc.info/gems/kappa/Twitch/V2/Game),
|
187
|
-
[`Games`](http://rdoc.info/gems/kappa/Twitch/V2/Games), and
|
188
|
-
[`GameSuggestion`](http://rdoc.info/gems/kappa/Twitch/V2/GameSuggestion) documentation.
|
189
|
-
|
190
|
-
```ruby
|
191
|
-
top = Twitch.games.top(:limit => 2)
|
192
|
-
top.map(&:name) # => ["League of Legends", "StarCraft II: Heart of the Swarm"]
|
193
|
-
```
|
194
|
-
|
195
|
-
```ruby
|
196
|
-
g = Twitch.games.top(:limit => 1).first
|
197
|
-
g.name # => "League of Legends"
|
198
|
-
g.channel_count # => 906
|
199
|
-
g.viewer_count # => 79223
|
200
|
-
g.box_images.medium_url # =>"http://static-cdn.jtvnw.net/ttv-boxart/31412.jpg"
|
201
|
-
```
|
202
|
-
|
203
|
-
```ruby
|
204
|
-
s = Twitch.games.find(:name => 'diablo', :live => true)
|
205
|
-
s.map(&:name) # => ["Diablo III", "Diablo II", "Diablo"]
|
206
|
-
s.map(&:popularity) # => [120, 4, 1]
|
207
|
-
```
|
208
|
-
|
209
|
-
## Errors
|
210
|
-
|
211
|
-
All errors derive from `Twitch::Error`.
|
212
|
-
|
213
|
-
- `Twitch:Error` - Base class for all errors.
|
214
|
-
- `Twitch::Error::ResponseError` - Base class for all Twitch.tv API response errors.
|
215
|
-
- `Twitch::Error::FormatError` - The returned data was incorrectly formatted (e.g. invalid JSON).
|
216
|
-
- `Twitch::Error::ClientError` - The server returned a 4xx status code.
|
217
|
-
- `Twitch::Error::ServerError` - The server returned a 5xx status code.
|
218
|
-
|
219
|
-
All `ResponseError` errors have additional diagnostic information:
|
220
|
-
|
221
|
-
```ruby
|
222
|
-
e.status # => 422
|
223
|
-
e.body # => '{"status":422,"message":"...","error":"..."}'
|
224
|
-
e.url # => "https://api.twitch.tv/streams/desrow"
|
225
|
-
```
|
226
|
-
|
227
|
-
See the [`ResponseError`](http://rdoc.info/gems/kappa/Twitch/Error/ResponseError) documentation.
|
228
|
-
|
229
|
-
## Documentation
|
230
|
-
|
231
|
-
- Current release: [http://rdoc.info/gems/kappa/frames](http://rdoc.info/gems/kappa/frames)
|
232
|
-
- Latest master: [http://rdoc.info/github/schmich/kappa/frames](http://rdoc.info/github/schmich/kappa/frames)
|
233
|
-
- Twitch REST API: [https://github.com/justintv/Twitch-API](https://github.com/justintv/Twitch-API)
|
234
|
-
|
235
|
-
## Versioning
|
236
|
-
|
237
|
-
### Library version
|
238
|
-
|
239
|
-
Kappa adheres to the [Semantic Versioning 2.0.0](http://semver.org/) specification. Most importantly, any
|
240
|
-
compatibility- or API-breaking changes will result in a new major version (e.g. `1.x.x` to `2.x.x`). Because
|
241
|
-
of this, you should use a [pessimistic version constraint](http://docs.rubygems.org/read/chapter/16#page74) when
|
242
|
-
taking a dependency on this library. For example:
|
243
|
-
|
244
|
-
```ruby
|
245
|
-
gem 'kappa', '~> 1.0'
|
246
|
-
```
|
247
|
-
|
248
|
-
Any new backwards-compatible features will result in a new minor version (e.g. `x.1.x` to `x.2.x`) while any
|
249
|
-
backwards-compatible bugfixes will result in a new patch version (e.g. `x.x.1` to `x.x.2`).
|
250
|
-
|
251
|
-
### Twitch API versions
|
252
|
-
|
253
|
-
Twitch supports multiple versions of their API simultaneously, with each version potentially providing different data
|
254
|
-
and behaving differently. Because of this, you can specify which version of the Twitch API you wish to use.
|
255
|
-
This is done through Kappa configuration.
|
256
|
-
|
257
|
-
For example, if you want to use the V2 Twitch API:
|
258
|
-
|
259
|
-
```ruby
|
260
|
-
Twitch.configure do |config|
|
261
|
-
config.client_id = 'sc2daily-v1.0.0'
|
262
|
-
config.api = Twitch::V2
|
263
|
-
end
|
264
|
-
```
|
265
|
-
|
266
|
-
`Twitch::V2` is the default and is currently the only supported API version.
|
267
|
-
|
268
|
-
## Contributing
|
269
|
-
|
270
|
-
- [Fork and clone the repo.](http://help.github.com/fork-a-repo/)
|
271
|
-
- [Create a branch for your changes.](http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging)
|
272
|
-
- Run `bundle install` to install development requirements.
|
273
|
-
- Implement your feature or bug fix.
|
274
|
-
- Add specs under the `spec` folder to prevent regressions or to test new code.
|
275
|
-
- Add [YARD](http://rubydoc.info/docs/yard/file/docs/GettingStarted.md) documentation for new features. Run `rake yard` to view documentation.
|
276
|
-
- Run `rake coverage` to run specs with code coverage. All specs must pass; coverage must remain at 100%. Run `rake coverage:view` to see a detailed report.
|
277
|
-
- Commit and push your changes.
|
278
|
-
- [Submit a pull request.](http://help.github.com/send-pull-requests/)
|
279
|
-
|
280
|
-
## License
|
281
|
-
|
282
|
-
Copyright © 2013 Chris Schmich
|
283
|
-
<br />
|
284
|
-
MIT License, See [LICENSE](LICENSE) for details.
|
285
|
-
[![githalytics.com alpha](https://cruel-carlota.pagodabox.com/b885add21cf8f2b473d1394edc1cf5b4 "githalytics.com")](http://githalytics.com/schmich/kappa)
|
1
|
+
# <img src="https://raw.github.com/schmich/kappa/master/assets/kappa.png" /> Kappa
|
2
|
+
|
3
|
+
Kappa is the Ruby library for interfacing with the [Twitch.tv API](https://github.com/justintv/Twitch-API).
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/kappa.png)](http://rubygems.org/gems/kappa)
|
6
|
+
[![Build Status](https://secure.travis-ci.org/schmich/kappa.png)](http://travis-ci.org/schmich/kappa)
|
7
|
+
[![Dependency Status](https://gemnasium.com/schmich/kappa.png)](https://gemnasium.com/schmich/kappa)
|
8
|
+
[![Coverage Status](https://coveralls.io/repos/schmich/kappa/badge.png?branch=master)](https://coveralls.io/r/schmich/kappa?branch=master)
|
9
|
+
[![Code Climate](https://codeclimate.com/github/schmich/kappa.png)](https://codeclimate.com/github/schmich/kappa)
|
10
|
+
|
11
|
+
## Getting Started
|
12
|
+
|
13
|
+
```bash
|
14
|
+
gem install kappa
|
15
|
+
```
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require 'kappa'
|
19
|
+
|
20
|
+
frag = Twitch.channels.get('lethalfrag')
|
21
|
+
puts frag.streaming?
|
22
|
+
```
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
gem 'kappa', '~> 1.0'
|
26
|
+
```
|
27
|
+
|
28
|
+
## Configuration
|
29
|
+
|
30
|
+
When making requests to Twitch, you must specify a client ID for your application.
|
31
|
+
If you do not specify a client ID, Twitch reserves the right to rate-limit your application
|
32
|
+
without warning.
|
33
|
+
|
34
|
+
Your client ID can be specified through configuration, for example:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
Twitch.configure do |config|
|
38
|
+
config.client_id = 'sc2daily-v1.0.0'
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
See the [`Twitch.configure`](http://rdoc.info/gems/kappa/Twitch#configure-class_method) documentation.
|
43
|
+
|
44
|
+
## Examples
|
45
|
+
|
46
|
+
Get the featured streams on the Twitch.tv homepage:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
Twitch.streams.featured do |stream|
|
50
|
+
channel = stream.channel
|
51
|
+
puts "#{channel.display_name}: #{stream.viewer_count} viewers"
|
52
|
+
puts "#{channel.status}"
|
53
|
+
puts '-' * 80
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
See if certain users are streaming:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
users = ['destiny', 'followgrubby', 'incontroltv']
|
61
|
+
Twitch.streams.find(:channel => users) do |stream|
|
62
|
+
puts "#{stream.channel.name} is streaming #{stream.game_name}."
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
Get the most popular games being streamed:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
Twitch.games.top(:limit => 3) do |game|
|
70
|
+
print "#{game.name}: "
|
71
|
+
print "#{game.viewer_count} viewers in "
|
72
|
+
puts "#{game.channel_count} channels"
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
Get streams for a particular game:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
Twitch.streams.find(:game => 'League of Legends') do |stream|
|
80
|
+
next if stream.viewer_count < 1000
|
81
|
+
puts "#{stream.channel.display_name}: #{stream.viewer_count}"
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
85
|
+
Get info for a single user:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
user = Twitch.users.get('lethalfrag')
|
89
|
+
stream = user.stream
|
90
|
+
|
91
|
+
puts user.display_name
|
92
|
+
if stream
|
93
|
+
puts "Streaming #{stream.game_name} at #{stream.url}"
|
94
|
+
else
|
95
|
+
puts 'Not streaming.'
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
99
|
+
Get the followers of a channel:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
channel = Twitch.channels.get('day9tv')
|
103
|
+
channel.followers do |user|
|
104
|
+
puts user.display_name
|
105
|
+
end
|
106
|
+
```
|
107
|
+
|
108
|
+
## Resources
|
109
|
+
|
110
|
+
### <a id="channels"></a>Channels
|
111
|
+
|
112
|
+
Channels serve as the home location for a [user's](#users) content. Channels have a [stream](#streams),
|
113
|
+
can run commercials, store [videos](#videos), display information and status, and have a customized page
|
114
|
+
including banners and backgrounds. See the [`Channel`](http://rdoc.info/gems/kappa/Twitch/V2/Channel) documentation.
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
c = Twitch.channels.get('destiny')
|
118
|
+
c.nil? # => false (channel exists)
|
119
|
+
c.stream # => #<Kappa::V2::Stream> (current live stream)
|
120
|
+
c.url # => "http://www.twitch.tv/destiny"
|
121
|
+
c.status # => "Destiny - Diamond I ADC - Number 1 Draven player..."
|
122
|
+
c.teams # => [#<Kappa::V2::Team>]
|
123
|
+
c.videos # => [#<Kappa::V2::Video>, ...]
|
124
|
+
c.followers # => [#<Kappa::V2::User>, ...]
|
125
|
+
```
|
126
|
+
|
127
|
+
### <a id="streams"></a>Streams
|
128
|
+
|
129
|
+
Streams are video broadcasts that are currently live. They belong to a [user](#users) and are part of a
|
130
|
+
[channel](#channels). See the [`Stream`](http://rdoc.info/gems/kappa/Twitch/V2/Stream) and
|
131
|
+
[`Streams`](http://rdoc.info/gems/kappa/Twitch/V2/Streams) documentation.
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
s = Twitch.streams.get('idrajit')
|
135
|
+
s.nil? # => false (currently live)
|
136
|
+
s.game_name # => "StarCraft II: Heart of the Swarm"
|
137
|
+
s.viewer_count # => 7267
|
138
|
+
s.channel.url # => "http://www.twitch.tv/idrajit"
|
139
|
+
```
|
140
|
+
|
141
|
+
### <a id="users"></a>Users
|
142
|
+
|
143
|
+
These are members of the Twitch community who have a Twitch account. If broadcasting, they can own a
|
144
|
+
[stream](#streams) that they can broadcast on their [channel](#channels). If mainly viewing, they might
|
145
|
+
follow or subscribe to channels. See the [`User`](http://rdoc.info/gems/kappa/Twitch/V2/User) documentation.
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
u = Twitch.users.get('snoopeh')
|
149
|
+
u.nil? # => false (user exists)
|
150
|
+
u.channel # => #<Kappa::V2::Channel>
|
151
|
+
u.following.map(&:name) # => ["national_esl1", "dreamhacklol", "riotgames"]
|
152
|
+
```
|
153
|
+
|
154
|
+
### <a id="videos"></a>Videos
|
155
|
+
|
156
|
+
Videos are broadcasts or highlights owned by a [channel](#channels). Broadcasts are unedited videos that are saved
|
157
|
+
after a streaming session. Highlights are videos edited from broadcasts by the channel's owner. See the
|
158
|
+
[`Video`](http://rdoc.info/gems/kappa/Twitch/V2/Video) and [`Videos`](http://rdoc.info/gems/kappa/Twitch/V2/Videos)
|
159
|
+
documentation.
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
v = Twitch.videos.get('a395995729')
|
163
|
+
v.nil? # => false (video exists)
|
164
|
+
v.title # => "DreamHack Open Stockholm 26-27 April"
|
165
|
+
v.game_name # => "StarCraft II: Heart of the Swarm"
|
166
|
+
v.recorded_at # => 2013-04-26 18:33:48 UTC
|
167
|
+
v.view_count # => 12506
|
168
|
+
```
|
169
|
+
|
170
|
+
### <a id="teams"></a>Teams
|
171
|
+
|
172
|
+
Teams are an organization of [channels](#channels). See the [`Team`](http://rdoc.info/gems/kappa/Twitch/V2/Team)
|
173
|
+
documentation.
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
t = Twitch.teams.get('teamliquid')
|
177
|
+
t.nil? # => false (team exists)
|
178
|
+
t.display_name # => "TeamLiquid"
|
179
|
+
t.info # => "TeamLiquid is awesome. and esports. video games. \n\n"
|
180
|
+
t.updated_at # => 2013-05-24 00:17:10 UTC
|
181
|
+
```
|
182
|
+
|
183
|
+
### <a id="games"></a>Games
|
184
|
+
|
185
|
+
Games are categories (e.g. League of Legends, Diablo 3) used by [streams](#streams) and [channels](#channels).
|
186
|
+
Games can be searched for by query. See the [`Game`](http://rdoc.info/gems/kappa/Twitch/V2/Game),
|
187
|
+
[`Games`](http://rdoc.info/gems/kappa/Twitch/V2/Games), and
|
188
|
+
[`GameSuggestion`](http://rdoc.info/gems/kappa/Twitch/V2/GameSuggestion) documentation.
|
189
|
+
|
190
|
+
```ruby
|
191
|
+
top = Twitch.games.top(:limit => 2)
|
192
|
+
top.map(&:name) # => ["League of Legends", "StarCraft II: Heart of the Swarm"]
|
193
|
+
```
|
194
|
+
|
195
|
+
```ruby
|
196
|
+
g = Twitch.games.top(:limit => 1).first
|
197
|
+
g.name # => "League of Legends"
|
198
|
+
g.channel_count # => 906
|
199
|
+
g.viewer_count # => 79223
|
200
|
+
g.box_images.medium_url # =>"http://static-cdn.jtvnw.net/ttv-boxart/31412.jpg"
|
201
|
+
```
|
202
|
+
|
203
|
+
```ruby
|
204
|
+
s = Twitch.games.find(:name => 'diablo', :live => true)
|
205
|
+
s.map(&:name) # => ["Diablo III", "Diablo II", "Diablo"]
|
206
|
+
s.map(&:popularity) # => [120, 4, 1]
|
207
|
+
```
|
208
|
+
|
209
|
+
## Errors
|
210
|
+
|
211
|
+
All errors derive from `Twitch::Error`.
|
212
|
+
|
213
|
+
- `Twitch:Error` - Base class for all errors.
|
214
|
+
- `Twitch::Error::ResponseError` - Base class for all Twitch.tv API response errors.
|
215
|
+
- `Twitch::Error::FormatError` - The returned data was incorrectly formatted (e.g. invalid JSON).
|
216
|
+
- `Twitch::Error::ClientError` - The server returned a 4xx status code.
|
217
|
+
- `Twitch::Error::ServerError` - The server returned a 5xx status code.
|
218
|
+
|
219
|
+
All `ResponseError` errors have additional diagnostic information:
|
220
|
+
|
221
|
+
```ruby
|
222
|
+
e.status # => 422
|
223
|
+
e.body # => '{"status":422,"message":"...","error":"..."}'
|
224
|
+
e.url # => "https://api.twitch.tv/streams/desrow"
|
225
|
+
```
|
226
|
+
|
227
|
+
See the [`ResponseError`](http://rdoc.info/gems/kappa/Twitch/Error/ResponseError) documentation.
|
228
|
+
|
229
|
+
## Documentation
|
230
|
+
|
231
|
+
- Current release: [http://rdoc.info/gems/kappa/frames](http://rdoc.info/gems/kappa/frames)
|
232
|
+
- Latest master: [http://rdoc.info/github/schmich/kappa/frames](http://rdoc.info/github/schmich/kappa/frames)
|
233
|
+
- Twitch REST API: [https://github.com/justintv/Twitch-API](https://github.com/justintv/Twitch-API)
|
234
|
+
|
235
|
+
## Versioning
|
236
|
+
|
237
|
+
### Library version
|
238
|
+
|
239
|
+
Kappa adheres to the [Semantic Versioning 2.0.0](http://semver.org/) specification. Most importantly, any
|
240
|
+
compatibility- or API-breaking changes will result in a new major version (e.g. `1.x.x` to `2.x.x`). Because
|
241
|
+
of this, you should use a [pessimistic version constraint](http://docs.rubygems.org/read/chapter/16#page74) when
|
242
|
+
taking a dependency on this library. For example:
|
243
|
+
|
244
|
+
```ruby
|
245
|
+
gem 'kappa', '~> 1.0'
|
246
|
+
```
|
247
|
+
|
248
|
+
Any new backwards-compatible features will result in a new minor version (e.g. `x.1.x` to `x.2.x`) while any
|
249
|
+
backwards-compatible bugfixes will result in a new patch version (e.g. `x.x.1` to `x.x.2`).
|
250
|
+
|
251
|
+
### Twitch API versions
|
252
|
+
|
253
|
+
Twitch supports multiple versions of their API simultaneously, with each version potentially providing different data
|
254
|
+
and behaving differently. Because of this, you can specify which version of the Twitch API you wish to use.
|
255
|
+
This is done through Kappa configuration.
|
256
|
+
|
257
|
+
For example, if you want to use the V2 Twitch API:
|
258
|
+
|
259
|
+
```ruby
|
260
|
+
Twitch.configure do |config|
|
261
|
+
config.client_id = 'sc2daily-v1.0.0'
|
262
|
+
config.api = Twitch::V2
|
263
|
+
end
|
264
|
+
```
|
265
|
+
|
266
|
+
`Twitch::V2` is the default and is currently the only supported API version.
|
267
|
+
|
268
|
+
## Contributing
|
269
|
+
|
270
|
+
- [Fork and clone the repo.](http://help.github.com/fork-a-repo/)
|
271
|
+
- [Create a branch for your changes.](http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging)
|
272
|
+
- Run `bundle install` to install development requirements.
|
273
|
+
- Implement your feature or bug fix.
|
274
|
+
- Add specs under the `spec` folder to prevent regressions or to test new code.
|
275
|
+
- Add [YARD](http://rubydoc.info/docs/yard/file/docs/GettingStarted.md) documentation for new features. Run `rake yard` to view documentation.
|
276
|
+
- Run `rake coverage` to run specs with code coverage. All specs must pass; coverage must remain at 100%. Run `rake coverage:view` to see a detailed report.
|
277
|
+
- Commit and push your changes.
|
278
|
+
- [Submit a pull request.](http://help.github.com/send-pull-requests/)
|
279
|
+
|
280
|
+
## License
|
281
|
+
|
282
|
+
Copyright © 2013 Chris Schmich
|
283
|
+
<br />
|
284
|
+
MIT License, See [LICENSE](LICENSE) for details.
|
285
|
+
[![githalytics.com alpha](https://cruel-carlota.pagodabox.com/b885add21cf8f2b473d1394edc1cf5b4 "githalytics.com")](http://githalytics.com/schmich/kappa)
|