Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Feature snag album #4

Merged
merged 3 commits into from
Dec 31, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
15 changes: 13 additions & 2 deletions lib/rdio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 => rdio_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)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions spec/rdio_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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