kappa 0.1.5.pre → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/kappa/user.rb CHANGED
@@ -1,27 +1,17 @@
1
- module Kappa
2
- # @private
3
- class UserBase
4
- include IdEquality
5
-
6
- #
7
- # GET /users/:user
8
- # https://github.com/justintv/Twitch-API/blob/master/v2_resources/users.md#get-usersuser
9
- #
10
- def self.get(user_name)
11
- json = connection.get("users/#{user_name}")
12
- if json['status'] == 404
13
- nil
14
- else
15
- new(json)
16
- end
17
- end
18
- end
19
- end
1
+ require 'cgi'
20
2
 
21
3
  module Kappa::V2
22
- class User < Kappa::UserBase
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
23
11
  include Connection
12
+ include Kappa::IdEquality
24
13
 
14
+ # @private
25
15
  def initialize(hash)
26
16
  @id = hash['_id']
27
17
  @created_at = DateTime.parse(hash['created_at'])
@@ -32,10 +22,29 @@ module Kappa::V2
32
22
  @updated_at = DateTime.parse(hash['updated_at'])
33
23
  end
34
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
35
43
  def channel
36
- # TODO
44
+ Channel.get(@name)
37
45
  end
38
46
 
47
+ # @return [Boolean] `true` if the user is a member of the Twitch.tv staff, `false` otherwise.
39
48
  def staff?
40
49
  @staff
41
50
  end
@@ -44,22 +53,22 @@ module Kappa::V2
44
53
  # GET /channels/:channel/subscriptions/:user
45
54
  # https://github.com/justintv/Twitch-API/blob/master/v2_resources/subscriptions.md#get-channelschannelsubscriptionsuser
46
55
  #
47
- # TODO: Requires authentication.
56
+
57
+ # TODO: Requires authentication. Private until implemented.
58
+ # @private
48
59
  def subscribed_to?(channel_name)
49
60
  end
50
61
 
51
- #
52
- # GET /streams/followed
53
- # TODO: Authenticate.
54
- # TODO: Only valid for authenticated user, might not belong here.
55
- #
56
- # GET /users/:user/follows/channels
57
- # https://github.com/justintv/Twitch-API/blob/master/v2_resources/follows.md#get-usersuserfollowschannels
58
- #
59
- def following(params = {})
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?
60
69
  params = {}
61
70
 
62
- limit = args[:limit]
71
+ limit = options[:limit]
63
72
  if limit && (limit < 100)
64
73
  params[:limit] = limit
65
74
  else
@@ -77,22 +86,44 @@ module Kappa::V2
77
86
  )
78
87
  end
79
88
 
80
- #
81
- # GET /users/:user/follows/:channels/:target
82
- # https://github.com/justintv/Twitch-API/blob/master/v2_resources/follows.md#get-usersuserfollowschannelstarget
83
- #
84
- def following?(channel_name)
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
+
85
105
  json = connection.get("users/#{@name}/follows/channels/#{channel_name}")
86
106
  status = json['status']
87
107
  return !status || (status != 404)
88
108
  end
89
109
 
110
+ # @return [Fixnum] Unique Twitch ID.
90
111
  attr_reader :id
112
+
113
+ # @return [DateTime] When the user account was created.
91
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.
92
120
  attr_reader :display_name
121
+
122
+ # @return [String] URL for the logo image.
93
123
  attr_reader :logo_url
124
+
125
+ # @return [String] Unique Twitch name.
94
126
  attr_reader :name
95
- attr_reader :updated_at
96
127
 
97
128
  # TODO: Authenticated user attributes.
98
129
  # attr_reader :email
data/lib/kappa/version.rb CHANGED
@@ -1 +1 @@
1
- $version = '0.1.5.pre'
1
+ $version = '0.2.0'
data/lib/kappa/video.rb CHANGED
@@ -1,21 +1,19 @@
1
- module Kappa
2
- # @private
3
- class VideoBase
4
- include IdEquality
5
-
6
- def self.get(id)
7
- json = connection.get("videos/#{id}")
8
- new(json)
9
- end
10
- end
11
- end
1
+ require 'cgi'
12
2
 
13
3
  module Kappa::V2
14
- class Video < Kappa::VideoBase
4
+ # Videos are broadcasts or highlights owned by a channel. Broadcasts are unedited
5
+ # videos that are saved after a streaming session. Highlights are videos edited from
6
+ # broadcasts by the channel's owner.
7
+ # @see .get Video.get
8
+ # @see Videos
9
+ # @see Channel
10
+ class Video
15
11
  include Connection
12
+ include Kappa::IdEquality
16
13
 
14
+ # @private
17
15
  def initialize(hash)
18
- @id = hash['id']
16
+ @id = hash['_id']
19
17
  @title = hash['title']
20
18
  @recorded_at = DateTime.parse(hash['recorded_at'])
21
19
  @url = hash['url']
@@ -28,26 +26,75 @@ module Kappa::V2
28
26
  # @channel_display_name = json['channel']['display_name']
29
27
  end
30
28
 
29
+ # Get a video by ID.
30
+ # @example
31
+ # v = Video.get('a396294648')
32
+ # v.title # => "DreamHack Open Stockholm 26-27 April"
33
+ # @param id [String] The ID of the video to get.
34
+ # @raise [ArgumentError] If `id` is `nil` or blank.
35
+ # @return [Video] A valid `Video` object if the video exists, `nil` otherwise.
36
+ def self.get(id)
37
+ raise ArgumentError if !id || id.strip.empty?
38
+
39
+ encoded_id = CGI.escape(id)
40
+ json = connection.get("videos/#{encoded_id}")
41
+ if !json || json['status'] == 404
42
+ nil
43
+ else
44
+ new(json)
45
+ end
46
+ end
47
+
48
+ # @note This incurs an additional web request.
49
+ # @return [Channel] The channel on which this video was originally streamed.
31
50
  def channel
32
51
  Channel.new(connection.get("channels/#{@channel_name}"))
33
52
  end
34
53
 
54
+ # @note This is a `String`, not a `Fixnum` like most other object IDs.
55
+ # @example
56
+ # v = Video.get('a396294648')
57
+ # v.id # => "a396294648"
58
+ # @return [String] Unique Twitch ID for this video.
35
59
  attr_reader :id
60
+
61
+ # @return [String] Title of this video. This is seen on the video's page.
36
62
  attr_reader :title
63
+
64
+ # @return [DateTime] When this video was recorded.
37
65
  attr_reader :recorded_at
66
+
67
+ # @return [String] URL of this video on Twitch.
38
68
  attr_reader :url
69
+
70
+ # @return [Fixnum] The number of views this video has received all-time.
39
71
  attr_reader :view_count
72
+
73
+ # @return [String] Description of this video.
40
74
  attr_reader :description
41
- # TODO: Is this actually in seconds? Doesn't seem to match up with video length.
42
- attr_reader :length_sec
75
+
76
+ # @return [Fixnum] The length of this video in seconds.
77
+ attr_reader :length_sec # TODO: Is this actually in seconds? Doesn't seem to match up with video length.
78
+
79
+ # @return [String] The name of the game played in this video.
43
80
  attr_reader :game_name
81
+
82
+ # @return [String] URL of a preview screenshot taken from the video stream.
44
83
  attr_reader :preview_url
45
- # TODO: Move this under "v.channel.name" and force the query if other attributes are requested.
46
- attr_reader :channel_name
84
+
85
+ # @return [String] The name of the channel on which this video was originally streamed.
86
+ attr_reader :channel_name # TODO: Move this under "v.channel.name" and force the query if other attributes are requested.
87
+
88
+ # TODO: embed (HTML embed code)
47
89
  end
48
90
 
91
+ # Query class used for finding top videos.
92
+ # @see Video
49
93
  class Videos
94
+ # @private
95
+ # Private until implemented.
50
96
  def self.top(params = {})
97
+ # TODO
51
98
  end
52
99
  end
53
100
  end
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kappa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5.pre
5
- prerelease: 6
4
+ version: 0.2.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Chris Schmich
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-12 00:00:00.000000000 Z
12
+ date: 2013-06-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &26379276 !ruby/object:Gem::Requirement
16
+ requirement: &24580620 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.9.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *26379276
24
+ version_requirements: *24580620
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: addressable
27
- requirement: &26378880 !ruby/object:Gem::Requirement
27
+ requirement: &24580296 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.3.3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *26378880
35
+ version_requirements: *24580296
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &26378304 !ruby/object:Gem::Requirement
38
+ requirement: &24579948 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0.9'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *26378304
46
+ version_requirements: *24579948
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: webmock
49
- requirement: &26394384 !ruby/object:Gem::Requirement
49
+ requirement: &24579624 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.11.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *26394384
57
+ version_requirements: *24579624
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &26394048 !ruby/object:Gem::Requirement
60
+ requirement: &24579288 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,43 @@ dependencies:
65
65
  version: 2.13.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *26394048
68
+ version_requirements: *24579288
69
+ - !ruby/object:Gem::Dependency
70
+ name: launchy
71
+ requirement: &24578952 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: 2.3.0
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *24578952
80
+ - !ruby/object:Gem::Dependency
81
+ name: yard
82
+ requirement: &24578604 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: 0.8.6
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *24578604
91
+ - !ruby/object:Gem::Dependency
92
+ name: simplecov
93
+ requirement: &24578280 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: 0.7.1
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *24578280
69
102
  - !ruby/object:Gem::Dependency
70
103
  name: coveralls
71
- requirement: &26393772 !ruby/object:Gem::Requirement
104
+ requirement: &24578004 !ruby/object:Gem::Requirement
72
105
  none: false
73
106
  requirements:
74
107
  - - ! '>='
@@ -76,7 +109,7 @@ dependencies:
76
109
  version: '0'
77
110
  type: :development
78
111
  prerelease: false
79
- version_requirements: *26393772
112
+ version_requirements: *24578004
80
113
  description: ! " A Ruby library for interfacing with the Twitch.tv API\n including
81
114
  users, channels, streams, and followers.\n"
82
115
  email: schmch@gmail.com
@@ -112,9 +145,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
145
  required_rubygems_version: !ruby/object:Gem::Requirement
113
146
  none: false
114
147
  requirements:
115
- - - ! '>'
148
+ - - ! '>='
116
149
  - !ruby/object:Gem::Version
117
- version: 1.3.1
150
+ version: '0'
118
151
  requirements: []
119
152
  rubyforge_project:
120
153
  rubygems_version: 1.8.15
@@ -122,3 +155,4 @@ signing_key:
122
155
  specification_version: 3
123
156
  summary: Ruby library for interfacing with the Twitch.tv API.
124
157
  test_files: []
158
+ has_rdoc: