jtv 1.0.0.beta1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +3 -0
  3. data/README.md +65 -0
  4. data/jtv.gemspec +1 -1
  5. data/lib/jtv/channel.rb +23 -0
  6. data/lib/jtv/client.rb +2 -0
  7. data/lib/jtv/version.rb +1 -1
  8. data/spec/features/channel_spec.rb +48 -0
  9. data/spec/features/stream_spec.rb +4 -10
  10. data/spec/features/user_spec.rb +2 -6
  11. data/spec/jtv/channel_spec.rb +44 -0
  12. data/spec/jtv/client_spec.rb +10 -0
  13. data/spec/vcr_cassettes/Jtv_Channel/_archives/returns_an_array_of_archives_for_given_channel.yml +70 -0
  14. data/spec/vcr_cassettes/Jtv_Channel/_channel_show/provides_information_for_a_given_channel.yml +69 -0
  15. data/spec/vcr_cassettes/Jtv_Channel/_chat_embed/returns_an_iframe_for_chat.yml +63 -0
  16. data/spec/vcr_cassettes/Jtv_Channel/_embed/returns_a_string_containing_an_embed_object.yml +63 -0
  17. data/spec/vcr_cassettes/Jtv_Channel/_fans/fetches_fans_for_a_given_channel.yml +209 -0
  18. data/spec/vcr_cassettes/Jtv_Stream/_list/returns_a_list_of_streams_for_a_category.yml +591 -0
  19. data/spec/vcr_cassettes/Jtv_Stream/_search/returns_streams_based_on_search_query.yml +161 -0
  20. data/spec/vcr_cassettes/Jtv_Stream/_summary/returns_a_summary_of_Jutstin_tv_data.yml +59 -0
  21. data/spec/vcr_cassettes/Jtv_User/_favorites/fetches_favorites_from_user.yml +88 -0
  22. data/spec/vcr_cassettes/Jtv_User/_user_show/fetches_information_on_user.yml +67 -0
  23. data/spec/vcr_config.rb +4 -3
  24. metadata +48 -52
  25. data/spec/vcr_cassettes/Jtv_Stream/_list.yml +0 -408
  26. data/spec/vcr_cassettes/Jtv_Stream/_search.yml +0 -156
  27. data/spec/vcr_cassettes/Jtv_Stream/_summary.yml +0 -81
  28. data/spec/vcr_cassettes/Jtv_User/_favorites.yml +0 -110
  29. data/spec/vcr_cassettes/Jtv_User/_user_show.yml +0 -92
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 55e6cb2e9244cffac200d57c616e2596b13bf484
4
+ data.tar.gz: 5b0cc8b1ba65ce9eba06d372bee8ced5d23a9bcc
5
+ SHA512:
6
+ metadata.gz: 0142328529cddcedb4079abfeb955313065da1e2a036aa9431c130da12dba14cf4386632c7e0b13064cd411a075c253e40d0659f0f372812df62af67ac177b45
7
+ data.tar.gz: 3d088168caf4810cc63ea011fdde152e849f7b7a7e9bdb7d1c200e644afae44d07d855c9b9da314bbde20ffb227e6f979e598c0884c468a65b51002f7d0fc572
@@ -13,3 +13,6 @@
13
13
 
14
14
  # v1.0.0.beta1
15
15
  * Added access to User API
16
+
17
+ # v1.0.0
18
+ * Channel access has been added
data/README.md CHANGED
@@ -118,6 +118,71 @@ Get all channels who are favorites of a user.
118
118
 
119
119
  Pass in a user's login.
120
120
 
121
+ ### Channel
122
+
123
+ #### Show
124
+
125
+ Returns extended information for a channel, specified by channel id or login.
126
+ Requires OAuth authentication for private channels.
127
+
128
+ ```ruby
129
+ Jtv.channel_show 'apidemo'
130
+ # {'login'=>'apidemo'...}
131
+ ```
132
+
133
+ Pass in a login or id for the channel.
134
+
135
+ #### Fans
136
+
137
+ Get users who are fans of a channel. Requires OAuth authentication for private
138
+ channels.
139
+
140
+ ```ruby
141
+ Jtv.fans id: 'officecam'
142
+ # [{'id'=>23}]
143
+ ```
144
+
145
+ Login must be included for the channel. Optional limit and offset params
146
+ (defaults are 20 for limit and 0 for offset). Results returned are limited to
147
+ 100. Results are returned in create date order.
148
+
149
+ #### Archives
150
+
151
+ Get archives from a given channel. Requires OAuth authentication for private
152
+ channels.
153
+
154
+ ```ruby
155
+ Jtv.archives id: 'dotahut', limit: 2
156
+ # [{'video_codec' => 'AVC'}, {}]
157
+ ```
158
+
159
+ channel id or login must be included as a param. Optional limit and offset
160
+ params (defaults are 20 for limit and 0 for offset). Results returned are
161
+ limited to 100. Results are returned in create date order
162
+
163
+ #### Embed
164
+
165
+ Get embed code for a channel.
166
+
167
+ ```ruby
168
+ Jtv.embed 'justin', volume: 50
169
+ # "<object></object>"
170
+ ```
171
+
172
+ You can supply params volume, publisher_guard (for the default channel password
173
+ to try), height, width, and watermark_position
174
+
175
+ #### Chat Embed
176
+
177
+ Get chat embed code for a channel.
178
+
179
+ ```ruby
180
+ Jtv.chat_embed 'justin', height: 1000
181
+ # "<iframe></iframe>"
182
+ ```
183
+
184
+ You can supply params height and width.
185
+
121
186
  ## Contributing
122
187
 
123
188
  Contributions and feedback are more than welcome and highly encouraged.
@@ -20,7 +20,7 @@ Gem::Specification.new do |gem|
20
20
  gem.add_development_dependency 'rake'
21
21
  gem.add_development_dependency 'rspec'
22
22
  gem.add_development_dependency 'vcr'
23
- gem.add_development_dependency 'fakeweb'
23
+ gem.add_development_dependency 'webmock'
24
24
  gem.add_dependency 'faraday'
25
25
  gem.add_dependency 'json'
26
26
  gem.add_dependency 'simple_oauth'
@@ -0,0 +1,23 @@
1
+ module Jtv
2
+ module Channel
3
+ def channel_show id
4
+ get "channel/show/#{id}.json"
5
+ end
6
+
7
+ def fans params = {}
8
+ get 'channel/fans', params
9
+ end
10
+
11
+ def archives params = {}
12
+ get 'channel/archives', params
13
+ end
14
+
15
+ def embed id, params = {}
16
+ request(:get, "channel/embed/#{id}", params)[:body]
17
+ end
18
+
19
+ def chat_embed id, params = {}
20
+ request(:get, "channel/chat_embed/#{id}", params)[:body]
21
+ end
22
+ end
23
+ end
@@ -4,12 +4,14 @@ require 'faraday'
4
4
  require 'jtv/defaults'
5
5
  require 'jtv/stream'
6
6
  require 'jtv/user'
7
+ require 'jtv/channel'
7
8
 
8
9
  module Jtv
9
10
  class Client
10
11
  include Jtv::Defaults
11
12
  include Jtv::Stream
12
13
  include Jtv::User
14
+ include Jtv::Channel
13
15
 
14
16
  def initialize args = {}
15
17
  args.each do |key, value|
@@ -1,3 +1,3 @@
1
1
  module Jtv
2
- VERSION = "1.0.0.beta1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+ require 'vcr_config'
3
+
4
+ describe Jtv::Channel do
5
+ describe '#fans', :vcr do
6
+ it 'fetches fans for a given channel' do
7
+ fans = Jtv.fans id: 'officecam'
8
+ expect(fans).to be_an Array
9
+ expect(fans.first).to be_a Hash
10
+ expect(fans.first['id']).to be_an Integer
11
+ end
12
+ end
13
+
14
+ describe '#archives', :vcr do
15
+ it 'returns an array of archives for given channel' do
16
+ archives = Jtv.archives id: 'dotahut', limit: 2
17
+ expect(archives).to be_an Array
18
+ expect(archives.count).to eq 2
19
+ expect(archives.first['video_codec']).to eq 'AVC'
20
+ end
21
+ end
22
+
23
+ describe '#channel_show', :vcr do
24
+ it 'provides information for a given channel' do
25
+ channel = Jtv.channel_show 'apidemo'
26
+ expect(channel['login']).to eq 'apidemo'
27
+ end
28
+ end
29
+
30
+ describe '#embed', :vcr do
31
+ it 'returns a string containing an embed object' do
32
+ embed = Jtv.embed 'justin', volume: 50
33
+ expect(embed).to be_a String
34
+ expect(embed).to include 'volume=50'
35
+ expect(embed).to include 'object'
36
+ expect(embed).to include 'x-shockwave-flash'
37
+ end
38
+ end
39
+
40
+ describe '#chat_embed', :vcr do
41
+ it 'returns an iframe for chat' do
42
+ chat = Jtv.chat_embed 'justin', height: 50
43
+ expect(chat).to be_a String
44
+ expect(chat).to include 'height:50px'
45
+ expect(chat).to include 'iframe'
46
+ end
47
+ end
48
+ end
@@ -2,18 +2,14 @@ require 'spec_helper'
2
2
  require 'vcr_config'
3
3
 
4
4
  describe Jtv::Stream do
5
- describe '#summary' do
6
- use_vcr_cassette
7
-
8
- it 'fetches a live channel' do
5
+ describe '#summary', :vcr do
6
+ it 'returns a summary of Jutstin.tv data' do
9
7
  summary = Jtv.summary
10
8
  expect(summary['streams_count']).to be > 0
11
9
  end
12
10
  end
13
11
 
14
- describe '#list' do
15
- use_vcr_cassette
16
-
12
+ describe '#list', :vcr do
17
13
  it 'returns a list of streams for a category' do
18
14
  list = Jtv.list category: 'gaming'
19
15
  expect(list.count).to eq 50
@@ -21,9 +17,7 @@ describe Jtv::Stream do
21
17
  end
22
18
  end
23
19
 
24
- describe '#search' do
25
- use_vcr_cassette
26
-
20
+ describe '#search', :vcr do
27
21
  it 'returns streams based on search query' do
28
22
  search = Jtv.search 'league of legends', limit: 10
29
23
  expect(search.count).to eq 10
@@ -2,18 +2,14 @@ require 'spec_helper'
2
2
  require 'vcr_config'
3
3
 
4
4
  describe Jtv::User do
5
- describe '#user_show' do
6
- use_vcr_cassette
7
-
5
+ describe '#user_show', :vcr do
8
6
  it 'fetches information on user' do
9
7
  user = Jtv.user_show 'augury'
10
8
  expect(user['login']).to eq 'augury'
11
9
  end
12
10
  end
13
11
 
14
- describe '#favorites' do
15
- use_vcr_cassette
16
-
12
+ describe '#favorites', :vcr do
17
13
  it 'fetches favorites from user' do
18
14
  user = Jtv.favorites 'augury'
19
15
  expect(user.first['language']).to eq 'en'
@@ -0,0 +1,44 @@
1
+ require_relative '../../lib/jtv/channel'
2
+
3
+ class Client; include Jtv::Channel; end
4
+
5
+ describe Jtv::Channel do
6
+ let(:client) { Client.new }
7
+
8
+ describe '#channel_show' do
9
+ it 'sends path with user to get' do
10
+ client.should_receive(:get).with 'channel/show/test.json'
11
+ client.channel_show 'test'
12
+ end
13
+ end
14
+
15
+ describe '#fans' do
16
+ it 'sends fans and params to get' do
17
+ client.should_receive(:get).with 'channel/fans', { channel: 'test' }
18
+ client.fans channel: 'test'
19
+ end
20
+ end
21
+
22
+ describe '#archives' do
23
+ it 'sends archives and params to get' do
24
+ client.should_receive(:get).with 'channel/archives', { channel: 'test' }
25
+ client.archives channel: 'test'
26
+ end
27
+ end
28
+
29
+ describe '#embed' do
30
+ it 'sends :get, embed path with login and params to request' do
31
+ client.should_receive(:request).with(:get, 'channel/embed/test',
32
+ { volume: 50 }).and_return({})
33
+ client.embed 'test', volume: 50
34
+ end
35
+ end
36
+
37
+ describe '#chat_embed' do
38
+ it 'sends :get, chat_embed path with login and params to request' do
39
+ client.should_receive(:request).with(:get, 'channel/chat_embed/justin',
40
+ { height: 50 }).and_return({})
41
+ client.chat_embed 'justin', height: 50
42
+ end
43
+ end
44
+ end
@@ -31,4 +31,14 @@ describe Jtv::Client do
31
31
  expect(client).to respond_to :favorites
32
32
  end
33
33
  end
34
+
35
+ context 'when including channel' do
36
+ it 'has access to show, stream_key, fans, and archives' do
37
+ expect(client).to respond_to :channel_show
38
+ expect(client).to respond_to :fans
39
+ expect(client).to respond_to :archives
40
+ expect(client).to respond_to :embed
41
+ expect(client).to respond_to :chat_embed
42
+ end
43
+ end
34
44
  end
@@ -0,0 +1,70 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.justin.tv/channel/archives?id=dotahut&limit=2
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ User-Agent:
13
+ - Jtv Gem
14
+ Authorization:
15
+ - OAuth oauth_nonce="51bdd0301c7a46881c7635851e726de7", oauth_signature="yZqw6ElypWDy5BrEKQCNZMqks8M%3D",
16
+ oauth_signature_method="HMAC-SHA1", oauth_timestamp="1361148689", oauth_version="1.0"
17
+ Accept-Encoding:
18
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
19
+ response:
20
+ status:
21
+ code: 200
22
+ message: OK
23
+ headers:
24
+ Server:
25
+ - nginx
26
+ Date:
27
+ - Mon, 18 Feb 2013 00:51:29 GMT
28
+ Content-Type:
29
+ - application/json
30
+ Transfer-Encoding:
31
+ - chunked
32
+ Connection:
33
+ - close
34
+ Status:
35
+ - 200 OK
36
+ Via:
37
+ - Twice 0.2 twice8:3346
38
+ X-Runtime:
39
+ - '0.027745'
40
+ X-Geo:
41
+ - US
42
+ X-Request-Id:
43
+ - 701588087b4b4105c6c82ecef540c699
44
+ Etag:
45
+ - '"69d23dbdb82971fa60ad0740024a8500"'
46
+ X-Ua-Compatible:
47
+ - IE=Edge,chrome=1
48
+ Cache-Control:
49
+ - must-revalidate, private, max-age=0
50
+ X-Rack-Cache:
51
+ - miss
52
+ Set-Cookie:
53
+ - language=en; domain=.twitch.tv; path=/; expires=Fri, 18-Feb-2033 00:51:29
54
+ GMT
55
+ Front-End-Https:
56
+ - 'off'
57
+ body:
58
+ encoding: UTF-8
59
+ string: '[{"image_url_medium":"http://static-cdn.jtvnw.net/jtv.thumbs/archive-368105393-320x240.jpg","video_rotation":"0","created_on":"2013-02-16
60
+ 22:36:52 UTC","title":"DotaHut Invitational: No Tidehunter vs. Team Liquid
61
+ (bo3 casted by Maut)","filtered":"unchecked","stream_name":"live_user_dotahut","video_bitrate":"1634887.0","broadcaster":"delay","save_forever":"false","broadcast_id":"4881010784","updated_on":"2013-02-16
62
+ 22:36:55 UTC","file_name":"2013-2-16/live_user_dotahut_1361053132.flv","id":"368105393","broadcast_part":"6","origin_name":"3810080","file_size":"216827014","audio_codec":"aac","deleted_by_user":"false","user_id":"38409951","tag_list":"","keyframes":"","length":"1061","video_file_url":"http://media22.justin.tv/archives/2013-2-16/live_user_dotahut_1361053132.flv","servers":"23","video_codec":"AVC","last_part":"true","start_time":"2013-02-16
63
+ 22:18:52 UTC"},{"image_url_medium":"http://static-cdn.jtvnw.net/jtv.thumbs/archive-368099460-320x240.jpg","video_rotation":"0","created_on":"2013-02-16
64
+ 22:19:10 UTC","title":"DotaHut Invitational: No Tidehunter vs. Team Liquid
65
+ (bo3 casted by Maut)","filtered":"unchecked","stream_name":"live_user_dotahut","video_bitrate":"1024628.0","broadcaster":"delay","save_forever":"false","broadcast_id":"4881010784","updated_on":"2013-02-16
66
+ 22:19:12 UTC","file_name":"2013-2-16/live_user_dotahut_1361051335.flv","id":"368099460","broadcast_part":"5","origin_name":"3810080","file_size":"230157225","audio_codec":"aac","deleted_by_user":"false","user_id":"38409951","tag_list":"","keyframes":"","length":"1797","video_file_url":"http://media32.justin.tv/archives/2013-2-16/live_user_dotahut_1361051335.flv","servers":"34","video_codec":"AVC","last_part":"false","start_time":"2013-02-16
67
+ 21:48:55 UTC"}]'
68
+ http_version:
69
+ recorded_at: Mon, 18 Feb 2013 00:51:29 GMT
70
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,69 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.justin.tv/channel/show/apidemo.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ User-Agent:
13
+ - Jtv Gem
14
+ Authorization:
15
+ - OAuth oauth_nonce="613a09775b6dbb5efbc4e91b7da1c3f4", oauth_signature="XxWxfNSnQqyKGRV3IbCTAND3GLA%3D",
16
+ oauth_signature_method="HMAC-SHA1", oauth_timestamp="1361148689", oauth_version="1.0"
17
+ Accept-Encoding:
18
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
19
+ response:
20
+ status:
21
+ code: 200
22
+ message: OK
23
+ headers:
24
+ Server:
25
+ - nginx
26
+ Date:
27
+ - Mon, 18 Feb 2013 00:51:29 GMT
28
+ Content-Type:
29
+ - application/json
30
+ Transfer-Encoding:
31
+ - chunked
32
+ Connection:
33
+ - close
34
+ Status:
35
+ - 200 OK
36
+ Via:
37
+ - Twice 0.2 twice1:3357
38
+ X-Runtime:
39
+ - '0.013731'
40
+ X-Geo:
41
+ - US
42
+ X-Request-Id:
43
+ - 914065f70dc7d033f46e7f6f7afbc54e
44
+ Etag:
45
+ - '"bfaefa574dd7d39f6d74ff48befc9bc1"'
46
+ X-Ua-Compatible:
47
+ - IE=Edge,chrome=1
48
+ Cache-Control:
49
+ - must-revalidate, private, max-age=0
50
+ X-Rack-Cache:
51
+ - miss
52
+ Set-Cookie:
53
+ - language=en; domain=.twitch.tv; path=/; expires=Fri, 18-Feb-2033 00:51:29
54
+ GMT
55
+ Front-End-Https:
56
+ - 'off'
57
+ body:
58
+ encoding: UTF-8
59
+ string: '{"screen_cap_url_huge":"http://static-cdn.jtvnw.net/previews/live_user_apidemo-630x473.jpg","timezone":"America/Los_Angeles","tags":null,"category_title":"Animals","subcategory":"other_animals","category":"animals","about":null,"views_count":"38302","screen_cap_url_large":"http://static-cdn.jtvnw.net/previews/live_user_apidemo-320x240.jpg","status":null,"channel_background_image_url":null,"embed_enabled":true,"image_url_huge":"http://www-cdn.jtvnw.net/images/xarth/404_user_600x600.png","channel_url":"http://www.justin.tv/apidemo","subcategory_title":"Other
60
+ Animals","title":"API demo (in HD)","channel_link_color":"#0066CC","screen_cap_url_small":"http://static-cdn.jtvnw.net/previews/live_user_apidemo-70x53.jpg","mature":null,"channel_header_image_url":null,"screen_cap_url_medium":"http://static-cdn.jtvnw.net/previews/live_user_apidemo-150x113.jpg","image_url_large":"http://www-cdn.jtvnw.net/images/xarth/404_user_300x300.png","id":6285586,"channel_column_color":"#FFFFFF","image_url_medium":"http://www-cdn.jtvnw.net/images/xarth/404_user_150x150.png","producer":false,"image_url_small":"http://www-cdn.jtvnw.net/images/xarth/404_user_70x70.png","channel_background_color":"#E1E3E6","anonymous_chatters_allowed":false,"embed_code":" <object
61
+ type=\"application/x-shockwave-flash\" height=\"295\" width=\"353\" id=\"live_embed_player_flash\"
62
+ data=\"http://www.justin.tv/widgets/live_embed_player.swf?channel=apidemo\"
63
+ bgcolor=\"#000000\"><param name=\"allowFullScreen\" value=\"true\" /><param
64
+ name=\"allowscriptaccess\" value=\"always\" /><param name=\"movie\" value=\"http://www.justin.tv/widgets/live_embed_player.swf\"
65
+ /><param name=\"flashvars\" value=\"auto_play=false&channel=apidemo&start_volume=25\"
66
+ /></object>\n","image_url_tiny":"http://www-cdn.jtvnw.net/images/xarth/404_user_50x50.png","language":"en","login":"apidemo","channel_text_color":"#222222","description":null}'
67
+ http_version:
68
+ recorded_at: Mon, 18 Feb 2013 00:51:29 GMT
69
+ recorded_with: VCR 2.4.0