kappa 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,99 +1,99 @@
1
- module Kappa::V2
2
- # Teams are an organization of channels.
3
- # @see .get Team.get
4
- # @see Teams
5
- # @see Channel
6
- class Team
7
- include Connection
8
- include Kappa::IdEquality
9
-
10
- # @private
11
- def initialize(hash)
12
- @id = hash['_id']
13
- @info = hash['info']
14
- @background_url = hash['background']
15
- @banner_url = hash['banner']
16
- @logo_url = hash['logo']
17
- @name = hash['name']
18
- @display_name = hash['display_name']
19
- @updated_at = DateTime.parse(hash['updated_at'])
20
- @created_at = DateTime.parse(hash['created_at'])
21
- end
22
-
23
- # Get a team by name.
24
- # @param team_name [String] The name of the team to get.
25
- # @return [Team] A valid `Team` object if the team exists, `nil` otherwise.
26
- # @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/teams.md#get-teamsteam GET /teams/:team
27
- def self.get(team_name)
28
- json = connection.get("teams/#{team_name}")
29
- if json['status'] == 404
30
- nil
31
- else
32
- new(json)
33
- end
34
- end
35
-
36
- # @return [Fixnum] Unique Twitch ID.
37
- attr_reader :id
38
-
39
- # @return [String] Info about the team. This is displayed on the team's page and can contain HTML.
40
- attr_reader :info
41
-
42
- # @return [String] URL for background image.
43
- attr_reader :background_url
44
-
45
- # @return [String] URL for banner image.
46
- attr_reader :banner_url
47
-
48
- # @return [String] URL for the logo image.
49
- attr_reader :logo_url
50
-
51
- # @return [String] Unique Twitch name.
52
- attr_reader :name
53
-
54
- # @return [String] User-friendly display name. This name is used for the team's page title.
55
- attr_reader :display_name
56
-
57
- # @return [DateTime] When the team was last updated.
58
- attr_reader :updated_at
59
-
60
- # @return [DateTime] When the team was created.
61
- attr_reader :created_at
62
- end
63
-
64
- # Query class used for finding all active teams.
65
- # @see Team
66
- class Teams
67
- include Connection
68
-
69
- # Get the list of all active teams.
70
- # @example
71
- # Teams.all
72
- # @example
73
- # Teams.all(:limit => 10)
74
- # @param options [Hash] Filter criteria.
75
- # @option options [Fixnum] :limit (none) Limit on the number of results returned.
76
- # @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/teams.md#get-teams GET /teams
77
- # @return [Array<Team>] List of all active teams.
78
- def self.all(options = {})
79
- # TODO: Is offset supported?
80
- params = {}
81
-
82
- limit = options[:limit]
83
- if limit && (limit < 100)
84
- params[:limit] = limit
85
- else
86
- params[:limit] = 100
87
- limit = 0
88
- end
89
-
90
- return connection.accumulate(
91
- :path => 'teams',
92
- :params => params,
93
- :json => 'teams',
94
- :class => Team,
95
- :limit => limit
96
- )
97
- end
98
- end
99
- end
1
+ require 'time'
2
+
3
+ module Kappa::V2
4
+ # Teams are an organization of channels.
5
+ # @see .get Team.get
6
+ # @see Teams
7
+ # @see Channel
8
+ class Team
9
+ include Connection
10
+ include Kappa::IdEquality
11
+
12
+ # @private
13
+ def initialize(hash)
14
+ @id = hash['_id']
15
+ @info = hash['info']
16
+ @background_url = hash['background']
17
+ @banner_url = hash['banner']
18
+ @logo_url = hash['logo']
19
+ @name = hash['name']
20
+ @display_name = hash['display_name']
21
+ @updated_at = Time.parse(hash['updated_at']).utc
22
+ @created_at = Time.parse(hash['created_at']).utc
23
+ @url = "http://www.twitch.tv/team/#{@name}"
24
+ end
25
+
26
+ # Get a team by name.
27
+ # @param team_name [String] The name of the team to get.
28
+ # @return [Team] A valid `Team` object if the team exists, `nil` otherwise.
29
+ # @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/teams.md#get-teamsteam GET /teams/:team
30
+ def self.get(team_name)
31
+ json = connection.get("teams/#{team_name}")
32
+ if json['status'] == 404
33
+ nil
34
+ else
35
+ new(json)
36
+ end
37
+ end
38
+
39
+ # @return [Fixnum] Unique Twitch ID.
40
+ attr_reader :id
41
+
42
+ # @return [String] Info about the team. This is displayed on the team's page and can contain HTML.
43
+ attr_reader :info
44
+
45
+ # @return [String] URL for background image.
46
+ attr_reader :background_url
47
+
48
+ # @return [String] URL for banner image.
49
+ attr_reader :banner_url
50
+
51
+ # @return [String] URL for the logo image.
52
+ attr_reader :logo_url
53
+
54
+ # @return [String] Unique Twitch name.
55
+ attr_reader :name
56
+
57
+ # @return [String] User-friendly display name. This name is used for the team's page title.
58
+ attr_reader :display_name
59
+
60
+ # @return [Time] When the team was last updated (UTC).
61
+ attr_reader :updated_at
62
+
63
+ # @return [Time] When the team was created (UTC).
64
+ attr_reader :created_at
65
+
66
+ # @example
67
+ # "http://www.twitch.tv/team/root"
68
+ # @return [String] URL for the team's Twitch landing page.
69
+ attr_reader :url
70
+ end
71
+
72
+ # Query class used for finding all active teams.
73
+ # @see Team
74
+ class Teams
75
+ include Connection
76
+
77
+ # Get the list of all active teams.
78
+ # @example
79
+ # Teams.all
80
+ # @example
81
+ # Teams.all(:limit => 10)
82
+ # @param options [Hash] Filter criteria.
83
+ # @option options [Fixnum] :limit (none) Limit on the number of results returned.
84
+ # @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/teams.md#get-teams GET /teams
85
+ # @return [Array<Team>] List of all active teams.
86
+ def self.all(options = {})
87
+ params = {}
88
+
89
+ return connection.accumulate(
90
+ :path => 'teams',
91
+ :params => params,
92
+ :json => 'teams',
93
+ :class => Team,
94
+ :limit => options[:limit],
95
+ :offset => options[:offset]
96
+ )
97
+ end
98
+ end
99
+ end
@@ -1,11 +1,13 @@
1
- module Kappa::V2
2
- class Twitch
3
- def self.viewer_count
4
- # TODO
5
- end
6
-
7
- def self.stream_count
8
- # TODO
9
- end
10
- end
11
- end
1
+ module Kappa::V2
2
+ # Private until implemented.
3
+ # @private
4
+ class Twitch
5
+ def self.viewer_count
6
+ # TODO
7
+ end
8
+
9
+ def self.stream_count
10
+ # TODO
11
+ end
12
+ end
13
+ end
@@ -1,132 +1,124 @@
1
- require 'cgi'
2
-
3
- module Kappa::V2
4
- # These are members of the Twitch community who have a Twitch account. If broadcasting,
5
- # they can own a stream that they can broadcast on their channel. If mainly viewing,
6
- # they might follow or subscribe to channels.
7
- # @see .get User.get
8
- # @see Channel
9
- # @see Stream
10
- class User
11
- include Connection
12
- include Kappa::IdEquality
13
-
14
- # @private
15
- def initialize(hash)
16
- @id = hash['_id']
17
- @created_at = DateTime.parse(hash['created_at'])
18
- @display_name = hash['display_name']
19
- @logo_url = hash['logo']
20
- @name = hash['name']
21
- @staff = hash['staff'] || false
22
- @updated_at = DateTime.parse(hash['updated_at'])
23
- end
24
-
25
- # Get a user by name.
26
- # @param user_name [String] The name of the user to get. This is the same as the channel or stream name.
27
- # @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/users.md#get-usersuser GET /users/:user
28
- # @return [User] A valid `User` object if the user exists, `nil` otherwise.
29
- def self.get(user_name)
30
- encoded_name = CGI.escape(user_name)
31
- json = connection.get("users/#{encoded_name}")
32
- if !json || json['status'] == 404
33
- nil
34
- else
35
- new(json)
36
- end
37
- end
38
-
39
- # Get the `Channel` associated with this user.
40
- # @note This incurs an additional web request.
41
- # @return [Channel] The `Channel` associated with this user, or `nil` if this is a Justin.tv account.
42
- # @see Channel.get
43
- def channel
44
- Channel.get(@name)
45
- end
46
-
47
- # @return [Boolean] `true` if the user is a member of the Twitch.tv staff, `false` otherwise.
48
- def staff?
49
- @staff
50
- end
51
-
52
- #
53
- # GET /channels/:channel/subscriptions/:user
54
- # https://github.com/justintv/Twitch-API/blob/master/v2_resources/subscriptions.md#get-channelschannelsubscriptionsuser
55
- #
56
-
57
- # TODO: Requires authentication. Private until implemented.
58
- # @private
59
- def subscribed_to?(channel_name)
60
- end
61
-
62
- # @param options [Hash] Filter criteria.
63
- # @option options [Fixnum] :limit (none) Limit on the number of results returned.
64
- # @see #following?
65
- # @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/follows.md#get-usersuserfollowschannels GET /users/:user/follows/channels
66
- # @return [Array<Channel>] List of channels the user is currently following.
67
- def following(options = {})
68
- # TODO: If offset supported?
69
- params = {}
70
-
71
- limit = options[:limit]
72
- if limit && (limit < 100)
73
- params[:limit] = limit
74
- else
75
- params[:limit] = 100
76
- limit = 0
77
- end
78
-
79
- return connection.accumulate(
80
- :path => "users/#{@name}/follows/channels",
81
- :params => params,
82
- :json => 'follows',
83
- :sub_json => 'channel',
84
- :class => Channel,
85
- :limit => limit
86
- )
87
- end
88
-
89
- # @param channel [String, Channel] The name of the channel (or `Channel` object) to check.
90
- # @return [Boolean] `true` if the user is following the channel, `false` otherwise.
91
- # @see #following
92
- # @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/follows.md#get-usersuserfollowschannelstarget GET /users/:user/follows/:channels/:target
93
- def following?(channel)
94
- # TODO: Support User for channel parameter? Stream?
95
-
96
- channel_name = case channel
97
- when String
98
- channel
99
- when Channel
100
- channel.name
101
- end
102
-
103
- channel_name = CGI.escape(channel_name)
104
-
105
- json = connection.get("users/#{@name}/follows/channels/#{channel_name}")
106
- status = json['status']
107
- return !status || (status != 404)
108
- end
109
-
110
- # @return [Fixnum] Unique Twitch ID.
111
- attr_reader :id
112
-
113
- # @return [DateTime] When the user account was created.
114
- attr_reader :created_at
115
-
116
- # @return [DateTime] When the user account was last updated.
117
- attr_reader :updated_at
118
-
119
- # @return [String] User-friendly display name.
120
- attr_reader :display_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
- # TODO: Authenticated user attributes.
129
- # attr_reader :email
130
- # def partnered?
131
- end
132
- end
1
+ require 'cgi'
2
+ require 'time'
3
+
4
+ module Kappa::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 .get User.get
9
+ # @see Channel
10
+ # @see Stream
11
+ class User
12
+ include Connection
13
+ include Kappa::IdEquality
14
+
15
+ # @private
16
+ def initialize(hash)
17
+ @id = hash['_id']
18
+ @created_at = Time.parse(hash['created_at']).utc
19
+ @display_name = hash['display_name']
20
+ @logo_url = hash['logo']
21
+ @name = hash['name']
22
+ @staff = hash['staff'] || false
23
+ @updated_at = Time.parse(hash['updated_at']).utc
24
+ end
25
+
26
+ # Get a user by name.
27
+ # @param user_name [String] The name of the user to get. This is the same as the channel or stream name.
28
+ # @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/users.md#get-usersuser GET /users/:user
29
+ # @return [User] A valid `User` object if the user exists, `nil` otherwise.
30
+ def self.get(user_name)
31
+ encoded_name = CGI.escape(user_name)
32
+ json = connection.get("users/#{encoded_name}")
33
+ if !json || json['status'] == 404
34
+ nil
35
+ else
36
+ new(json)
37
+ end
38
+ end
39
+
40
+ # Get the `Channel` associated with this user.
41
+ # @note This incurs an additional web request.
42
+ # @return [Channel] The `Channel` associated with this user, or `nil` if this is a Justin.tv account.
43
+ # @see Channel.get
44
+ def channel
45
+ Channel.get(@name)
46
+ end
47
+
48
+ # Get the live stream associated with this user.
49
+ # @note This incurs an additional web request.
50
+ # @return [Stream] Live stream object for this user, or `nil` if the user is not currently streaming.
51
+ # @see #streaming?
52
+ def stream
53
+ Stream.get(@name)
54
+ end
55
+
56
+ # Is this user currently streaming?
57
+ # @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.
58
+ # @return [Boolean] `true` if the user currently has a live stream, `false` otherwise.
59
+ # @see #stream
60
+ def streaming?
61
+ !stream.nil?
62
+ end
63
+
64
+ # @return [Boolean] `true` if the user is a member of the Twitch.tv staff, `false` otherwise.
65
+ def staff?
66
+ @staff
67
+ end
68
+
69
+ # Get the channels the user is currently following.
70
+ # @param options [Hash] Filter criteria.
71
+ # @option options [Fixnum] :limit (none) Limit on the number of results returned.
72
+ # @option options [Fixnum] :offset (0) Offset into the result set to begin enumeration.
73
+ # @see #following?
74
+ # @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/follows.md#get-usersuserfollowschannels GET /users/:user/follows/channels
75
+ # @return [Array<Channel>] List of channels the user is currently following.
76
+ def following(options = {})
77
+ return connection.accumulate(
78
+ :path => "users/#{@name}/follows/channels",
79
+ :json => 'follows',
80
+ :sub_json => 'channel',
81
+ :class => Channel,
82
+ :limit => options[:limit],
83
+ :offset => options[:offset]
84
+ )
85
+ end
86
+
87
+ # @param channel [String, Channel] The name of the channel (or `Channel` object) to check.
88
+ # @return [Boolean] `true` if the user is following the channel, `false` otherwise.
89
+ # @see #following
90
+ # @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/follows.md#get-usersuserfollowschannelstarget GET /users/:user/follows/:channels/:target
91
+ def following?(channel)
92
+ channel_name = case channel
93
+ when String
94
+ channel
95
+ when Channel
96
+ channel.name
97
+ end
98
+
99
+ channel_name = CGI.escape(channel_name)
100
+
101
+ json = connection.get("users/#{@name}/follows/channels/#{channel_name}")
102
+ status = json['status']
103
+ return !status || (status != 404)
104
+ end
105
+
106
+ # @return [Fixnum] Unique Twitch ID.
107
+ attr_reader :id
108
+
109
+ # @return [Time] When the user account was created (UTC).
110
+ attr_reader :created_at
111
+
112
+ # @return [Time] When the user account was last updated (UTC).
113
+ attr_reader :updated_at
114
+
115
+ # @return [String] User-friendly display name.
116
+ attr_reader :display_name
117
+
118
+ # @return [String] URL for the logo image.
119
+ attr_reader :logo_url
120
+
121
+ # @return [String] Unique Twitch name.
122
+ attr_reader :name
123
+ end
124
+ end