kappa 0.1.1.pre → 0.1.2.pre

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/lib/kappa/team.rb ADDED
@@ -0,0 +1,83 @@
1
+ module Kappa
2
+ class TeamBase
3
+ include IdEquality
4
+
5
+ def initialize(arg, connection)
6
+ @connection = connection
7
+
8
+ case arg
9
+ when Hash
10
+ parse(arg)
11
+ when String
12
+ json = @connection.get("teams/#{arg}")
13
+ else
14
+ raise ArgumentError
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ module Kappa::V2
21
+ class Team < Kappa::TeamBase
22
+ #
23
+ # GET /teams/:team
24
+ # https://github.com/justintv/Twitch-API/blob/master/v2_resources/teams.md#get-teamsteam
25
+ #
26
+ def intialize(arg, connection = Connection.instance)
27
+ super(arg, connection)
28
+ end
29
+
30
+ attr_reader :id
31
+ attr_reader :info
32
+ attr_reader :background_url
33
+ attr_reader :banner_url
34
+ attr_reader :logo_url
35
+ attr_reader :name
36
+ attr_reader :display_name
37
+ attr_reader :updated_at
38
+ attr_reader :created_at
39
+
40
+ private
41
+ def parse(hash)
42
+ @id = hash['_id']
43
+ @info = hash['info']
44
+ @background_url = hash['background']
45
+ @banner_url = hash['banner']
46
+ @logo_url = hash['logo']
47
+ @name = hash['name']
48
+ @display_name = hash['display_name']
49
+ @updated_at = DateTime.parse(hash['updated_at'])
50
+ @created_at = DateTime.parse(hash['created_at'])
51
+ end
52
+ end
53
+
54
+ class Teams
55
+ #
56
+ # GET /teams
57
+ # https://github.com/justintv/Twitch-API/blob/master/v2_resources/teams.md#get-teams
58
+ #
59
+ def all(params = {})
60
+ limit = params[:limit] || 0
61
+
62
+ teams = []
63
+ ids = Set.new
64
+
65
+ @conn.paginated('teams', params) do |json|
66
+ teams_json = json['teams']
67
+ teams_json.each do |team_json|
68
+ team = Team.new(team_json, @conn)
69
+ if ids.add?(team.id)
70
+ teams << team
71
+ if teams.count == limit
72
+ return teams
73
+ end
74
+ end
75
+ end
76
+
77
+ !teams_json.empty?
78
+ end
79
+
80
+ teams
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,11 @@
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
data/lib/kappa/user.rb ADDED
@@ -0,0 +1,113 @@
1
+ module Kappa
2
+ class UserBase
3
+ include IdEquality
4
+
5
+ def initialize(hash, connection = self.class.default_connection)
6
+ @connection = connection
7
+ parse(hash)
8
+ end
9
+
10
+ #
11
+ # GET /users/:user
12
+ # https://github.com/justintv/Twitch-API/blob/master/v2_resources/users.md#get-usersuser
13
+ #
14
+ def self.get(user_name, connection = default_connection)
15
+ json = connection.get("users/#{user_name}")
16
+ if json['status'] == 404
17
+ nil
18
+ else
19
+ new(json, connection)
20
+ end
21
+ end
22
+
23
+ private
24
+ def self.default_connection
25
+ self.class.module_class(:Connection).instance
26
+ end
27
+ end
28
+ end
29
+
30
+ module Kappa::V2
31
+ class User < Kappa::UserBase
32
+ def channel
33
+ # TODO
34
+ end
35
+
36
+ def staff?
37
+ @staff
38
+ end
39
+
40
+ #
41
+ # GET /channels/:channel/subscriptions/:user
42
+ # https://github.com/justintv/Twitch-API/blob/master/v2_resources/subscriptions.md#get-channelschannelsubscriptionsuser
43
+ #
44
+ # TODO: Requires authentication.
45
+ def subscribed_to?(channel_name)
46
+ end
47
+
48
+ #
49
+ # GET /streams/followed
50
+ # TODO: Authenticate.
51
+ # TODO: Only valid for authenticated user, might not belong here.
52
+ #
53
+ # GET /users/:user/follows/channels
54
+ # https://github.com/justintv/Twitch-API/blob/master/v2_resources/follows.md#get-usersuserfollowschannels
55
+ #
56
+ def following(params = {})
57
+ limit = params[:limit] || 0
58
+
59
+ channels = []
60
+ ids = Set.new
61
+
62
+ @connection.paginated("users/#{@name}/follows/channels", params) do |json|
63
+ current_channels = json['follows']
64
+ current_channels.each do |follow_json|
65
+ channel_json = follow_json['channel']
66
+ channel = Channel.new(channel_json, @connection)
67
+ if ids.add?(channel.id)
68
+ channels << channel
69
+ if channels.count == limit
70
+ return channels
71
+ end
72
+ end
73
+ end
74
+
75
+ !current_channels.empty?
76
+ end
77
+
78
+ channels
79
+ end
80
+
81
+ #
82
+ # GET /users/:user/follows/:channels/:target
83
+ # https://github.com/justintv/Twitch-API/blob/master/v2_resources/follows.md#get-usersuserfollowschannelstarget
84
+ #
85
+ def following?(channel_name)
86
+ json = @connection.get("users/#{@name}/follows/channels/#{channel_name}")
87
+ status = json['status']
88
+ return !status || (status != 404)
89
+ end
90
+
91
+ attr_reader :id
92
+ attr_reader :created_at
93
+ attr_reader :display_name
94
+ attr_reader :logo_url
95
+ attr_reader :name
96
+ attr_reader :updated_at
97
+
98
+ # TODO: Authenticated user attributes.
99
+ # attr_reader :email
100
+ # def partnered?
101
+
102
+ private
103
+ def parse(hash)
104
+ @id = hash['_id']
105
+ @created_at = DateTime.parse(hash['created_at'])
106
+ @display_name = hash['display_name']
107
+ @logo_url = hash['logo']
108
+ @name = hash['name']
109
+ @staff = hash['staff'] || false
110
+ @updated_at = DateTime.parse(hash['updated_at'])
111
+ end
112
+ end
113
+ end
data/lib/kappa/version.rb CHANGED
@@ -1 +1 @@
1
- $version = '0.1.1.pre'
1
+ $version = '0.1.2.pre'
@@ -0,0 +1,66 @@
1
+ module Kappa
2
+ class VideoBase
3
+ include IdEquality
4
+
5
+ def initialize(arg, connection)
6
+ @connection = connection
7
+
8
+ case arg
9
+ when Hash
10
+ parse(arg)
11
+ when String
12
+ json = @connection.get("videos/#{arg}")
13
+ parse(json)
14
+ else
15
+ raise ArgumentError
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ module Kappa::V2
22
+ class Video < Kappa::VideoBase
23
+ def initialize(arg)
24
+ super(arg, Connection.instance)
25
+ end
26
+
27
+ def channel
28
+ Channel.new(@conn.get("channels/#{@channel_name}"), @conn)
29
+ end
30
+
31
+ attr_reader :id
32
+ attr_reader :title
33
+ attr_reader :recorded_at
34
+ attr_reader :url
35
+ attr_reader :view_count
36
+ attr_reader :description
37
+ # TODO: Is this actually in seconds? Doesn't seem to match up with video length.
38
+ attr_reader :length_sec
39
+ attr_reader :game_name
40
+ attr_reader :preview_url
41
+ # TODO: Move this under "v.channel.name" and force the query if other attributes are requested.
42
+ attr_reader :channel_name
43
+
44
+ private
45
+ def parse(hash)
46
+ @conn = conn
47
+
48
+ @id = hash['id']
49
+ @title = hash['title']
50
+ @recorded_at = DateTime.parse(hash['recorded_at'])
51
+ @url = hash['url']
52
+ @view_count = hash['views']
53
+ @description = hash['description']
54
+ @length_sec = hash['length']
55
+ @game_name = hash['game']
56
+ @preview_url = hash['preview']
57
+ @channel_name = hash['channel']['name']
58
+ # @channel_display_name = json['channel']['display_name']
59
+ end
60
+ end
61
+
62
+ class Videos
63
+ def self.top(params = {})
64
+ end
65
+ end
66
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kappa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.pre
4
+ version: 0.1.2.pre
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-28 00:00:00.000000000 Z
12
+ date: 2013-05-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -59,6 +59,38 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0.9'
62
+ - !ruby/object:Gem::Dependency
63
+ name: webmock
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 1.11.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.11.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 2.13.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 2.13.0
62
94
  description: ! " A Ruby library for interfacing with the Twitch.tv Kraken API\n
63
95
  \ including users, channels, streams, and followers.\n"
64
96
  email: schmch@gmail.com
@@ -66,7 +98,18 @@ executables: []
66
98
  extensions: []
67
99
  extra_rdoc_files: []
68
100
  files:
101
+ - lib/kappa/base.rb
102
+ - lib/kappa/channel.rb
103
+ - lib/kappa/connection.rb
104
+ - lib/kappa/game.rb
105
+ - lib/kappa/id_equality.rb
106
+ - lib/kappa/images.rb
107
+ - lib/kappa/stream.rb
108
+ - lib/kappa/team.rb
109
+ - lib/kappa/twitch.rb
110
+ - lib/kappa/user.rb
69
111
  - lib/kappa/version.rb
112
+ - lib/kappa/video.rb
70
113
  - lib/kappa.rb
71
114
  - README.md
72
115
  homepage: https://github.com/schmich/kappa