Permalink
Browse files

Merge pull request #4 from EtienneLem/feature-snag-album

Feature snag album
  • Loading branch information...
2 parents 7ba73f3 + 9435fd3 commit d3bca7a6ffcce8f8c7f0f95e08e8dfb950e49540 @pengwynn committed Dec 31, 2012
Showing with 29 additions and 3 deletions.
  1. +1 −1 README.md
  2. +13 −2 lib/rdio.rb
  3. +15 −0 spec/rdio_spec.rb
View
@@ -66,7 +66,7 @@ COMMANDS
## TODO
* `[✓]` <del>Snag current track to collection</del>
-* `[ ]` Snag current album to collection
+* `[]` <del>Snag current album to collection</del>
* `[ ]` Create a playlist
* `[ ]` Follow a user
* `[ ]` Tail a user?
View
@@ -53,12 +53,23 @@ def self.write_config
end
end
+ def self.current_user
+ @current_user ||= api.call('currentUser', :extras => 'lastSongPlayed')['result']
+ end
+
def self.current_track_key
data = api.call 'getObjectFromUrl', { :url => bridge.current_url }
data['result']['key']
end
+ def self.current_album_track_keys
+ current_album_url = current_user['lastSongPlayed']['albumUrl']
+ data = api.call 'getObjectFromUrl', { :url => current_album_url }
+
+ data['result']['trackKeys']
+ end
+
def self.add_to_collection(tracks)
tracks = Array(tracks)
@@ -198,7 +209,7 @@ def self.add_to_collection(tracks)
desc 'Show the current Rdio user'
command :user do |c|
c.action do |global_options,options,args|
- user = api.call('currentUser')['result']
+ user = current_user
say "#{user['firstName']} #{user['lastName']}"
end
end
@@ -208,7 +219,7 @@ def self.add_to_collection(tracks)
c.action do |global_options,options,args|
case args.shift
when 'album'
- say 'Not implemented'
+ add_to_collection current_album_track_keys
when nil
add_to_collection current_track_key
end
View
@@ -132,6 +132,21 @@
'snag'
]
end
+
+ it "snags the currently playing album tracks to your collection" do
+ Rdio.stub(:current_album_track_keys).and_return(['t12345', 't23456', 't34567'])
+ Api.any_instance.should_receive(:call).
+ with('addToCollection', {:keys => 't12345,t23456,t34567'})
+
+ Rdio.run [
+ '--consumer_key=fup94efx5qgb2uunev7dsdyt',
+ '--consumer_secret=YdvEwYJsUj5w',
+ '--access_token=fczfuy25vf83bzz35hw6p5pc8ft5ur6wsb8u5dcqa5zwbzbwrvfzbudpnwx2b3nz',
+ '--access_secret=exyNUP88Ur',
+ 'snag',
+ 'album'
+ ]
+ end
end
end

0 comments on commit d3bca7a

Please sign in to comment.