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/lib/kappa.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
require 'kappa/id_equality'
|
2
|
-
require 'kappa/proxy'
|
3
|
-
require 'kappa/status'
|
4
|
-
require 'kappa/errors'
|
5
|
-
require 'kappa/connection'
|
6
|
-
require 'kappa/configuration'
|
7
|
-
require 'kappa/query'
|
8
|
-
require 'kappa/channel'
|
9
|
-
require 'kappa/stream'
|
10
|
-
require 'kappa/game'
|
11
|
-
require 'kappa/video'
|
12
|
-
require 'kappa/team'
|
13
|
-
require 'kappa/user'
|
14
|
-
require 'kappa/images'
|
15
|
-
require 'kappa/version'
|
1
|
+
require 'kappa/id_equality'
|
2
|
+
require 'kappa/proxy'
|
3
|
+
require 'kappa/status'
|
4
|
+
require 'kappa/errors'
|
5
|
+
require 'kappa/connection'
|
6
|
+
require 'kappa/configuration'
|
7
|
+
require 'kappa/query'
|
8
|
+
require 'kappa/channel'
|
9
|
+
require 'kappa/stream'
|
10
|
+
require 'kappa/game'
|
11
|
+
require 'kappa/video'
|
12
|
+
require 'kappa/team'
|
13
|
+
require 'kappa/user'
|
14
|
+
require 'kappa/images'
|
15
|
+
require 'kappa/version'
|
data/lib/kappa/channel.rb
CHANGED
@@ -1,214 +1,214 @@
|
|
1
|
-
require 'cgi'
|
2
|
-
require 'time'
|
3
|
-
|
4
|
-
module Twitch::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 Channels#get Channels#get
|
9
|
-
# @see Channels
|
10
|
-
# @see Stream
|
11
|
-
# @see User
|
12
|
-
class Channel
|
13
|
-
include Twitch::IdEquality
|
14
|
-
|
15
|
-
# @private
|
16
|
-
def initialize(hash, query)
|
17
|
-
@query = query
|
18
|
-
@id = hash['_id']
|
19
|
-
@background_url = hash['background']
|
20
|
-
@banner_url = hash['banner']
|
21
|
-
@created_at = Time.parse(hash['created_at']).utc
|
22
|
-
@display_name = hash['display_name']
|
23
|
-
@game_name = hash['game']
|
24
|
-
@logo_url = hash['logo']
|
25
|
-
@mature = hash['mature'] || false
|
26
|
-
@name = hash['name']
|
27
|
-
@status = hash['status']
|
28
|
-
@updated_at = Time.parse(hash['updated_at']).utc
|
29
|
-
@url = hash['url']
|
30
|
-
@video_banner_url = hash['video_banner']
|
31
|
-
|
32
|
-
@teams = []
|
33
|
-
teams = hash['teams']
|
34
|
-
teams.each do |team_json|
|
35
|
-
@teams << Team.new(team_json)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
# Does this channel have mature content? This flag is specified by the owner of the channel.
|
40
|
-
# @return [Boolean] `true` if the channel has mature content, `false` otherwise.
|
41
|
-
def mature?
|
42
|
-
@mature
|
43
|
-
end
|
44
|
-
|
45
|
-
# Get the live stream associated with this channel.
|
46
|
-
# @note This incurs an additional web request.
|
47
|
-
# @return [Stream] Live stream object for this channel, or `nil` if the channel is not currently streaming.
|
48
|
-
# @see #streaming?
|
49
|
-
def stream
|
50
|
-
@query.streams.get(@name)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Does this channel currently have a live stream?
|
54
|
-
# @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.
|
55
|
-
# @return [Boolean] `true` if the channel currently has a live stream, `false` otherwise.
|
56
|
-
# @see #stream
|
57
|
-
def streaming?
|
58
|
-
!stream.nil?
|
59
|
-
end
|
60
|
-
|
61
|
-
# Get the owner of this channel.
|
62
|
-
# @note This incurs an additional web request.
|
63
|
-
# @return [User] The user that owns this channel.
|
64
|
-
def user
|
65
|
-
@query.users.get(@name)
|
66
|
-
end
|
67
|
-
|
68
|
-
# Get the users following this channel.
|
69
|
-
# @note The number of followers is potentially very large, so it's recommended that you specify a `:limit`.
|
70
|
-
# @example
|
71
|
-
# channel.followers(:limit => 20)
|
72
|
-
# @example
|
73
|
-
# channel.followers do |follower|
|
74
|
-
# puts follower.display_name
|
75
|
-
# end
|
76
|
-
# @param options [Hash] Filter criteria.
|
77
|
-
# @option options [Fixnum] :limit (nil) Limit on the number of results returned.
|
78
|
-
# @option options [Fixnum] :offset (0) Offset into the result set to begin enumeration.
|
79
|
-
# @yield Optional. If a block is given, each follower is yielded.
|
80
|
-
# @yieldparam [User] follower Current follower.
|
81
|
-
# @see User
|
82
|
-
# @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/channels.md#get-channelschannelfollows GET /channels/:channel/follows
|
83
|
-
# @return [Array<User>] Users following this channel, if no block is given.
|
84
|
-
# @return [nil] If a block is given.
|
85
|
-
def followers(options = {}, &block)
|
86
|
-
name = CGI.escape(@name)
|
87
|
-
return @query.connection.accumulate(
|
88
|
-
:path => "channels/#{name}/follows",
|
89
|
-
:json => 'follows',
|
90
|
-
:sub_json => 'user',
|
91
|
-
:create => -> hash { User.new(hash, @query) },
|
92
|
-
:limit => options[:limit],
|
93
|
-
:offset => options[:offset],
|
94
|
-
&block
|
95
|
-
)
|
96
|
-
end
|
97
|
-
|
98
|
-
# Get the videos for a channel, most recently created first.
|
99
|
-
# @note This incurs additional web requests.
|
100
|
-
# @note You can get videos directly from a channel name via {Videos#for_channel}.
|
101
|
-
# @example
|
102
|
-
# v = channel.videos(:type => :broadcasts)
|
103
|
-
# @example
|
104
|
-
# channel.videos(:type => :highlights) do |video|
|
105
|
-
# next if video.view_count < 10000
|
106
|
-
# puts video.url
|
107
|
-
# end
|
108
|
-
# @param options [Hash] Filter criteria.
|
109
|
-
# @option options [Symbol] :type (:highlights) The type of videos to return. Valid values are `:broadcasts`, `:highlights`.
|
110
|
-
# @option options [Fixnum] :limit (nil) Limit on the number of results returned.
|
111
|
-
# @option options [Fixnum] :offset (0) Offset into the result set to begin enumeration.
|
112
|
-
# @yield Optional. If a block is given, each video is yielded.
|
113
|
-
# @yieldparam [Video] video Current video.
|
114
|
-
# @see Video
|
115
|
-
# @see Videos#for_channel Videos#for_channel
|
116
|
-
# @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/videos.md#get-channelschannelvideos GET /channels/:channel/videos
|
117
|
-
# @raise [ArgumentError] If `:type` is not one of `:broadcasts` or `:highlights`.
|
118
|
-
# @return [Array<Video>] Videos for the channel, if no block is given.
|
119
|
-
# @return [nil] If a block is given.
|
120
|
-
def videos(options = {}, &block)
|
121
|
-
@query.videos.for_channel(@name, options, &block)
|
122
|
-
end
|
123
|
-
|
124
|
-
# @example
|
125
|
-
# 23460970
|
126
|
-
# @return [Fixnum] Unique Twitch ID.
|
127
|
-
attr_reader :id
|
128
|
-
|
129
|
-
# @example
|
130
|
-
# "http://static-cdn.jtvnw.net/jtv_user_pictures/lethalfrag-channel_background_image-833a4324bc698c9b.jpeg"
|
131
|
-
# @return [String] URL for background image.
|
132
|
-
attr_reader :background_url
|
133
|
-
|
134
|
-
# @example
|
135
|
-
# "http://static-cdn.jtvnw.net/jtv_user_pictures/lethalfrag-channel_header_image-463a4670c91c2b61-640x125.jpeg"
|
136
|
-
# @return [String] URL for banner image.
|
137
|
-
attr_reader :banner_url
|
138
|
-
|
139
|
-
# @example
|
140
|
-
# 2011-07-15 07:53:58 UTC
|
141
|
-
# @return [Time] When the channel was created (UTC).
|
142
|
-
attr_reader :created_at
|
143
|
-
|
144
|
-
# @example
|
145
|
-
# "Lethalfrag"
|
146
|
-
# @see #name
|
147
|
-
# @return [String] User-friendly display name. This name is used for the channel's page title.
|
148
|
-
attr_reader :display_name
|
149
|
-
|
150
|
-
# @example
|
151
|
-
# "Super Meat Boy"
|
152
|
-
# @return [String] Name of the primary game for this channel.
|
153
|
-
attr_reader :game_name
|
154
|
-
|
155
|
-
# @example
|
156
|
-
# "http://static-cdn.jtvnw.net/jtv_user_pictures/lethalfrag-profile_image-050adf252718823b-300x300.png"
|
157
|
-
# @return [String] URL for the logo image.
|
158
|
-
attr_reader :logo_url
|
159
|
-
|
160
|
-
# @example
|
161
|
-
# "lethalfrag"
|
162
|
-
# @see #display_name
|
163
|
-
# @return [String] Unique Twitch name.
|
164
|
-
attr_reader :name
|
165
|
-
|
166
|
-
# @example
|
167
|
-
# "(Day 563/731) | Dinner and a Game (Cooking at http://twitch.tv/lookatmychicken)"
|
168
|
-
# @return [String] Current status set by the channel's owner.
|
169
|
-
attr_reader :status
|
170
|
-
|
171
|
-
# @example
|
172
|
-
# 2013-07-21 05:27:58 UTC
|
173
|
-
# @return [Time] When the channel was last updated (UTC). For example, when a stream is started or a channel's status is changed, the channel is updated.
|
174
|
-
attr_reader :updated_at
|
175
|
-
|
176
|
-
# @example
|
177
|
-
# "http://www.twitch.tv/lethalfrag"
|
178
|
-
# @return [String] The URL for the channel's main page.
|
179
|
-
attr_reader :url
|
180
|
-
|
181
|
-
# @example
|
182
|
-
# "http://static-cdn.jtvnw.net/jtv_user_pictures/lethalfrag-channel_offline_image-3b801b2ccc11830b-640x360.jpeg"
|
183
|
-
# @return [String] URL for the image shown when the stream is offline.
|
184
|
-
attr_reader :video_banner_url
|
185
|
-
|
186
|
-
# @see Team
|
187
|
-
# @return [Array<Team>] The list of teams that this channel is associated with. Not all channels have associated teams.
|
188
|
-
attr_reader :teams
|
189
|
-
end
|
190
|
-
|
191
|
-
# Query class for finding channels.
|
192
|
-
# @see Channel
|
193
|
-
class Channels
|
194
|
-
# @private
|
195
|
-
def initialize(query)
|
196
|
-
@query = query
|
197
|
-
end
|
198
|
-
|
199
|
-
# Get a channel by name.
|
200
|
-
# @example
|
201
|
-
# c = Twitch.channels.get('day9tv')
|
202
|
-
# @param channel_name [String] The name of the channel to get. This is the same as the stream or user name.
|
203
|
-
# @return [Channel] A valid `Channel` object if the channel exists, `nil` otherwise.
|
204
|
-
def get(channel_name)
|
205
|
-
name = CGI.escape(channel_name)
|
206
|
-
|
207
|
-
# HTTP 422 can happen if the channel is associated with a Justin.tv account.
|
208
|
-
Twitch::Status.map(404 => nil, 422 => nil) do
|
209
|
-
json = @query.connection.get("channels/#{name}")
|
210
|
-
Channel.new(json, @query)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
1
|
+
require 'cgi'
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
module Twitch::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 Channels#get Channels#get
|
9
|
+
# @see Channels
|
10
|
+
# @see Stream
|
11
|
+
# @see User
|
12
|
+
class Channel
|
13
|
+
include Twitch::IdEquality
|
14
|
+
|
15
|
+
# @private
|
16
|
+
def initialize(hash, query)
|
17
|
+
@query = query
|
18
|
+
@id = hash['_id']
|
19
|
+
@background_url = hash['background']
|
20
|
+
@banner_url = hash['banner']
|
21
|
+
@created_at = Time.parse(hash['created_at']).utc
|
22
|
+
@display_name = hash['display_name']
|
23
|
+
@game_name = hash['game']
|
24
|
+
@logo_url = hash['logo']
|
25
|
+
@mature = hash['mature'] || false
|
26
|
+
@name = hash['name']
|
27
|
+
@status = hash['status']
|
28
|
+
@updated_at = Time.parse(hash['updated_at']).utc
|
29
|
+
@url = hash['url']
|
30
|
+
@video_banner_url = hash['video_banner']
|
31
|
+
|
32
|
+
@teams = []
|
33
|
+
teams = hash['teams']
|
34
|
+
teams.each do |team_json|
|
35
|
+
@teams << Team.new(team_json)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Does this channel have mature content? This flag is specified by the owner of the channel.
|
40
|
+
# @return [Boolean] `true` if the channel has mature content, `false` otherwise.
|
41
|
+
def mature?
|
42
|
+
@mature
|
43
|
+
end
|
44
|
+
|
45
|
+
# Get the live stream associated with this channel.
|
46
|
+
# @note This incurs an additional web request.
|
47
|
+
# @return [Stream] Live stream object for this channel, or `nil` if the channel is not currently streaming.
|
48
|
+
# @see #streaming?
|
49
|
+
def stream
|
50
|
+
@query.streams.get(@name)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Does this channel currently have a live stream?
|
54
|
+
# @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.
|
55
|
+
# @return [Boolean] `true` if the channel currently has a live stream, `false` otherwise.
|
56
|
+
# @see #stream
|
57
|
+
def streaming?
|
58
|
+
!stream.nil?
|
59
|
+
end
|
60
|
+
|
61
|
+
# Get the owner of this channel.
|
62
|
+
# @note This incurs an additional web request.
|
63
|
+
# @return [User] The user that owns this channel.
|
64
|
+
def user
|
65
|
+
@query.users.get(@name)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Get the users following this channel.
|
69
|
+
# @note The number of followers is potentially very large, so it's recommended that you specify a `:limit`.
|
70
|
+
# @example
|
71
|
+
# channel.followers(:limit => 20)
|
72
|
+
# @example
|
73
|
+
# channel.followers do |follower|
|
74
|
+
# puts follower.display_name
|
75
|
+
# end
|
76
|
+
# @param options [Hash] Filter criteria.
|
77
|
+
# @option options [Fixnum] :limit (nil) Limit on the number of results returned.
|
78
|
+
# @option options [Fixnum] :offset (0) Offset into the result set to begin enumeration.
|
79
|
+
# @yield Optional. If a block is given, each follower is yielded.
|
80
|
+
# @yieldparam [User] follower Current follower.
|
81
|
+
# @see User
|
82
|
+
# @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/channels.md#get-channelschannelfollows GET /channels/:channel/follows
|
83
|
+
# @return [Array<User>] Users following this channel, if no block is given.
|
84
|
+
# @return [nil] If a block is given.
|
85
|
+
def followers(options = {}, &block)
|
86
|
+
name = CGI.escape(@name)
|
87
|
+
return @query.connection.accumulate(
|
88
|
+
:path => "channels/#{name}/follows",
|
89
|
+
:json => 'follows',
|
90
|
+
:sub_json => 'user',
|
91
|
+
:create => -> hash { User.new(hash, @query) },
|
92
|
+
:limit => options[:limit],
|
93
|
+
:offset => options[:offset],
|
94
|
+
&block
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Get the videos for a channel, most recently created first.
|
99
|
+
# @note This incurs additional web requests.
|
100
|
+
# @note You can get videos directly from a channel name via {Videos#for_channel}.
|
101
|
+
# @example
|
102
|
+
# v = channel.videos(:type => :broadcasts)
|
103
|
+
# @example
|
104
|
+
# channel.videos(:type => :highlights) do |video|
|
105
|
+
# next if video.view_count < 10000
|
106
|
+
# puts video.url
|
107
|
+
# end
|
108
|
+
# @param options [Hash] Filter criteria.
|
109
|
+
# @option options [Symbol] :type (:highlights) The type of videos to return. Valid values are `:broadcasts`, `:highlights`.
|
110
|
+
# @option options [Fixnum] :limit (nil) Limit on the number of results returned.
|
111
|
+
# @option options [Fixnum] :offset (0) Offset into the result set to begin enumeration.
|
112
|
+
# @yield Optional. If a block is given, each video is yielded.
|
113
|
+
# @yieldparam [Video] video Current video.
|
114
|
+
# @see Video
|
115
|
+
# @see Videos#for_channel Videos#for_channel
|
116
|
+
# @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/videos.md#get-channelschannelvideos GET /channels/:channel/videos
|
117
|
+
# @raise [ArgumentError] If `:type` is not one of `:broadcasts` or `:highlights`.
|
118
|
+
# @return [Array<Video>] Videos for the channel, if no block is given.
|
119
|
+
# @return [nil] If a block is given.
|
120
|
+
def videos(options = {}, &block)
|
121
|
+
@query.videos.for_channel(@name, options, &block)
|
122
|
+
end
|
123
|
+
|
124
|
+
# @example
|
125
|
+
# 23460970
|
126
|
+
# @return [Fixnum] Unique Twitch ID.
|
127
|
+
attr_reader :id
|
128
|
+
|
129
|
+
# @example
|
130
|
+
# "http://static-cdn.jtvnw.net/jtv_user_pictures/lethalfrag-channel_background_image-833a4324bc698c9b.jpeg"
|
131
|
+
# @return [String] URL for background image.
|
132
|
+
attr_reader :background_url
|
133
|
+
|
134
|
+
# @example
|
135
|
+
# "http://static-cdn.jtvnw.net/jtv_user_pictures/lethalfrag-channel_header_image-463a4670c91c2b61-640x125.jpeg"
|
136
|
+
# @return [String] URL for banner image.
|
137
|
+
attr_reader :banner_url
|
138
|
+
|
139
|
+
# @example
|
140
|
+
# 2011-07-15 07:53:58 UTC
|
141
|
+
# @return [Time] When the channel was created (UTC).
|
142
|
+
attr_reader :created_at
|
143
|
+
|
144
|
+
# @example
|
145
|
+
# "Lethalfrag"
|
146
|
+
# @see #name
|
147
|
+
# @return [String] User-friendly display name. This name is used for the channel's page title.
|
148
|
+
attr_reader :display_name
|
149
|
+
|
150
|
+
# @example
|
151
|
+
# "Super Meat Boy"
|
152
|
+
# @return [String] Name of the primary game for this channel.
|
153
|
+
attr_reader :game_name
|
154
|
+
|
155
|
+
# @example
|
156
|
+
# "http://static-cdn.jtvnw.net/jtv_user_pictures/lethalfrag-profile_image-050adf252718823b-300x300.png"
|
157
|
+
# @return [String] URL for the logo image.
|
158
|
+
attr_reader :logo_url
|
159
|
+
|
160
|
+
# @example
|
161
|
+
# "lethalfrag"
|
162
|
+
# @see #display_name
|
163
|
+
# @return [String] Unique Twitch name.
|
164
|
+
attr_reader :name
|
165
|
+
|
166
|
+
# @example
|
167
|
+
# "(Day 563/731) | Dinner and a Game (Cooking at http://twitch.tv/lookatmychicken)"
|
168
|
+
# @return [String] Current status set by the channel's owner.
|
169
|
+
attr_reader :status
|
170
|
+
|
171
|
+
# @example
|
172
|
+
# 2013-07-21 05:27:58 UTC
|
173
|
+
# @return [Time] When the channel was last updated (UTC). For example, when a stream is started or a channel's status is changed, the channel is updated.
|
174
|
+
attr_reader :updated_at
|
175
|
+
|
176
|
+
# @example
|
177
|
+
# "http://www.twitch.tv/lethalfrag"
|
178
|
+
# @return [String] The URL for the channel's main page.
|
179
|
+
attr_reader :url
|
180
|
+
|
181
|
+
# @example
|
182
|
+
# "http://static-cdn.jtvnw.net/jtv_user_pictures/lethalfrag-channel_offline_image-3b801b2ccc11830b-640x360.jpeg"
|
183
|
+
# @return [String] URL for the image shown when the stream is offline.
|
184
|
+
attr_reader :video_banner_url
|
185
|
+
|
186
|
+
# @see Team
|
187
|
+
# @return [Array<Team>] The list of teams that this channel is associated with. Not all channels have associated teams.
|
188
|
+
attr_reader :teams
|
189
|
+
end
|
190
|
+
|
191
|
+
# Query class for finding channels.
|
192
|
+
# @see Channel
|
193
|
+
class Channels
|
194
|
+
# @private
|
195
|
+
def initialize(query)
|
196
|
+
@query = query
|
197
|
+
end
|
198
|
+
|
199
|
+
# Get a channel by name.
|
200
|
+
# @example
|
201
|
+
# c = Twitch.channels.get('day9tv')
|
202
|
+
# @param channel_name [String] The name of the channel to get. This is the same as the stream or user name.
|
203
|
+
# @return [Channel] A valid `Channel` object if the channel exists, `nil` otherwise.
|
204
|
+
def get(channel_name)
|
205
|
+
name = CGI.escape(channel_name)
|
206
|
+
|
207
|
+
# HTTP 422 can happen if the channel is associated with a Justin.tv account.
|
208
|
+
Twitch::Status.map(404 => nil, 422 => nil) do
|
209
|
+
json = @query.connection.get("channels/#{name}")
|
210
|
+
Channel.new(json, @query)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|