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.
- 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/lib/kappa/team.rb
CHANGED
@@ -1,99 +1,99 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
#
|
5
|
-
# @see
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
# @return [
|
40
|
-
attr_reader :
|
41
|
-
|
42
|
-
# @return [String]
|
43
|
-
attr_reader :
|
44
|
-
|
45
|
-
# @return [String] URL for
|
46
|
-
attr_reader :
|
47
|
-
|
48
|
-
# @return [String] URL for
|
49
|
-
attr_reader :
|
50
|
-
|
51
|
-
# @return [String]
|
52
|
-
attr_reader :
|
53
|
-
|
54
|
-
# @return [String]
|
55
|
-
attr_reader :
|
56
|
-
|
57
|
-
# @return [
|
58
|
-
attr_reader :
|
59
|
-
|
60
|
-
# @return [
|
61
|
-
attr_reader :
|
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
|
-
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
|
data/lib/kappa/twitch.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
module Kappa::V2
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
data/lib/kappa/user.rb
CHANGED
@@ -1,132 +1,124 @@
|
|
1
|
-
require 'cgi'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
# they
|
7
|
-
#
|
8
|
-
# @see
|
9
|
-
# @see
|
10
|
-
|
11
|
-
|
12
|
-
include
|
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
|
-
# @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
|