shuffler_fm 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ 0.1.0
2
+ -----
3
+
4
+ Added track streaming URI acquisition (Tracks#stream)
5
+
6
+ 0.0.2
7
+ -----
8
+
9
+ Added the per_page parameter & corrected pagination threshold
10
+
11
+ 0.0.1
12
+ -----
13
+
14
+ 1st release
data/README.md CHANGED
@@ -59,6 +59,7 @@ track.metadata.artist.name
59
59
 
60
60
  ### Search for an artist
61
61
  ```ruby
62
+
62
63
  api.search_artists('radiohead').map(&:name)
63
64
  => ["Radiohead", "Radiohead at Lollapalooza 2008", "REM & Radiohead", "Radiohead 6. Permanent Daylight live", "Radiohead @ Optimus Alive'12", "I Can't Take The Hurt (Johnny Cash vs Tegan and Sarah and Radiohead)"]
64
65
  ```
@@ -67,7 +68,7 @@ api.search_artists('radiohead').map(&:name)
67
68
  ```ruby
68
69
 
69
70
  activity = []
70
- api.genre_channels('punk', 'rock').each do |act|
71
+ api.genre_channels('punk', 'rock', page: 1, per_page: 10).each do |act|
71
72
  activity << "#{act.verb.capitalize} on #{act.actor.title} refering music track #{act.object.metadata.title}"
72
73
  end
73
74
 
@@ -13,7 +13,7 @@ module ShufflerFM
13
13
  # @return [Array] an array with the channel's activity stream
14
14
  #
15
15
  # @example
16
- # api.media_channels('youtube', page: 2)
16
+ # api.media_channels('soundcloud')
17
17
  #
18
18
  def media_channels(key, options = {})
19
19
  channel(:media, key, options)
@@ -21,7 +21,7 @@ module ShufflerFM
21
21
 
22
22
  # Reads the blog channels activity stream
23
23
  #
24
- # @param [String] key The channel key.
24
+ # @param [Integer] key The blog id
25
25
  # @param [Hash] options
26
26
  # @option options [Integer] :page The page to request on paginated operation responses. First page is page 1.
27
27
  # @option options [Integer] :per_page The page size. Default is 50, maximum is 100.
@@ -37,7 +37,6 @@ module ShufflerFM
37
37
 
38
38
  # Reads the artist channels activity stream
39
39
  #
40
- # @param key The channel key.
41
40
  # @param [Hash] options
42
41
  # @option options [Integer] :page The page to request on paginated operation responses. First page is page 1.
43
42
  # @option options [Integer] :per_page The page size. Default is 50, maximum is 100.
@@ -53,13 +52,22 @@ module ShufflerFM
53
52
 
54
53
  # Reads the genere channels activity stream.
55
54
  #
56
- # @param [Array] keys The channel keys.
55
+ # @overload genre_channels(*keys)
56
+ # @param [Array] keys The channel keys.
57
57
  #
58
- # @return [Array] an array with the channel's activity stream
58
+ # @example
59
+ # api.genre_channels('punk')
60
+ # api.genre_channels('punk', 'rock')
59
61
  #
60
- # @example
61
- # api.genre_channels('rock')
62
- # api.genre_channels('punk', 'rock', page: 2)
62
+ # @overload genre_channels(*keys, options)
63
+ # @param [Hash] options
64
+ # @option options [Integer] :page The page to request on paginated operation responses. First page is page 1.
65
+ # @option options [Integer] :per_page The page size. Default is 50, maximum is 100.
66
+ #
67
+ # @example
68
+ # api.genre_channels('punk', 'rock', page: 1, per_page: 10)
69
+ #
70
+ # @return [Array] an array with the channel's activity stream
63
71
  #
64
72
  def genre_channels(*keys)
65
73
  channel(:genre, *keys)
@@ -29,6 +29,18 @@ module ShufflerFM
29
29
  rescue ShufflerFM::NotFound
30
30
  nil
31
31
  end
32
+
33
+ # Streaming URI for a track.
34
+ #
35
+ # NOTE: This operation requires a specific authorization form shuffler.fm
36
+ #
37
+ # @param [Integer] id The track id
38
+ #
39
+ # @return [URI] the track streaming URI if avaliable
40
+ #
41
+ def stream(id)
42
+ URI(get("/tracks/#{Integer(id)}/stream", {}, false).headers['location'])
43
+ end
32
44
  end
33
45
  end
34
46
  end
@@ -6,13 +6,15 @@ module ShufflerFM
6
6
  # @private
7
7
  module HTTP
8
8
  private
9
- def connection
9
+ def connection(managed = true)
10
10
  options = {:url => ShufflerFM::API.base_uri,
11
11
  :params => {'api-key' => key}}.merge(ShufflerFM.configuration.values)
12
12
 
13
13
  Faraday.new(options) do |builder|
14
- builder.use FaradayMiddleware::Rashify
15
- builder.use FaradayMiddleware::ParseJson
14
+ if managed
15
+ builder.use FaradayMiddleware::Rashify
16
+ builder.use FaradayMiddleware::ParseJson
17
+ end
16
18
 
17
19
  builder.use ShufflerFM::Middleware::ErrorHandler
18
20
 
@@ -7,19 +7,23 @@ module ShufflerFM
7
7
  # @param [String] path The request path
8
8
  # @param [Hash] options The operation options
9
9
  #
10
+ # @param [Boolean] managed true for a custom middleware mangaed connection,
11
+ # false to overide the middleware and recive the raw http response
12
+ #
10
13
  # @return The HTTP response
11
14
  #
12
- def get(path, options = {})
13
- request(:get, path, options)
15
+ def get(path, options = {}, managed = true)
16
+ request(:get, path, options, managed)
14
17
  end
15
18
 
16
19
  private
17
- def request(method, path, options = {})
18
- response = http_connection.send(method) do |request|
20
+ def request(method, path, options = {}, managed = true)
21
+ response = http_connection(managed).send(method) do |request|
19
22
  request.url("#{API.version}/#{path}", process_options(options))
20
23
  end
21
24
 
22
- response.body
25
+ return response.body if managed
26
+ response
23
27
  end
24
28
 
25
29
  def process_options(options)
@@ -1,3 +1,3 @@
1
1
  module ShufflerFM
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -92,4 +92,33 @@ http_interactions:
92
92
  string: ""
93
93
  http_version:
94
94
  recorded_at: Thu, 04 Oct 2012 20:57:56 GMT
95
+ - request:
96
+ method: get
97
+ uri: http://api.shuffler.fm/v1/tracks/1/stream?api-key=<api-key>&page=0
98
+ body:
99
+ string: ""
100
+ headers:
101
+ Accept:
102
+ - "*/*"
103
+ response:
104
+ status:
105
+ code: 302
106
+ message: FOUND
107
+ headers:
108
+ Content-Type:
109
+ - text/html; charset=utf-8
110
+ Server:
111
+ - TornadoServer/2.4
112
+ Location:
113
+ - http://api.soundcloud.com/tracks/9598274/stream?consumer_key=WFhMwGBRy2BnBBB7IK7WiQ
114
+ Content-Length:
115
+ - "373"
116
+ body:
117
+ string: |-
118
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
119
+ <title>Redirecting...</title>
120
+ <h1>Redirecting...</h1>
121
+ <p>You should be redirected automatically to target URL: <a href="http://api.soundcloud.com/tracks/9598274/stream?consumer_key=WFhMwGBRy2BnBBB7IK7WiQ">http://api.soundcloud.com/tracks/9598274/stream?consumer_key=WFhMwGBRy2BnBBB7IK7WiQ</a>. If not click the link.
122
+ http_version:
123
+ recorded_at: Mon, 08 Oct 2012 21:55:01 GMT
95
124
  recorded_with: VCR 2.2.5
data/spec/helper.rb CHANGED
@@ -24,7 +24,7 @@ end
24
24
  # setup VCR
25
25
  VCR.configure do |cfg|
26
26
  cfg.filter_sensitive_data('<api-key>') { KEY }
27
- cfg.default_cassette_options = { :record => :new_episodes, :serialize_with => :syck }
27
+ cfg.default_cassette_options = { :record => :new_episodes }
28
28
  cfg.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
29
29
  cfg.hook_into :webmock
30
30
  end
@@ -12,4 +12,8 @@ describe ShufflerFM::API::Tracks do
12
12
  api.track(1).should be_a(Hashie::Mash)
13
13
  api.track(0).should be_nil
14
14
  end
15
+
16
+ it 'requests a track stream' do
17
+ api.stream(1).should be_a(URI)
18
+ end
15
19
  end
metadata CHANGED
@@ -1,222 +1,236 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: shuffler_fm
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 2
10
- version: 0.0.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Miguel Guinada
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-10-04 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-10-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: faraday
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 27
29
- segments:
30
- - 0
31
- - 8
32
- version: "0.8"
20
+ - !ruby/object:Gem::Version
21
+ version: '0.8'
33
22
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: faraday_middleware
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
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
39
33
  none: false
40
- requirements:
34
+ requirements:
41
35
  - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 27
44
- segments:
45
- - 0
46
- - 8
47
- version: "0.8"
36
+ - !ruby/object:Gem::Version
37
+ version: '0.8'
48
38
  type: :runtime
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: rash
52
39
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
54
41
  none: false
55
- requirements:
42
+ requirements:
56
43
  - - ~>
57
- - !ruby/object:Gem::Version
58
- hash: 13
59
- segments:
60
- - 0
61
- - 3
62
- version: "0.3"
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'
63
54
  type: :runtime
64
- version_requirements: *id003
65
- - !ruby/object:Gem::Dependency
66
- name: multi_json
67
55
  prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
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
69
65
  none: false
70
- requirements:
66
+ requirements:
71
67
  - - ~>
72
- - !ruby/object:Gem::Version
73
- hash: 9
74
- segments:
75
- - 1
76
- - 3
77
- version: "1.3"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
78
70
  type: :runtime
79
- version_requirements: *id004
80
- - !ruby/object:Gem::Dependency
81
- name: json
82
71
  prerelease: false
83
- requirement: &id005 !ruby/object:Gem::Requirement
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
84
81
  none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- hash: 3
89
- segments:
90
- - 0
91
- version: "0"
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
92
86
  type: :development
93
- version_requirements: *id005
94
- - !ruby/object:Gem::Dependency
95
- name: rake
96
87
  prerelease: false
97
- requirement: &id006 !ruby/object:Gem::Requirement
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
98
97
  none: false
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- hash: 3
103
- segments:
104
- - 0
105
- version: "0"
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
106
102
  type: :development
107
- version_requirements: *id006
108
- - !ruby/object:Gem::Dependency
109
- name: pry
110
103
  prerelease: false
111
- requirement: &id007 !ruby/object:Gem::Requirement
104
+ version_requirements: !ruby/object:Gem::Requirement
112
105
  none: false
113
- requirements:
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- hash: 3
117
- segments:
118
- - 0
119
- version: "0"
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'
120
118
  type: :development
121
- version_requirements: *id007
122
- - !ruby/object:Gem::Dependency
123
- name: rspec
124
119
  prerelease: false
125
- requirement: &id008 !ruby/object:Gem::Requirement
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
126
129
  none: false
127
- requirements:
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- hash: 3
131
- segments:
132
- - 0
133
- version: "0"
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
134
  type: :development
135
- version_requirements: *id008
136
- - !ruby/object:Gem::Dependency
137
- name: webmock
138
135
  prerelease: false
139
- requirement: &id009 !ruby/object:Gem::Requirement
136
+ version_requirements: !ruby/object:Gem::Requirement
140
137
  none: false
141
- requirements:
142
- - - ">="
143
- - !ruby/object:Gem::Version
144
- hash: 3
145
- segments:
146
- - 0
147
- version: "0"
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'
148
150
  type: :development
149
- version_requirements: *id009
150
- - !ruby/object:Gem::Dependency
151
- name: vcr
152
151
  prerelease: false
153
- requirement: &id010 !ruby/object:Gem::Requirement
152
+ version_requirements: !ruby/object:Gem::Requirement
154
153
  none: false
155
- requirements:
156
- - - ">="
157
- - !ruby/object:Gem::Version
158
- hash: 3
159
- segments:
160
- - 0
161
- version: "0"
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'
162
166
  type: :development
163
- version_requirements: *id010
164
- - !ruby/object:Gem::Dependency
165
- name: simplecov
166
167
  prerelease: false
167
- requirement: &id011 !ruby/object:Gem::Requirement
168
+ version_requirements: !ruby/object:Gem::Requirement
168
169
  none: false
169
- requirements:
170
- - - ">="
171
- - !ruby/object:Gem::Version
172
- hash: 3
173
- segments:
174
- - 0
175
- version: "0"
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'
176
182
  type: :development
177
- version_requirements: *id011
178
- - !ruby/object:Gem::Dependency
179
- name: yard
180
183
  prerelease: false
181
- requirement: &id012 !ruby/object:Gem::Requirement
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
182
193
  none: false
183
- requirements:
184
- - - ">="
185
- - !ruby/object:Gem::Version
186
- hash: 3
187
- segments:
188
- - 0
189
- version: "0"
194
+ requirements:
195
+ - - ! '>='
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
190
198
  type: :development
191
- version_requirements: *id012
192
- - !ruby/object:Gem::Dependency
193
- name: maruku
194
199
  prerelease: false
195
- requirement: &id013 !ruby/object:Gem::Requirement
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
196
209
  none: false
197
- requirements:
198
- - - ">="
199
- - !ruby/object:Gem::Version
200
- hash: 3
201
- segments:
202
- - 0
203
- version: "0"
210
+ requirements:
211
+ - - ! '>='
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
204
214
  type: :development
205
- version_requirements: *id013
206
- description: " shuffler_fm wraps shuffler.fm's REST api on a thin layer of ruby. "
207
- email:
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:
208
224
  - mguinada@gmail.com
209
225
  executables: []
210
-
211
226
  extensions: []
212
-
213
227
  extra_rdoc_files: []
214
-
215
- files:
228
+ files:
216
229
  - .gitignore
217
230
  - .rspec
218
231
  - .travis.yml
219
232
  - .yardopts
233
+ - CHANGELOG.md
220
234
  - Gemfile
221
235
  - LICENSE
222
236
  - README.md
@@ -257,38 +271,29 @@ files:
257
271
  - spec/shufflerfm_spec.rb
258
272
  homepage: https://github.com/mguinada/shuffler_fm
259
273
  licenses: []
260
-
261
274
  post_install_message:
262
275
  rdoc_options: []
263
-
264
- require_paths:
276
+ require_paths:
265
277
  - lib
266
- required_ruby_version: !ruby/object:Gem::Requirement
278
+ required_ruby_version: !ruby/object:Gem::Requirement
267
279
  none: false
268
- requirements:
269
- - - ">="
270
- - !ruby/object:Gem::Version
271
- hash: 3
272
- segments:
273
- - 0
274
- version: "0"
275
- required_rubygems_version: !ruby/object:Gem::Requirement
280
+ requirements:
281
+ - - ! '>='
282
+ - !ruby/object:Gem::Version
283
+ version: '0'
284
+ required_rubygems_version: !ruby/object:Gem::Requirement
276
285
  none: false
277
- requirements:
278
- - - ">="
279
- - !ruby/object:Gem::Version
280
- hash: 3
281
- segments:
282
- - 0
283
- version: "0"
286
+ requirements:
287
+ - - ! '>='
288
+ - !ruby/object:Gem::Version
289
+ version: '0'
284
290
  requirements: []
285
-
286
291
  rubyforge_project:
287
- rubygems_version: 1.8.15
292
+ rubygems_version: 1.8.24
288
293
  signing_key:
289
294
  specification_version: 3
290
295
  summary: Ruby API wrapper for http://shuffler.fm
291
- test_files:
296
+ test_files:
292
297
  - spec/config.yml.sample
293
298
  - spec/fixtures/vcr_cassettes/api.yml
294
299
  - spec/fixtures/vcr_cassettes/artists.yml