Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Implement and test Webhallon::Tracks

  • Loading branch information...
commit 84f6f96271dadc254650e26033bd7e05802ebd00 1 parent 27fa542
Linus Oleander authored
4 lib/webhallon/client.rb
@@ -10,5 +10,9 @@ def connected?
10 10 def playlists
11 11 @_playlists ||= Webhallon::Playlists.new(server)
12 12 end
  13 +
  14 + def tracks
  15 + @_tracks ||= Webhallon::Tracks.new(server)
  16 + end
13 17 end
14 18 end
18 lib/webhallon/tracks.rb
... ... @@ -0,0 +1,18 @@
  1 +module Webhallon
  2 + class Tracks < Webhallon::Base
  3 + #
  4 + # @args[:playlist] String Spotify Playlist
  5 + # @args[:tracks] Array<String> A list of tracks
  6 + # @args[:index] Integer Index position for tracks
  7 + # @return Webhallon::Playlist
  8 + #
  9 + def add(args)
  10 + response = fetch("/#{args.fetch(:playlist)}/tracks", :post, {
  11 + tracks: args.fetch(:tracks),
  12 + index: args[:index] || 0
  13 + })
  14 +
  15 + Webhallon::Playlist.new(response)
  16 + end
  17 + end
  18 +end
1  lib/webhallon_wrapper.rb
@@ -3,4 +3,5 @@
3 3 require "webhallon/base"
4 4 require "webhallon/playlists"
5 5 require "webhallon/playlist"
  6 +require "webhallon/tracks"
6 7 require "webhallon/client"
129 spec/fixtures/vcr_cassettes/client.yml
... ... @@ -1,6 +1,54 @@
1 1 ---
2 2 http_interactions:
3 3 - request:
  4 + method: post
  5 + uri: http://localhost:9292/spotify:user:radiofy.se:playlist:0wVa3u1ckpCraTnNw9dPCC
  6 + body:
  7 + encoding: ASCII-8BIT
  8 + string: tracks[]=spotify%3Atrack%3A0FRelX0g1nNDFt6nvtiakE&index=0
  9 + headers:
  10 + Accept:
  11 + - ! '*/*; q=0.5, application/xml'
  12 + Accept-Encoding:
  13 + - gzip, deflate
  14 + Content-Length:
  15 + - '57'
  16 + Content-Type:
  17 + - application/x-www-form-urlencoded
  18 + User-Agent:
  19 + - Ruby
  20 + response:
  21 + status:
  22 + code: 404
  23 + message: ! 'Not Found '
  24 + headers:
  25 + X-Frame-Options:
  26 + - sameorigin
  27 + X-Xss-Protection:
  28 + - 1; mode=block
  29 + X-Cascade:
  30 + - pass
  31 + Content-Type:
  32 + - text/html;charset=utf-8
  33 + Content-Length:
  34 + - '492'
  35 + Server:
  36 + - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
  37 + Date:
  38 + - Tue, 05 Jun 2012 00:23:42 GMT
  39 + Connection:
  40 + - Keep-Alive
  41 + body:
  42 + encoding: US-ASCII
  43 + string: ! "<!DOCTYPE html>\n<html>\n<head>\n <style type=\"text/css\">\n body
  44 + { text-align:center;font-family:helvetica,arial;font-size:22px;\n color:#888;margin:20px}\n
  45 + \ #c {margin:0 auto;width:500px;text-align:left}\n </style>\n</head>\n<body>\n
  46 + \ <h2>Sinatra doesn&rsquo;t know this ditty.</h2>\n <img src='http://localhost:9292/__sinatra__/404.png'>\n
  47 + \ <div id=\"c\">\n Try this:\n <pre>post '/spotify:user:radiofy.se:playlist:0wVa3u1ckpCraTnNw9dPCC'
  48 + do\n \"Hello World\"\nend</pre>\n </div>\n</body>\n</html>\n"
  49 + http_version: !!null
  50 + recorded_at: Tue, 05 Jun 2012 00:23:42 GMT
  51 +- request:
4 52 method: get
5 53 uri: http://localhost:9292/connected
6 54 body:
@@ -33,14 +81,14 @@ http_interactions:
33 81 Server:
34 82 - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
35 83 Date:
36   - - Tue, 05 Jun 2012 00:14:38 GMT
  84 + - Tue, 05 Jun 2012 00:25:40 GMT
37 85 Connection:
38 86 - Keep-Alive
39 87 body:
40 88 encoding: US-ASCII
41 89 string: ! '{"connected":true}'
42 90 http_version: !!null
43   - recorded_at: Tue, 05 Jun 2012 00:14:38 GMT
  91 + recorded_at: Tue, 05 Jun 2012 00:25:40 GMT
44 92 - request:
45 93 method: post
46 94 uri: http://localhost:9292/
@@ -74,14 +122,14 @@ http_interactions:
74 122 Server:
75 123 - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
76 124 Date:
77   - - Tue, 05 Jun 2012 00:14:40 GMT
  125 + - Tue, 05 Jun 2012 00:25:43 GMT
78 126 Connection:
79 127 - Keep-Alive
80 128 body:
81 129 encoding: US-ASCII
82   - string: ! '{"name":"This is a name","link":"spotify:user:radiofy.se:playlist:6cJJjSDQijnfMloutp6t5V","length":0,"tracks":[],"collaborative":true}'
  130 + string: ! '{"name":"This is a name","link":"spotify:user:radiofy.se:playlist:3PHDF3VUrWqz6NGqCaqhtl","length":0,"tracks":[],"collaborative":true}'
83 131 http_version: !!null
84   - recorded_at: Tue, 05 Jun 2012 00:14:40 GMT
  132 + recorded_at: Tue, 05 Jun 2012 00:25:43 GMT
85 133 - request:
86 134 method: post
87 135 uri: http://localhost:9292/
@@ -115,14 +163,55 @@ http_interactions:
115 163 Server:
116 164 - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
117 165 Date:
118   - - Tue, 05 Jun 2012 00:14:42 GMT
  166 + - Tue, 05 Jun 2012 00:25:43 GMT
  167 + Connection:
  168 + - Keep-Alive
  169 + body:
  170 + encoding: US-ASCII
  171 + string: ! '{"name":"This is a name","link":"spotify:user:radiofy.se:playlist:0akkl1Wec0qcR78ITXuKjf","length":0,"tracks":[],"collaborative":false}'
  172 + http_version: !!null
  173 + recorded_at: Tue, 05 Jun 2012 00:25:43 GMT
  174 +- request:
  175 + method: put
  176 + uri: http://localhost:9292/spotify:user:radiofy.se:playlist:0wVa3u1ckpCraTnNw9dPCC
  177 + body:
  178 + encoding: ASCII-8BIT
  179 + string: name=0723ae17be65ea04a9edf1bc217f0363
  180 + headers:
  181 + Accept:
  182 + - ! '*/*; q=0.5, application/xml'
  183 + Accept-Encoding:
  184 + - gzip, deflate
  185 + Content-Length:
  186 + - '37'
  187 + Content-Type:
  188 + - application/x-www-form-urlencoded
  189 + User-Agent:
  190 + - Ruby
  191 + response:
  192 + status:
  193 + code: 200
  194 + message: ! 'OK '
  195 + headers:
  196 + X-Frame-Options:
  197 + - sameorigin
  198 + X-Xss-Protection:
  199 + - 1; mode=block
  200 + Content-Type:
  201 + - application/json; charset=utf-8
  202 + Content-Length:
  203 + - '230'
  204 + Server:
  205 + - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
  206 + Date:
  207 + - Tue, 05 Jun 2012 00:25:44 GMT
119 208 Connection:
120 209 - Keep-Alive
121 210 body:
122 211 encoding: US-ASCII
123   - string: ! '{"name":"This is a name","link":"spotify:user:radiofy.se:playlist:2JeHX0hyXzN6ehnMjZ0d3K","length":0,"tracks":[],"collaborative":false}'
  212 + string: ! '{"name":"0723ae17be65ea04a9edf1bc217f0363","link":"spotify:user:radiofy.se:playlist:0wVa3u1ckpCraTnNw9dPCC","length":2,"tracks":["spotify:track:0FRelX0g1nNDFt6nvtiakE","spotify:track:0FRelX0g1nNDFt6nvtiakE"],"collaborative":false}'
124 213 http_version: !!null
125   - recorded_at: Tue, 05 Jun 2012 00:14:42 GMT
  214 + recorded_at: Tue, 05 Jun 2012 00:25:44 GMT
126 215 - request:
127 216 method: get
128 217 uri: http://localhost:9292/spotify:user:radiofy.se:playlist:0wVa3u1ckpCraTnNw9dPCC
@@ -152,31 +241,31 @@ http_interactions:
152 241 Content-Type:
153 242 - application/json; charset=utf-8
154 243 Content-Length:
155   - - '153'
  244 + - '230'
156 245 Server:
157 246 - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
158 247 Date:
159   - - Tue, 05 Jun 2012 00:14:42 GMT
  248 + - Tue, 05 Jun 2012 00:25:44 GMT
160 249 Connection:
161 250 - Keep-Alive
162 251 body:
163 252 encoding: US-ASCII
164   - string: ! '{"name":"619a26ffb707fff99c42cc93bd99f70d","link":"spotify:user:radiofy.se:playlist:0wVa3u1ckpCraTnNw9dPCC","length":0,"tracks":[],"collaborative":false}'
  253 + string: ! '{"name":"0723ae17be65ea04a9edf1bc217f0363","link":"spotify:user:radiofy.se:playlist:0wVa3u1ckpCraTnNw9dPCC","length":2,"tracks":["spotify:track:0FRelX0g1nNDFt6nvtiakE","spotify:track:0FRelX0g1nNDFt6nvtiakE"],"collaborative":false}'
165 254 http_version: !!null
166   - recorded_at: Tue, 05 Jun 2012 00:14:42 GMT
  255 + recorded_at: Tue, 05 Jun 2012 00:25:44 GMT
167 256 - request:
168   - method: put
169   - uri: http://localhost:9292/spotify:user:radiofy.se:playlist:0wVa3u1ckpCraTnNw9dPCC
  257 + method: post
  258 + uri: http://localhost:9292/spotify:user:radiofy.se:playlist:0wVa3u1ckpCraTnNw9dPCC/tracks
170 259 body:
171 260 encoding: ASCII-8BIT
172   - string: name=639ecee5f40327e64638e08b015a374b
  261 + string: tracks[]=spotify%3Atrack%3A0FRelX0g1nNDFt6nvtiakE&index=0
173 262 headers:
174 263 Accept:
175 264 - ! '*/*; q=0.5, application/xml'
176 265 Accept-Encoding:
177 266 - gzip, deflate
178 267 Content-Length:
179   - - '37'
  268 + - '57'
180 269 Content-Type:
181 270 - application/x-www-form-urlencoded
182 271 User-Agent:
@@ -193,16 +282,16 @@ http_interactions:
193 282 Content-Type:
194 283 - application/json; charset=utf-8
195 284 Content-Length:
196   - - '153'
  285 + - '269'
197 286 Server:
198 287 - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
199 288 Date:
200   - - Tue, 05 Jun 2012 00:14:42 GMT
  289 + - Tue, 05 Jun 2012 00:25:44 GMT
201 290 Connection:
202 291 - Keep-Alive
203 292 body:
204 293 encoding: US-ASCII
205   - string: ! '{"name":"639ecee5f40327e64638e08b015a374b","link":"spotify:user:radiofy.se:playlist:0wVa3u1ckpCraTnNw9dPCC","length":0,"tracks":[],"collaborative":false}'
  294 + string: ! '{"name":"0723ae17be65ea04a9edf1bc217f0363","link":"spotify:user:radiofy.se:playlist:0wVa3u1ckpCraTnNw9dPCC","length":3,"tracks":["spotify:track:0FRelX0g1nNDFt6nvtiakE","spotify:track:0FRelX0g1nNDFt6nvtiakE","spotify:track:0FRelX0g1nNDFt6nvtiakE"],"collaborative":false}'
206 295 http_version: !!null
207   - recorded_at: Tue, 05 Jun 2012 00:14:42 GMT
  296 + recorded_at: Tue, 05 Jun 2012 00:25:44 GMT
208 297 recorded_with: VCR 2.2.0
4 spec/spec_helper.rb
@@ -13,8 +13,8 @@
13 13 c.cassette_library_dir = "spec/fixtures/vcr_cassettes"
14 14 c.hook_into :webmock
15 15 c.default_cassette_options = {
16   - record: :new_episodes
17   - # record: :all
  16 + # record: :new_episodes
  17 + record: :all
18 18 }
19 19 c.allow_http_connections_when_no_cassette = false
20 20 end
14 spec/webhallon_wrapper_spec.rb
@@ -10,6 +10,7 @@ def validate(playlist)
10 10 describe Webhallon::Client do
11 11 let(:socket) { Webhallon::Client.new("http://localhost:9292") }
12 12 let(:playlist) { "spotify:user:radiofy.se:playlist:0wVa3u1ckpCraTnNw9dPCC" }
  13 + let(:track) { "spotify:track:0FRelX0g1nNDFt6nvtiakE" }
13 14
14 15 use_vcr_cassette "client"
15 16
@@ -67,4 +68,17 @@ def validate(playlist)
67 68 validate(p)
68 69 end
69 70 end
  71 +
  72 + describe "add tracks" do
  73 + it "should be possible to add a track" do
  74 + playlist1 = socket.playlists.information(playlist)
  75 + playlist2 = socket.tracks.add({
  76 + playlist: playlist,
  77 + tracks: [track]
  78 + })
  79 +
  80 + playlist1.length.should eq(playlist2.length - 1)
  81 + validate(playlist2)
  82 + end
  83 + end
70 84 end

0 comments on commit 84f6f96

Please sign in to comment.
Something went wrong with that request. Please try again.