kappa 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +184 -148
- data/lib/kappa.rb +12 -11
- data/lib/kappa/channel.rb +143 -184
- data/lib/kappa/connection.rb +129 -142
- data/lib/kappa/game.rb +147 -161
- data/lib/kappa/id_equality.rb +17 -17
- data/lib/kappa/images.rb +34 -36
- data/lib/kappa/proxy.rb +32 -0
- data/lib/kappa/stream.rb +185 -175
- data/lib/kappa/team.rb +99 -99
- data/lib/kappa/twitch.rb +13 -11
- data/lib/kappa/user.rb +124 -132
- data/lib/kappa/version.rb +3 -1
- data/lib/kappa/video.rb +150 -100
- metadata +100 -38
data/README.md
CHANGED
@@ -1,148 +1,184 @@
|
|
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
|
-
|
14
|
-
|
15
|
-
```
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
c
|
36
|
-
c.
|
37
|
-
c.
|
38
|
-
c.
|
39
|
-
c.
|
40
|
-
c.
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
s
|
53
|
-
s.
|
54
|
-
s.
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
u
|
67
|
-
u.
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
v
|
80
|
-
v.
|
81
|
-
v.
|
82
|
-
v.
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
t
|
95
|
-
t.
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
```
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
g.
|
114
|
-
g.
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
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
|
+
include Kappa::V2
|
21
|
+
|
22
|
+
grubby = Channel.get('followgrubby')
|
23
|
+
puts grubby.streaming?
|
24
|
+
```
|
25
|
+
|
26
|
+
## Overview
|
27
|
+
|
28
|
+
### <a id="channels"></a>Channels
|
29
|
+
|
30
|
+
Channels serve as the home location for a [user's](#users) content. Channels have a [stream](#streams), can run commercials, store [videos](#videos), display information and status, and have a customized page including banners and backgrounds.
|
31
|
+
|
32
|
+
See also [`Channel`](http://rdoc.info/gems/kappa/Kappa/V2/Channel) documentation.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
c = Channel.get('destiny')
|
36
|
+
c.nil? # => false (channel exists)
|
37
|
+
c.stream # => #<Kappa::V2::Stream> (current live stream)
|
38
|
+
c.url # => "http://www.twitch.tv/destiny"
|
39
|
+
c.status # => "Destiny - Diamond I ADC - Number 1 Draven player..."
|
40
|
+
c.teams # => [#<Kappa::V2::Team>]
|
41
|
+
c.videos # => [#<Kappa::V2::Video>, ...]
|
42
|
+
c.followers # => [#<Kappa::V2::User>, ...]
|
43
|
+
```
|
44
|
+
|
45
|
+
### <a id="streams"></a>Streams
|
46
|
+
|
47
|
+
Streams are video broadcasts that are currently live. They belong to a [user](#users) and are part of a [channel](#channels).
|
48
|
+
|
49
|
+
See also [`Stream`](http://rdoc.info/gems/kappa/Kappa/V2/Stream) and [`Streams`](http://rdoc.info/gems/kappa/Kappa/V2/Streams) documentation.
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
s = Stream.get('idrajit')
|
53
|
+
s.nil? # => false (currently live)
|
54
|
+
s.game_name # => "StarCraft II: Heart of the Swarm"
|
55
|
+
s.viewer_count # => 7267
|
56
|
+
s.channel.url # => "http://www.twitch.tv/idrajit"
|
57
|
+
```
|
58
|
+
|
59
|
+
### <a id="users"></a>Users
|
60
|
+
|
61
|
+
These are members of the Twitch community who have a Twitch account. If broadcasting, they can own a [stream](#streams) that they can broadcast on their [channel](#channels). If mainly viewing, they might follow or subscribe to channels.
|
62
|
+
|
63
|
+
See also [`User`](http://rdoc.info/gems/kappa/Kappa/V2/User) documentation.
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
u = User.get('snoopeh')
|
67
|
+
u.nil? # => false (user exists)
|
68
|
+
u.channel # => #<Kappa::V2::Channel>
|
69
|
+
u.following.map(&:name) # => ["national_esl1", "dreamhacklol", "riotgames"]
|
70
|
+
```
|
71
|
+
|
72
|
+
### <a id="videos"></a>Videos
|
73
|
+
|
74
|
+
Videos are broadcasts or highlights owned by a [channel](#channels). Broadcasts are unedited videos that are saved after a streaming session. Highlights are videos edited from broadcasts by the channel's owner.
|
75
|
+
|
76
|
+
See also [`Video`](http://rdoc.info/gems/kappa/Kappa/V2/Video) and [`Videos`](http://rdoc.info/gems/kappa/Kappa/V2/Videos) documentation.
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
v = Video.get('a395995729')
|
80
|
+
v.nil? # => false (video exists)
|
81
|
+
v.title # => "DreamHack Open Stockholm 26-27 April"
|
82
|
+
v.game_name # => "StarCraft II: Heart of the Swarm"
|
83
|
+
v.recorded_at # => 2013-04-26 18:33:48 UTC
|
84
|
+
v.view_count # => 12506
|
85
|
+
```
|
86
|
+
|
87
|
+
### <a id="teams"></a>Teams
|
88
|
+
|
89
|
+
Teams are an organization of [channels](#channels).
|
90
|
+
|
91
|
+
See also [`Team`](http://rdoc.info/gems/kappa/Kappa/V2/Team) documentation.
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
t = Team.get('teamliquid')
|
95
|
+
t.nil? # => false (team exists)
|
96
|
+
t.display_name # => "TeamLiquid"
|
97
|
+
t.info # => "TeamLiquid is awesome. and esports. video games. \n\n"
|
98
|
+
t.updated_at # => 2013-05-24 00:17:10 UTC
|
99
|
+
```
|
100
|
+
|
101
|
+
### <a id="games"></a>Games
|
102
|
+
|
103
|
+
Games are categories (e.g. League of Legends, Diablo 3) used by [streams](#streams) and [channels](#channels). Games can be searched for by query.
|
104
|
+
|
105
|
+
See also [`Game`](http://rdoc.info/gems/kappa/Kappa/V2/Game), [`Games`](http://rdoc.info/gems/kappa/Kappa/V2/Games), and [`GameSuggestion`](http://rdoc.info/gems/kappa/Kappa/V2/GameSuggestion) documentation.
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
top = Games.top(:limit => 3)
|
109
|
+
top.map(&:name) # => ["League of Legends", "Dota 2", "StarCraft II: Heart of the Swarm"]
|
110
|
+
```
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
g = Games.top(:limit => 1).first
|
114
|
+
g.name # => "League of Legends"
|
115
|
+
g.channel_count # => 906
|
116
|
+
g.viewer_count # => 79223
|
117
|
+
g.box_images.medium_url # =>"http://static-cdn.jtvnw.net/ttv-boxart/League%20of%20Legends-272x380.jpg"
|
118
|
+
```
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
s = Games.find(:name => 'diablo', :live => true)
|
122
|
+
s.map(&:name) # => ["Diablo III", "Diablo II", "Diablo", "Diablo II: Lord of Destruction"]
|
123
|
+
s.map(&:popularity) # => [120, 4, 1, 1]
|
124
|
+
```
|
125
|
+
|
126
|
+
## Examples
|
127
|
+
|
128
|
+
## Documentation
|
129
|
+
|
130
|
+
- Current release: [http://rdoc.info/gems/kappa/frames](http://rdoc.info/gems/kappa/frames)
|
131
|
+
- Latest master: [http://rdoc.info/github/schmich/kappa/frames](http://rdoc.info/github/schmich/kappa/frames)
|
132
|
+
- Twitch REST API: [https://github.com/justintv/Twitch-API](https://github.com/justintv/Twitch-API)
|
133
|
+
|
134
|
+
## Versioning
|
135
|
+
|
136
|
+
### Library version
|
137
|
+
|
138
|
+
Kappa adheres to the [Semantic Versioning 2.0.0](http://semver.org/) specification. Most importantly, any
|
139
|
+
compatibility- or API-breaking changes will result in a new major version (e.g. `1.x.x` to `2.x.x`). Because
|
140
|
+
of this, you should use a [pessimistic version constraint](http://docs.rubygems.org/read/chapter/16#page74) when
|
141
|
+
taking a dependency on this library. For example:
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
gem 'kappa', '~> 1.0'
|
145
|
+
```
|
146
|
+
|
147
|
+
Any new backwards-compatible features will result in a new minor version (e.g. `x.1.x` to `x.2.x`) while any
|
148
|
+
backwards-compatible bugfixes will result in a new patch version (e.g. `x.x.1` to `x.x.2`).
|
149
|
+
|
150
|
+
### Twitch API versions
|
151
|
+
|
152
|
+
Twitch supports multiple versions of their API simultaneously, with each version potentially providing different data and behaving differently. Because of this, you must specify which version of the Twitch API you wish to use. With Kappa, this is done with modules.
|
153
|
+
|
154
|
+
For example, if you want to use the v2 Twitch API:
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
# Option 1: Include the module once.
|
158
|
+
include Kappa::V2
|
159
|
+
c = Channel.get('day9tv')
|
160
|
+
u = User.get('artosis')
|
161
|
+
```
|
162
|
+
```ruby
|
163
|
+
# Option 2: Specify the full class name each time.
|
164
|
+
c = Kappa::V2::Channel.get('day9tv')
|
165
|
+
u = Kappa::V2::User.get('artosis')
|
166
|
+
```
|
167
|
+
|
168
|
+
## Contributing
|
169
|
+
|
170
|
+
- [Fork and clone the repo.](http://help.github.com/fork-a-repo/)
|
171
|
+
- [Create a branch for your changes.](http://learn.github.com/p/branching.html)
|
172
|
+
- Run `bundle install` to install development requirements.
|
173
|
+
- Implement your feature or bug fix.
|
174
|
+
- Add specs under the `spec` folder to prevent regressions or to test new code.
|
175
|
+
- Add [YARD](http://rubydoc.info/docs/yard/file/docs/GettingStarted.md) documentation for new features. Run `rake yard` to view documentation.
|
176
|
+
- 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.
|
177
|
+
- Commit and push your changes.
|
178
|
+
- [Submit a pull request.](http://help.github.com/send-pull-requests/)
|
179
|
+
|
180
|
+
## License
|
181
|
+
|
182
|
+
Copyright © 2013 Chris Schmich
|
183
|
+
<br />
|
184
|
+
MIT License, See [LICENSE](LICENSE) for details.
|
data/lib/kappa.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
require 'kappa/id_equality'
|
2
|
-
require 'kappa/
|
3
|
-
require 'kappa/
|
4
|
-
require 'kappa/
|
5
|
-
require 'kappa/
|
6
|
-
require 'kappa/
|
7
|
-
require 'kappa/
|
8
|
-
require 'kappa/
|
9
|
-
require 'kappa/
|
10
|
-
require 'kappa/
|
11
|
-
require 'kappa/
|
1
|
+
require 'kappa/id_equality'
|
2
|
+
require 'kappa/proxy'
|
3
|
+
require 'kappa/connection'
|
4
|
+
require 'kappa/channel'
|
5
|
+
require 'kappa/stream'
|
6
|
+
require 'kappa/game'
|
7
|
+
require 'kappa/video'
|
8
|
+
require 'kappa/team'
|
9
|
+
require 'kappa/user'
|
10
|
+
require 'kappa/images'
|
11
|
+
require 'kappa/twitch'
|
12
|
+
require 'kappa/version'
|
data/lib/kappa/channel.rb
CHANGED
@@ -1,184 +1,143 @@
|
|
1
|
-
require 'cgi'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# @see
|
9
|
-
# @see
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
#
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@
|
23
|
-
@
|
24
|
-
@
|
25
|
-
@
|
26
|
-
@
|
27
|
-
@
|
28
|
-
@
|
29
|
-
@
|
30
|
-
|
31
|
-
@
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
#
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
#
|
83
|
-
# @
|
84
|
-
#
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
#
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
#
|
108
|
-
|
109
|
-
|
110
|
-
# @
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
#
|
117
|
-
|
118
|
-
|
119
|
-
# @
|
120
|
-
|
121
|
-
|
122
|
-
# @
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
# @return [Fixnum] Unique Twitch ID.
|
146
|
-
attr_reader :id
|
147
|
-
|
148
|
-
# @return [String] URL for background image.
|
149
|
-
attr_reader :background_url
|
150
|
-
|
151
|
-
# @return [String] URL for banner image.
|
152
|
-
attr_reader :banner_url
|
153
|
-
|
154
|
-
# @return [DateTime] When the channel was created.
|
155
|
-
attr_reader :created_at
|
156
|
-
|
157
|
-
# @return [String] User-friendly display name. This name is used for the channel's page title.
|
158
|
-
attr_reader :display_name
|
159
|
-
|
160
|
-
# @return [String] Name of the primary game for this channel.
|
161
|
-
attr_reader :game_name
|
162
|
-
|
163
|
-
# @return [String] URL for the logo image.
|
164
|
-
attr_reader :logo_url
|
165
|
-
|
166
|
-
# @return [String] Unique Twitch name.
|
167
|
-
attr_reader :name
|
168
|
-
|
169
|
-
# @return [String] Current status set by the channel's owner.
|
170
|
-
attr_reader :status
|
171
|
-
|
172
|
-
# @return [DateTime] When the channel was last updated. When a stream is started, its channel is updated.
|
173
|
-
attr_reader :updated_at
|
174
|
-
|
175
|
-
# @return [String] The URL for the channel's main page.
|
176
|
-
attr_reader :url
|
177
|
-
|
178
|
-
# @return [String] URL for the image shown when the stream is offline.
|
179
|
-
attr_reader :video_banner_url
|
180
|
-
|
181
|
-
# @return [Array<Team>] The list of teams that this channel is associated with. Not all channels have associated teams.
|
182
|
-
attr_reader :teams
|
183
|
-
end
|
184
|
-
end
|
1
|
+
require 'cgi'
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
module Kappa::V2
|
5
|
+
# Channels serve as the home location for a user's content. Channels have a stream, can run
|
6
|
+
# commercials, store videos, display information and status, and have a customized page including
|
7
|
+
# banners and backgrounds.
|
8
|
+
# @see .get Channel.get
|
9
|
+
# @see Stream
|
10
|
+
# @see User
|
11
|
+
class Channel
|
12
|
+
include Connection
|
13
|
+
include Kappa::IdEquality
|
14
|
+
|
15
|
+
# @private
|
16
|
+
def initialize(hash)
|
17
|
+
@id = hash['_id']
|
18
|
+
@background_url = hash['background']
|
19
|
+
@banner_url = hash['banner']
|
20
|
+
@created_at = Time.parse(hash['created_at']).utc
|
21
|
+
@display_name = hash['display_name']
|
22
|
+
@game_name = hash['game']
|
23
|
+
@logo_url = hash['logo']
|
24
|
+
@mature = hash['mature'] || false
|
25
|
+
@name = hash['name']
|
26
|
+
@status = hash['status']
|
27
|
+
@updated_at = Time.parse(hash['updated_at']).utc
|
28
|
+
@url = hash['url']
|
29
|
+
@video_banner_url = hash['video_banner']
|
30
|
+
|
31
|
+
@teams = []
|
32
|
+
teams = hash['teams']
|
33
|
+
teams.each do |team_json|
|
34
|
+
@teams << Team.new(team_json)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Get a channel by name.
|
39
|
+
# @param channel_name [String] The name of the channel to get. This is the same as the stream or user name.
|
40
|
+
# @return [Channel] A valid `Channel` object if the channel exists, `nil` otherwise.
|
41
|
+
def self.get(channel_name)
|
42
|
+
encoded_name = CGI.escape(channel_name)
|
43
|
+
json = connection.get("channels/#{encoded_name}")
|
44
|
+
|
45
|
+
# HTTP 422 can happen if the channel is associated with a Justin.tv account.
|
46
|
+
if !json || json['status'] == 404 || json['status'] == 422
|
47
|
+
nil
|
48
|
+
else
|
49
|
+
new(json)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Does this channel have mature content? This flag is specified by the owner of the channel.
|
54
|
+
# @return [Boolean] `true` if the channel has mature content, `false` otherwise.
|
55
|
+
def mature?
|
56
|
+
@mature
|
57
|
+
end
|
58
|
+
|
59
|
+
# Get the live stream associated with this channel.
|
60
|
+
# @note This incurs an additional web request.
|
61
|
+
# @return [Stream] Live stream object for this channel, or `nil` if the channel is not currently streaming.
|
62
|
+
# @see #streaming?
|
63
|
+
def stream
|
64
|
+
Stream.get(@name)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Does this channel currently have a live stream?
|
68
|
+
# @note This makes a separate request to get the channel's stream. If you want to actually use the stream object, you should call `#stream` instead.
|
69
|
+
# @return [Boolean] `true` if the channel currently has a live stream, `false` otherwise.
|
70
|
+
# @see #stream
|
71
|
+
def streaming?
|
72
|
+
!stream.nil?
|
73
|
+
end
|
74
|
+
|
75
|
+
# Get the owner of this channel.
|
76
|
+
# @note This incurs an additional web request.
|
77
|
+
# @return [User] The user that owns this channel.
|
78
|
+
def user
|
79
|
+
User.get(@name)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Get the users following this channel.
|
83
|
+
# @note The number of followers is potentially very large, so it's recommended that you specify a `:limit`.
|
84
|
+
# @param options [Hash] Filter criteria.
|
85
|
+
# @option options [Fixnum] :limit (none) Limit on the number of results returned.
|
86
|
+
# @option options [Fixnum] :offset (0) Offset into the result set to begin enumeration.
|
87
|
+
# @see User
|
88
|
+
# @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/channels.md#get-channelschannelfollows GET /channels/:channel/follows
|
89
|
+
# @return [Array<User>] List of users following this channel.
|
90
|
+
def followers(options = {})
|
91
|
+
params = {}
|
92
|
+
|
93
|
+
return connection.accumulate(
|
94
|
+
:path => "channels/#{@name}/follows",
|
95
|
+
:params => params,
|
96
|
+
:json => 'follows',
|
97
|
+
:sub_json => 'user',
|
98
|
+
:class => User,
|
99
|
+
:limit => options[:limit],
|
100
|
+
:offset => options[:offset]
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
# @return [Fixnum] Unique Twitch ID.
|
105
|
+
attr_reader :id
|
106
|
+
|
107
|
+
# @return [String] URL for background image.
|
108
|
+
attr_reader :background_url
|
109
|
+
|
110
|
+
# @return [String] URL for banner image.
|
111
|
+
attr_reader :banner_url
|
112
|
+
|
113
|
+
# @return [Time] When the channel was created (UTC).
|
114
|
+
attr_reader :created_at
|
115
|
+
|
116
|
+
# @return [String] User-friendly display name. This name is used for the channel's page title.
|
117
|
+
attr_reader :display_name
|
118
|
+
|
119
|
+
# @return [String] Name of the primary game for this channel.
|
120
|
+
attr_reader :game_name
|
121
|
+
|
122
|
+
# @return [String] URL for the logo image.
|
123
|
+
attr_reader :logo_url
|
124
|
+
|
125
|
+
# @return [String] Unique Twitch name.
|
126
|
+
attr_reader :name
|
127
|
+
|
128
|
+
# @return [String] Current status set by the channel's owner.
|
129
|
+
attr_reader :status
|
130
|
+
|
131
|
+
# @return [Time] When the channel was last updated (UTC). For example, when a stream is started, its channel is updated.
|
132
|
+
attr_reader :updated_at
|
133
|
+
|
134
|
+
# @return [String] The URL for the channel's main page.
|
135
|
+
attr_reader :url
|
136
|
+
|
137
|
+
# @return [String] URL for the image shown when the stream is offline.
|
138
|
+
attr_reader :video_banner_url
|
139
|
+
|
140
|
+
# @return [Array<Team>] The list of teams that this channel is associated with. Not all channels have associated teams.
|
141
|
+
attr_reader :teams
|
142
|
+
end
|
143
|
+
end
|