shuffler_fm 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/.gitignore +21 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +10 -0
  4. data/.yardopts +2 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +22 -0
  7. data/README.md +121 -0
  8. data/Rakefile +37 -0
  9. data/lib/shuffler_fm/api/artists.rb +53 -0
  10. data/lib/shuffler_fm/api/blogs.rb +52 -0
  11. data/lib/shuffler_fm/api/channels.rb +88 -0
  12. data/lib/shuffler_fm/api/charts.rb +28 -0
  13. data/lib/shuffler_fm/api/genres.rb +28 -0
  14. data/lib/shuffler_fm/api/tracks.rb +33 -0
  15. data/lib/shuffler_fm/api.rb +54 -0
  16. data/lib/shuffler_fm/configuration.rb +44 -0
  17. data/lib/shuffler_fm/errors.rb +37 -0
  18. data/lib/shuffler_fm/http.rb +25 -0
  19. data/lib/shuffler_fm/middleware/error_handler.rb +49 -0
  20. data/lib/shuffler_fm/request.rb +25 -0
  21. data/lib/shuffler_fm/version.rb +3 -0
  22. data/lib/shuffler_fm.rb +67 -0
  23. data/shuffler_fm.gemspec +37 -0
  24. data/spec/config.yml.sample +3 -0
  25. data/spec/fixtures/vcr_cassettes/api.yml +26 -0
  26. data/spec/fixtures/vcr_cassettes/artists.yml +187 -0
  27. data/spec/fixtures/vcr_cassettes/blogs.yml +187 -0
  28. data/spec/fixtures/vcr_cassettes/channels.yml +95 -0
  29. data/spec/fixtures/vcr_cassettes/charts.yml +95 -0
  30. data/spec/fixtures/vcr_cassettes/genres.yml +95 -0
  31. data/spec/fixtures/vcr_cassettes/tracks.yml +95 -0
  32. data/spec/helper.rb +39 -0
  33. data/spec/shuffler_fm/api/artists_spec.rb +25 -0
  34. data/spec/shuffler_fm/api/blogs_spec.rb +25 -0
  35. data/spec/shuffler_fm/api/channels_spec.rb +23 -0
  36. data/spec/shuffler_fm/api/charts_spec.rb +15 -0
  37. data/spec/shuffler_fm/api/genres_spec.rb +15 -0
  38. data/spec/shuffler_fm/api/tracks_spec.rb +15 -0
  39. data/spec/shuffler_fm/api_spec.rb +15 -0
  40. data/spec/shuffler_fm/configuration_spec.rb +9 -0
  41. data/spec/shuffler_fm/middleware/error_handler_spec.rb +29 -0
  42. data/spec/shufflerfm_spec.rb +29 -0
  43. metadata +315 -0
data/spec/helper.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'simplecov'
2
+ require 'yaml'
3
+ require 'webmock/rspec'
4
+ require 'vcr'
5
+ require 'pry'
6
+
7
+ #setup simplecov
8
+ SimpleCov.start do
9
+ add_filter "/spec"
10
+ end
11
+
12
+ require File.expand_path('../../lib/shuffler_fm', __FILE__)
13
+
14
+ # load config
15
+ begin
16
+ cfg = YAML::load(File.open(File.expand_path('../config.yml', __FILE__)))
17
+ raise "Couldn't find a key" if cfg['key'].nil?
18
+ KEY = cfg['key']
19
+ rescue Errno::ENOENT
20
+ puts "NOTICE: no key configured."
21
+ KEY = 'No-Key'
22
+ end
23
+
24
+ # setup VCR
25
+ VCR.configure do |cfg|
26
+ cfg.filter_sensitive_data('<api-key>') { KEY }
27
+ cfg.default_cassette_options = { :record => :new_episodes }
28
+ cfg.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
29
+ cfg.hook_into :webmock
30
+ end
31
+
32
+ # add VCR macros to rspec
33
+ RSpec.configure do |cfg|
34
+ cfg.extend VCR::RSpec::Macros
35
+ end
36
+
37
+ def fixture(filename)
38
+ File.new(File.expand_path("../fixtures/#{filename}", __FILE__))
39
+ end
@@ -0,0 +1,25 @@
1
+ describe ShufflerFM::API::Artists do
2
+ use_vcr_cassette :artists
3
+
4
+ let!(:api) { ShufflerFM::API.new(KEY) }
5
+
6
+ it 'lists artists' do
7
+ api.artists.size.should be(50)
8
+ api.artists(:page => 3).size.should be(50)
9
+ end
10
+
11
+ it 'requests a specific artist' do
12
+ api.artist(1).should be_a(Hashie::Mash)
13
+ api.artist(0).should be_nil
14
+ end
15
+
16
+ it 'requests an artist top blogs' do
17
+ api.artist_blogs(1).should be_a(Array)
18
+ api.artist_blogs(1, :page => 3).should be_a(Array)
19
+ end
20
+
21
+ it 'searches for an artist' do
22
+ api.search_artists('queen').should be_a(Array)
23
+ api.search_artists('queen', :page => 3).should be_a(Array)
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ describe ShufflerFM::API::Blogs do
2
+ use_vcr_cassette :blogs
3
+
4
+ let!(:api) { ShufflerFM::API.new(KEY) }
5
+
6
+ it 'lists blogs' do
7
+ api.blogs.should be_a(Array)
8
+ api.blogs(:page => 2).should be_a(Array)
9
+ end
10
+
11
+ it 'lists featured blogs' do
12
+ api.featured_blogs.should be_a(Array)
13
+ api.featured_blogs(:page => 2).should be_a(Array)
14
+ end
15
+
16
+ it 'requests an particular blog' do
17
+ api.blog(1).should be_a(Hashie::Mash)
18
+ api.blog(0).should be_nil
19
+ end
20
+
21
+ it 'searches for a blog' do
22
+ api.search_blogs('queen').should be_a(Array)
23
+ api.search_blogs('queen', :page => 3).should be_a(Array)
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ describe ShufflerFM::API::Channels do
2
+ use_vcr_cassette :channels
3
+
4
+ describe 'stream activity on' do
5
+ let!(:api) { ShufflerFM::API.new(KEY) }
6
+
7
+ it 'media' do
8
+ api.media_channels('mp3').should be_a(Array)
9
+ end
10
+
11
+ it 'blogs' do
12
+ api.blog_channels(1).should be_a(Array)
13
+ end
14
+
15
+ it 'artists' do
16
+ api.artist_channels('Pixies', :page => 2).should be_a(Array)
17
+ end
18
+
19
+ it 'genre' do
20
+ api.genre_channels('punk', 'rock', :page => 2).should be_a(Array)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ describe ShufflerFM::API::Charts do
2
+ use_vcr_cassette :charts
3
+
4
+ let!(:api) { ShufflerFM.api(KEY) }
5
+
6
+ it 'lists popular charts' do
7
+ api.popular_charts.should be_a(Array)
8
+ api.popular_charts(:page => 2).should be_a(Array)
9
+ end
10
+
11
+ it 'lists tracks that were recently added to the popular list' do
12
+ api.popular_charts_newest.should be_a(Array)
13
+ api.popular_charts_newest(:page => 2).should be_a(Array)
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ describe ShufflerFM::API::Genres do
2
+ use_vcr_cassette :genres
3
+
4
+ let!(:api) { ShufflerFM.api(KEY) }
5
+
6
+ it 'lists genres' do
7
+ api.genres.should be_a(Array)
8
+ api.genres(:page => 2).should be_a(Array)
9
+ end
10
+
11
+ it 'requests a specific genre' do
12
+ api.genre(1).should be_a(Hashie::Mash)
13
+ api.genre(0).should be_nil
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ describe ShufflerFM::API::Tracks do
2
+ use_vcr_cassette :tracks
3
+
4
+ let!(:api) { ShufflerFM::API.new(KEY) }
5
+
6
+ it 'lists tracks' do
7
+ api.tracks.size.should be(50)
8
+ api.tracks(:page => 2).size.should be(50)
9
+ end
10
+
11
+ it 'requests a specific track' do
12
+ api.track(1).should be_a(Hashie::Mash)
13
+ api.track(0).should be_nil
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ describe ShufflerFM::API do
2
+ use_vcr_cassette :api
3
+
4
+ it 'requires a key' do
5
+ expect { ShufflerFM::API.new(KEY) }.not_to raise_error
6
+ end
7
+
8
+ context 'on invalid api key' do
9
+ let!(:api) { ShufflerFM::API.new('NO-SUCH-KEY') }
10
+
11
+ it 'throws exception' do
12
+ expect { api.tracks }.to raise_error(ShufflerFM::Forbidden)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ describe ShufflerFM::Configuration do
2
+ let!(:cfg) { ShufflerFM::Configuration.new }
3
+
4
+ it 'has default values' do
5
+ cfg.connection_timeout.should eq(2)
6
+ cfg.read_timeout.should eq(5)
7
+ cfg.proxy.should be_nil
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ describe ShufflerFM::Middleware::ErrorHandler do
2
+ use_vcr_cassette :tracks
3
+
4
+ @errors = { 400 => ShufflerFM::BadRequest,
5
+ 401 => ShufflerFM::Unauthorized,
6
+ 403 => ShufflerFM::Forbidden,
7
+ 404 => ShufflerFM::NotFound,
8
+ 406 => ShufflerFM::NotAcceptable,
9
+ 422 => ShufflerFM::UnprocessableEntity,
10
+ 429 => ShufflerFM::TooManyRequests,
11
+ 500 => ShufflerFM::InternalServerError,
12
+ 501 => ShufflerFM::NotImplemented,
13
+ 502 => ShufflerFM::BadGateway,
14
+ 503 => ShufflerFM::ServiceUnavailable }
15
+
16
+ @errors.each do |status, error|
17
+ context "on response status #{status}" do
18
+ let!(:api) { ShufflerFM::API.new(KEY) }
19
+
20
+ before(:each) do
21
+ stub_request(:get, "http://api.shuffler.fm/v1/tracks?api-key=#{KEY}&page=1").to_return(:status => status)
22
+ end
23
+
24
+ it "should raise #{error.name}" do
25
+ expect { api.tracks }.to raise_error(error)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ describe ShufflerFM do
2
+ it 'provides an API given an api key' do
3
+ ShufflerFM.api(KEY).should be_a(ShufflerFM::API)
4
+ end
5
+
6
+ context 'is configurable' do
7
+ it 'with a block' do
8
+ ShufflerFM.configure do |cfg|
9
+ cfg.connection_timeout = 1 #seconds
10
+ cfg.read_timeout = 5 #seconds
11
+ cfg.proxy = 'http://192.168.1.1:8080'
12
+ end
13
+
14
+ ShufflerFM.configuration.values.should eq(:connection_timeout => 1,
15
+ :read_timeout => 5,
16
+ :proxy => 'http://192.168.1.1:8080')
17
+ end
18
+
19
+ it 'with a hash' do
20
+ ShufflerFM.api(KEY, :connection_timeout => 2,
21
+ :read_timeout => 3,
22
+ :proxy => 'http://127.0.0.1:8888')
23
+
24
+ ShufflerFM.configuration.connection_timeout.should eq(2)
25
+ ShufflerFM.configuration.read_timeout.should eq(3)
26
+ ShufflerFM.configuration.proxy.should eq('http://127.0.0.1:8888')
27
+ end
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,315 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shuffler_fm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Miguel Guinada
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.8'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.8'
30
+ - !ruby/object:Gem::Dependency
31
+ name: faraday_middleware
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '0.8'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '0.8'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rash
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '0.3'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: multi_json
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.3'
78
+ - !ruby/object:Gem::Dependency
79
+ name: json
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '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: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rake
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: pry
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rspec
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: webmock
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: vcr
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: simplecov
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ - !ruby/object:Gem::Dependency
191
+ name: yard
192
+ requirement: !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ! '>='
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ type: :development
199
+ prerelease: false
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ - !ruby/object:Gem::Dependency
207
+ name: maruku
208
+ requirement: !ruby/object:Gem::Requirement
209
+ none: false
210
+ requirements:
211
+ - - ! '>='
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ type: :development
215
+ prerelease: false
216
+ version_requirements: !ruby/object:Gem::Requirement
217
+ none: false
218
+ requirements:
219
+ - - ! '>='
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ description: ! ' shuffler_fm wraps shuffler.fm''s REST api on a thin layer of ruby. '
223
+ email:
224
+ - mguinada@gmail.com
225
+ executables: []
226
+ extensions: []
227
+ extra_rdoc_files: []
228
+ files:
229
+ - .gitignore
230
+ - .rspec
231
+ - .travis.yml
232
+ - .yardopts
233
+ - Gemfile
234
+ - LICENSE
235
+ - README.md
236
+ - Rakefile
237
+ - lib/shuffler_fm.rb
238
+ - lib/shuffler_fm/api.rb
239
+ - lib/shuffler_fm/api/artists.rb
240
+ - lib/shuffler_fm/api/blogs.rb
241
+ - lib/shuffler_fm/api/channels.rb
242
+ - lib/shuffler_fm/api/charts.rb
243
+ - lib/shuffler_fm/api/genres.rb
244
+ - lib/shuffler_fm/api/tracks.rb
245
+ - lib/shuffler_fm/configuration.rb
246
+ - lib/shuffler_fm/errors.rb
247
+ - lib/shuffler_fm/http.rb
248
+ - lib/shuffler_fm/middleware/error_handler.rb
249
+ - lib/shuffler_fm/request.rb
250
+ - lib/shuffler_fm/version.rb
251
+ - shuffler_fm.gemspec
252
+ - spec/config.yml.sample
253
+ - spec/fixtures/vcr_cassettes/api.yml
254
+ - spec/fixtures/vcr_cassettes/artists.yml
255
+ - spec/fixtures/vcr_cassettes/blogs.yml
256
+ - spec/fixtures/vcr_cassettes/channels.yml
257
+ - spec/fixtures/vcr_cassettes/charts.yml
258
+ - spec/fixtures/vcr_cassettes/genres.yml
259
+ - spec/fixtures/vcr_cassettes/tracks.yml
260
+ - spec/helper.rb
261
+ - spec/shuffler_fm/api/artists_spec.rb
262
+ - spec/shuffler_fm/api/blogs_spec.rb
263
+ - spec/shuffler_fm/api/channels_spec.rb
264
+ - spec/shuffler_fm/api/charts_spec.rb
265
+ - spec/shuffler_fm/api/genres_spec.rb
266
+ - spec/shuffler_fm/api/tracks_spec.rb
267
+ - spec/shuffler_fm/api_spec.rb
268
+ - spec/shuffler_fm/configuration_spec.rb
269
+ - spec/shuffler_fm/middleware/error_handler_spec.rb
270
+ - spec/shufflerfm_spec.rb
271
+ homepage: https://github.com/mguinada/shuffler_fm
272
+ licenses: []
273
+ post_install_message:
274
+ rdoc_options: []
275
+ require_paths:
276
+ - lib
277
+ required_ruby_version: !ruby/object:Gem::Requirement
278
+ none: false
279
+ requirements:
280
+ - - ! '>='
281
+ - !ruby/object:Gem::Version
282
+ version: '0'
283
+ required_rubygems_version: !ruby/object:Gem::Requirement
284
+ none: false
285
+ requirements:
286
+ - - ! '>='
287
+ - !ruby/object:Gem::Version
288
+ version: '0'
289
+ requirements: []
290
+ rubyforge_project:
291
+ rubygems_version: 1.8.24
292
+ signing_key:
293
+ specification_version: 3
294
+ summary: Ruby API wrapper for http://shuffler.fm
295
+ test_files:
296
+ - spec/config.yml.sample
297
+ - spec/fixtures/vcr_cassettes/api.yml
298
+ - spec/fixtures/vcr_cassettes/artists.yml
299
+ - spec/fixtures/vcr_cassettes/blogs.yml
300
+ - spec/fixtures/vcr_cassettes/channels.yml
301
+ - spec/fixtures/vcr_cassettes/charts.yml
302
+ - spec/fixtures/vcr_cassettes/genres.yml
303
+ - spec/fixtures/vcr_cassettes/tracks.yml
304
+ - spec/helper.rb
305
+ - spec/shuffler_fm/api/artists_spec.rb
306
+ - spec/shuffler_fm/api/blogs_spec.rb
307
+ - spec/shuffler_fm/api/channels_spec.rb
308
+ - spec/shuffler_fm/api/charts_spec.rb
309
+ - spec/shuffler_fm/api/genres_spec.rb
310
+ - spec/shuffler_fm/api/tracks_spec.rb
311
+ - spec/shuffler_fm/api_spec.rb
312
+ - spec/shuffler_fm/configuration_spec.rb
313
+ - spec/shuffler_fm/middleware/error_handler_spec.rb
314
+ - spec/shufflerfm_spec.rb
315
+ has_rdoc: