kappa 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,132 +1,132 @@
1
- require 'cgi'
2
- require 'time'
3
-
4
- module Twitch::V2
5
- # Teams are an organization of channels.
6
- # @see Teams#get Teams#get
7
- # @see Teams#all Teams#all
8
- # @see Teams
9
- # @see Channel
10
- class Team
11
- include Twitch::IdEquality
12
-
13
- # @private
14
- def initialize(hash)
15
- @id = hash['_id']
16
- @info = hash['info']
17
- @background_url = hash['background']
18
- @banner_url = hash['banner']
19
- @logo_url = hash['logo']
20
- @name = hash['name']
21
- @display_name = hash['display_name']
22
- @updated_at = Time.parse(hash['updated_at']).utc
23
- @created_at = Time.parse(hash['created_at']).utc
24
-
25
- name = CGI.escape(@name)
26
- @url = "http://www.twitch.tv/team/#{name}"
27
- end
28
-
29
- # @example
30
- # 12
31
- # @return [Fixnum] Unique Twitch ID.
32
- attr_reader :id
33
-
34
- # @example
35
- # "TeamLiquid is awesome. and esports. video games. \n\n"
36
- # @return [String] Info about the team. This is displayed on the team's page and can contain HTML.
37
- attr_reader :info
38
-
39
- # @example
40
- # "http://static-cdn.jtvnw.net/jtv_user_pictures/team-eg-background_image-da36973b6d829ac6.png"
41
- # @return [String] URL for background image.
42
- attr_reader :background_url
43
-
44
- # @example
45
- # "http://static-cdn.jtvnw.net/jtv_user_pictures/team-eg-banner_image-1ad9c4738f4698b1-640x125.png"
46
- # @return [String] URL for banner image.
47
- attr_reader :banner_url
48
-
49
- # @example
50
- # "http://static-cdn.jtvnw.net/jtv_user_pictures/team-eg-team_logo_image-9107b874d4c3fc3b-300x300.jpeg"
51
- # @return [String] URL for the logo image.
52
- attr_reader :logo_url
53
-
54
- # @example
55
- # "teamliquid"
56
- # @see #display_name
57
- # @return [String] Unique Twitch name.
58
- attr_reader :name
59
-
60
- # @example
61
- # "TeamLiquid"
62
- # @see #name
63
- # @return [String] User-friendly display name. This name is used for the team's page title.
64
- attr_reader :display_name
65
-
66
- # @example
67
- # 2013-05-24 00:17:10 UTC
68
- # @return [Time] When the team was last updated (UTC).
69
- attr_reader :updated_at
70
-
71
- # @example
72
- # 2011-10-27 01:00:44 UTC
73
- # @return [Time] When the team was created (UTC).
74
- attr_reader :created_at
75
-
76
- # @example
77
- # "http://www.twitch.tv/team/teamliquid"
78
- # @return [String] URL for the team's Twitch landing page.
79
- attr_reader :url
80
- end
81
-
82
- # Query class for finding all active teams.
83
- # @see Team
84
- class Teams
85
- # @private
86
- def initialize(query)
87
- @query = query
88
- end
89
-
90
- # Get a team by name.
91
- # @example
92
- # Twitch.teams.get('teamliquid')
93
- # @param team_name [String] The name of the team to get.
94
- # @return [Team] A valid `Team` object if the team exists, `nil` otherwise.
95
- # @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/teams.md#get-teamsteam GET /teams/:team
96
- def get(team_name)
97
- name = CGI.escape(team_name)
98
- Twitch::Status.map(404 => nil) do
99
- json = @query.connection.get("teams/#{name}")
100
- Team.new(json)
101
- end
102
- end
103
-
104
- # Get the list of all active teams.
105
- # @example
106
- # Twitch.teams.all
107
- # @example
108
- # Twitch.teams.all(:limit => 10)
109
- # @example
110
- # Twitch.teams do |team|
111
- # next if (Time.now - team.updated_at) > (60 * 60 * 24)
112
- # puts team.url
113
- # end
114
- # @param options [Hash] Filter criteria.
115
- # @option options [Fixnum] :limit (nil) Limit on the number of results returned.
116
- # @yield Optional. If a block is given, each team is yielded.
117
- # @yieldparam [Team] team Current team.
118
- # @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/teams.md#get-teams GET /teams
119
- # @return [Array<Team>] All active teams, if no block is given.
120
- # @return [nil] If a block is given.
121
- def all(options = {}, &block)
122
- return @query.connection.accumulate(
123
- :path => 'teams',
124
- :json => 'teams',
125
- :create => Team,
126
- :limit => options[:limit],
127
- :offset => options[:offset],
128
- &block
129
- )
130
- end
131
- end
132
- end
1
+ require 'cgi'
2
+ require 'time'
3
+
4
+ module Twitch::V2
5
+ # Teams are an organization of channels.
6
+ # @see Teams#get Teams#get
7
+ # @see Teams#all Teams#all
8
+ # @see Teams
9
+ # @see Channel
10
+ class Team
11
+ include Twitch::IdEquality
12
+
13
+ # @private
14
+ def initialize(hash)
15
+ @id = hash['_id']
16
+ @info = hash['info']
17
+ @background_url = hash['background']
18
+ @banner_url = hash['banner']
19
+ @logo_url = hash['logo']
20
+ @name = hash['name']
21
+ @display_name = hash['display_name']
22
+ @updated_at = Time.parse(hash['updated_at']).utc
23
+ @created_at = Time.parse(hash['created_at']).utc
24
+
25
+ name = CGI.escape(@name)
26
+ @url = "http://www.twitch.tv/team/#{name}"
27
+ end
28
+
29
+ # @example
30
+ # 12
31
+ # @return [Fixnum] Unique Twitch ID.
32
+ attr_reader :id
33
+
34
+ # @example
35
+ # "TeamLiquid is awesome. and esports. video games. \n\n"
36
+ # @return [String] Info about the team. This is displayed on the team's page and can contain HTML.
37
+ attr_reader :info
38
+
39
+ # @example
40
+ # "http://static-cdn.jtvnw.net/jtv_user_pictures/team-eg-background_image-da36973b6d829ac6.png"
41
+ # @return [String] URL for background image.
42
+ attr_reader :background_url
43
+
44
+ # @example
45
+ # "http://static-cdn.jtvnw.net/jtv_user_pictures/team-eg-banner_image-1ad9c4738f4698b1-640x125.png"
46
+ # @return [String] URL for banner image.
47
+ attr_reader :banner_url
48
+
49
+ # @example
50
+ # "http://static-cdn.jtvnw.net/jtv_user_pictures/team-eg-team_logo_image-9107b874d4c3fc3b-300x300.jpeg"
51
+ # @return [String] URL for the logo image.
52
+ attr_reader :logo_url
53
+
54
+ # @example
55
+ # "teamliquid"
56
+ # @see #display_name
57
+ # @return [String] Unique Twitch name.
58
+ attr_reader :name
59
+
60
+ # @example
61
+ # "TeamLiquid"
62
+ # @see #name
63
+ # @return [String] User-friendly display name. This name is used for the team's page title.
64
+ attr_reader :display_name
65
+
66
+ # @example
67
+ # 2013-05-24 00:17:10 UTC
68
+ # @return [Time] When the team was last updated (UTC).
69
+ attr_reader :updated_at
70
+
71
+ # @example
72
+ # 2011-10-27 01:00:44 UTC
73
+ # @return [Time] When the team was created (UTC).
74
+ attr_reader :created_at
75
+
76
+ # @example
77
+ # "http://www.twitch.tv/team/teamliquid"
78
+ # @return [String] URL for the team's Twitch landing page.
79
+ attr_reader :url
80
+ end
81
+
82
+ # Query class for finding all active teams.
83
+ # @see Team
84
+ class Teams
85
+ # @private
86
+ def initialize(query)
87
+ @query = query
88
+ end
89
+
90
+ # Get a team by name.
91
+ # @example
92
+ # Twitch.teams.get('teamliquid')
93
+ # @param team_name [String] The name of the team to get.
94
+ # @return [Team] A valid `Team` object if the team exists, `nil` otherwise.
95
+ # @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/teams.md#get-teamsteam GET /teams/:team
96
+ def get(team_name)
97
+ name = CGI.escape(team_name)
98
+ Twitch::Status.map(404 => nil) do
99
+ json = @query.connection.get("teams/#{name}")
100
+ Team.new(json)
101
+ end
102
+ end
103
+
104
+ # Get the list of all active teams.
105
+ # @example
106
+ # Twitch.teams.all
107
+ # @example
108
+ # Twitch.teams.all(:limit => 10)
109
+ # @example
110
+ # Twitch.teams do |team|
111
+ # next if (Time.now - team.updated_at) > (60 * 60 * 24)
112
+ # puts team.url
113
+ # end
114
+ # @param options [Hash] Filter criteria.
115
+ # @option options [Fixnum] :limit (nil) Limit on the number of results returned.
116
+ # @yield Optional. If a block is given, each team is yielded.
117
+ # @yieldparam [Team] team Current team.
118
+ # @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/teams.md#get-teams GET /teams
119
+ # @return [Array<Team>] All active teams, if no block is given.
120
+ # @return [nil] If a block is given.
121
+ def all(options = {}, &block)
122
+ return @query.connection.accumulate(
123
+ :path => 'teams',
124
+ :json => 'teams',
125
+ :create => Team,
126
+ :limit => options[:limit],
127
+ :offset => options[:offset],
128
+ &block
129
+ )
130
+ end
131
+ end
132
+ end
@@ -1,159 +1,159 @@
1
- require 'cgi'
2
- require 'time'
3
-
4
- module Twitch::V2
5
- # These are members of the Twitch community who have a Twitch account. If broadcasting,
6
- # they can own a stream that they can broadcast on their channel. If mainly viewing,
7
- # they might follow or subscribe to channels.
8
- # @see Users#get Users#get
9
- # @see Users
10
- # @see Channel
11
- # @see Stream
12
- class User
13
- include Twitch::IdEquality
14
-
15
- # @private
16
- def initialize(hash, query)
17
- @query = query
18
- @id = hash['_id']
19
- @created_at = Time.parse(hash['created_at']).utc
20
- @display_name = hash['display_name']
21
- @logo_url = hash['logo']
22
- @name = hash['name']
23
- @staff = hash['staff'] || false
24
- @updated_at = Time.parse(hash['updated_at']).utc
25
- end
26
-
27
- # Get the `Channel` associated with this user.
28
- # @note This incurs an additional web request.
29
- # @return [Channel] The `Channel` associated with this user, or `nil` if this is a Justin.tv account.
30
- # @see Channel#get Channel#get
31
- def channel
32
- @query.channels.get(@name)
33
- end
34
-
35
- # Get the live stream associated with this user.
36
- # @note This incurs an additional web request.
37
- # @return [Stream] Live stream object for this user, or `nil` if the user is not currently streaming.
38
- # @see #streaming?
39
- def stream
40
- @query.streams.get(@name)
41
- end
42
-
43
- # Is this user currently streaming?
44
- # @note This makes a separate request to get the user's stream. If you want to actually use the stream object, you should call `#stream` instead.
45
- # @return [Boolean] `true` if the user currently has a live stream, `false` otherwise.
46
- # @see #stream
47
- def streaming?
48
- !stream.nil?
49
- end
50
-
51
- # @return [Boolean] `true` if the user is a member of the Twitch.tv staff, `false` otherwise.
52
- def staff?
53
- @staff
54
- end
55
-
56
- # Get the channels the user is currently following.
57
- # @example
58
- # user.following(:limit => 10)
59
- # @example
60
- # user.following do |channel|
61
- # next if channel.game_name !~ /starcraft/i
62
- # puts channel.display_name
63
- # end
64
- # @param options [Hash] Filter criteria.
65
- # @option options [Fixnum] :limit (nil) Limit on the number of results returned.
66
- # @option options [Fixnum] :offset (0) Offset into the result set to begin enumeration.
67
- # @yield Optional. If a block is given, each followed channel is yielded.
68
- # @yieldparam [Channel] channel Current channel.
69
- # @see #following?
70
- # @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/follows.md#get-usersuserfollowschannels GET /users/:user/follows/channels
71
- # @return [Array<Channel>] Channels the user is currently following, if no block is given.
72
- # @return [nil] If a block is given.
73
- def following(options = {}, &block)
74
- name = CGI.escape(@name)
75
- return @query.connection.accumulate(
76
- :path => "users/#{name}/follows/channels",
77
- :json => 'follows',
78
- :sub_json => 'channel',
79
- :create => -> hash { Channel.new(hash, @query) },
80
- :limit => options[:limit],
81
- :offset => options[:offset],
82
- &block
83
- )
84
- end
85
-
86
- # @param target [String, Channel, User, Stream, #name] The name of the channel to check.
87
- # @return [Boolean] `true` if the user is following the channel, `false` otherwise.
88
- # @see #following
89
- # @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/follows.md#get-usersuserfollowschannelstarget GET /users/:user/follows/channels/:target
90
- def following?(target)
91
- name = if target.respond_to?(:name)
92
- target.name
93
- else
94
- target.to_s
95
- end
96
-
97
- user_name = CGI.escape(@name)
98
- channel_name = CGI.escape(name)
99
-
100
- Twitch::Status.map(404 => false) do
101
- @query.connection.get("users/#{user_name}/follows/channels/#{channel_name}")
102
- true
103
- end
104
- end
105
-
106
- # @example
107
- # 23945610
108
- # @return [Fixnum] Unique Twitch ID.
109
- attr_reader :id
110
-
111
- # @example
112
- # 2011-08-08 21:03:44 UTC
113
- # @return [Time] When the user account was created (UTC).
114
- attr_reader :created_at
115
-
116
- # @example
117
- # 2013-07-19 23:51:43 UTC
118
- # @return [Time] When the user account was last updated (UTC).
119
- attr_reader :updated_at
120
-
121
- # @example
122
- # "LAGTVMaximusBlack"
123
- # @return [String] User-friendly display name.
124
- attr_reader :display_name
125
-
126
- # @example
127
- # "http://static-cdn.jtvnw.net/jtv_user_pictures/lagtvmaximusblack-profile_image-4b77a2305f5d85c8-300x300.png"
128
- # @return [String] URL for the logo image.
129
- attr_reader :logo_url
130
-
131
- # @example
132
- # "lagtvmaximusblack"
133
- # @return [String] Unique Twitch name.
134
- attr_reader :name
135
- end
136
-
137
- # Query class for finding users.
138
- # @see User
139
- class Users
140
- # @private
141
- def initialize(query)
142
- @query = query
143
- end
144
-
145
- # Get a user by name.
146
- # @example
147
- # Twitch.users.get('totalbiscuit')
148
- # @param user_name [String] The name of the user to get. This is the same as the channel or stream name.
149
- # @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/users.md#get-usersuser GET /users/:user
150
- # @return [User] A valid `User` object if the user exists, `nil` otherwise.
151
- def get(user_name)
152
- name = CGI.escape(user_name)
153
- Twitch::Status.map(404 => nil) do
154
- json = @query.connection.get("users/#{name}")
155
- User.new(json, @query)
156
- end
157
- end
158
- end
159
- end
1
+ require 'cgi'
2
+ require 'time'
3
+
4
+ module Twitch::V2
5
+ # These are members of the Twitch community who have a Twitch account. If broadcasting,
6
+ # they can own a stream that they can broadcast on their channel. If mainly viewing,
7
+ # they might follow or subscribe to channels.
8
+ # @see Users#get Users#get
9
+ # @see Users
10
+ # @see Channel
11
+ # @see Stream
12
+ class User
13
+ include Twitch::IdEquality
14
+
15
+ # @private
16
+ def initialize(hash, query)
17
+ @query = query
18
+ @id = hash['_id']
19
+ @created_at = Time.parse(hash['created_at']).utc
20
+ @display_name = hash['display_name']
21
+ @logo_url = hash['logo']
22
+ @name = hash['name']
23
+ @staff = hash['staff'] || false
24
+ @updated_at = Time.parse(hash['updated_at']).utc
25
+ end
26
+
27
+ # Get the `Channel` associated with this user.
28
+ # @note This incurs an additional web request.
29
+ # @return [Channel] The `Channel` associated with this user, or `nil` if this is a Justin.tv account.
30
+ # @see Channel#get Channel#get
31
+ def channel
32
+ @query.channels.get(@name)
33
+ end
34
+
35
+ # Get the live stream associated with this user.
36
+ # @note This incurs an additional web request.
37
+ # @return [Stream] Live stream object for this user, or `nil` if the user is not currently streaming.
38
+ # @see #streaming?
39
+ def stream
40
+ @query.streams.get(@name)
41
+ end
42
+
43
+ # Is this user currently streaming?
44
+ # @note This makes a separate request to get the user's stream. If you want to actually use the stream object, you should call `#stream` instead.
45
+ # @return [Boolean] `true` if the user currently has a live stream, `false` otherwise.
46
+ # @see #stream
47
+ def streaming?
48
+ !stream.nil?
49
+ end
50
+
51
+ # @return [Boolean] `true` if the user is a member of the Twitch.tv staff, `false` otherwise.
52
+ def staff?
53
+ @staff
54
+ end
55
+
56
+ # Get the channels the user is currently following.
57
+ # @example
58
+ # user.following(:limit => 10)
59
+ # @example
60
+ # user.following do |channel|
61
+ # next if channel.game_name !~ /starcraft/i
62
+ # puts channel.display_name
63
+ # end
64
+ # @param options [Hash] Filter criteria.
65
+ # @option options [Fixnum] :limit (nil) Limit on the number of results returned.
66
+ # @option options [Fixnum] :offset (0) Offset into the result set to begin enumeration.
67
+ # @yield Optional. If a block is given, each followed channel is yielded.
68
+ # @yieldparam [Channel] channel Current channel.
69
+ # @see #following?
70
+ # @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/follows.md#get-usersuserfollowschannels GET /users/:user/follows/channels
71
+ # @return [Array<Channel>] Channels the user is currently following, if no block is given.
72
+ # @return [nil] If a block is given.
73
+ def following(options = {}, &block)
74
+ name = CGI.escape(@name)
75
+ return @query.connection.accumulate(
76
+ :path => "users/#{name}/follows/channels",
77
+ :json => 'follows',
78
+ :sub_json => 'channel',
79
+ :create => -> hash { Channel.new(hash, @query) },
80
+ :limit => options[:limit],
81
+ :offset => options[:offset],
82
+ &block
83
+ )
84
+ end
85
+
86
+ # @param target [String, Channel, User, Stream, #name] The name of the channel to check.
87
+ # @return [Boolean] `true` if the user is following the channel, `false` otherwise.
88
+ # @see #following
89
+ # @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/follows.md#get-usersuserfollowschannelstarget GET /users/:user/follows/channels/:target
90
+ def following?(target)
91
+ name = if target.respond_to?(:name)
92
+ target.name
93
+ else
94
+ target.to_s
95
+ end
96
+
97
+ user_name = CGI.escape(@name)
98
+ channel_name = CGI.escape(name)
99
+
100
+ Twitch::Status.map(404 => false) do
101
+ @query.connection.get("users/#{user_name}/follows/channels/#{channel_name}")
102
+ true
103
+ end
104
+ end
105
+
106
+ # @example
107
+ # 23945610
108
+ # @return [Fixnum] Unique Twitch ID.
109
+ attr_reader :id
110
+
111
+ # @example
112
+ # 2011-08-08 21:03:44 UTC
113
+ # @return [Time] When the user account was created (UTC).
114
+ attr_reader :created_at
115
+
116
+ # @example
117
+ # 2013-07-19 23:51:43 UTC
118
+ # @return [Time] When the user account was last updated (UTC).
119
+ attr_reader :updated_at
120
+
121
+ # @example
122
+ # "LAGTVMaximusBlack"
123
+ # @return [String] User-friendly display name.
124
+ attr_reader :display_name
125
+
126
+ # @example
127
+ # "http://static-cdn.jtvnw.net/jtv_user_pictures/lagtvmaximusblack-profile_image-4b77a2305f5d85c8-300x300.png"
128
+ # @return [String] URL for the logo image.
129
+ attr_reader :logo_url
130
+
131
+ # @example
132
+ # "lagtvmaximusblack"
133
+ # @return [String] Unique Twitch name.
134
+ attr_reader :name
135
+ end
136
+
137
+ # Query class for finding users.
138
+ # @see User
139
+ class Users
140
+ # @private
141
+ def initialize(query)
142
+ @query = query
143
+ end
144
+
145
+ # Get a user by name.
146
+ # @example
147
+ # Twitch.users.get('totalbiscuit')
148
+ # @param user_name [String] The name of the user to get. This is the same as the channel or stream name.
149
+ # @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/users.md#get-usersuser GET /users/:user
150
+ # @return [User] A valid `User` object if the user exists, `nil` otherwise.
151
+ def get(user_name)
152
+ name = CGI.escape(user_name)
153
+ Twitch::Status.map(404 => nil) do
154
+ json = @query.connection.get("users/#{name}")
155
+ User.new(json, @query)
156
+ end
157
+ end
158
+ end
159
+ end