Permalink
Browse files

Snag track

  • Loading branch information...
pengwynn committed Dec 27, 2012
1 parent 9d2892f commit c77d190243dade03a5fc9459d5cad0e7eedf0ae8
Showing with 46 additions and 0 deletions.
  1. +24 −0 lib/rdio.rb
  2. +22 −0 spec/rdio_spec.rb
View
@@ -86,6 +86,18 @@ def self.rdio_url
"http://www.rdio.com#{path}"
end
+ def self.current_track_key
+ data = api.call 'getObjectFromUrl', { :url => rdio_url }
+
+ data['result']['key']
+ end
+
+ def self.add_to_collection(tracks)
+ tracks = Array(tracks)
+
+ api.call 'addToCollection', { :keys => tracks.join(',') }
+ end
+
config_file '.rdio'
flag :consumer_key
@@ -222,6 +234,18 @@ def self.rdio_url
end
end
+ desc 'Add the current track or album to your collection'
+ command :snag do |c|
+ c.action do |global_options,options,args|
+ case args.shift
+ when 'album'
+ say 'Not implemented'
+ when nil
+ add_to_collection current_track_key
+ end
+ end
+ end
+
pre do |global,command,options,args|
# Pre logic here
# Return true to proceed; false to abourt and not call the
View
@@ -65,4 +65,26 @@
Rdio.run ["current", %Q(Now rocking %{track} by %{artist} from the album %{album})]
end
+ context "when authenticated" do
+ before do
+ config = {
+ :consumer_key => 'fup94efx5qgb2uunev7dsdyt',
+ :consumer_secret => 'YdvEwYJsUj5w',
+ :access_key => 'fczfuy25vf83bzz35hw6p5pc8ft5ur6wsb8u5dcqa5zwbzbwrvfzbudpnwx2b3nz',
+ :access_secret => 'exyNUP88Ur'
+ }
+ File.open('tmp/fakehome/.rdio', 'w') do |out|
+ YAML.dump(config, out)
+ end
+ end
+
+ it "snags the currently playing track to your collection" do
+ Rdio.stub(:current_track_key).and_return('t12345')
+ Api.any_instance.should_receive(:call).
+ with('addToCollection', {:keys => 't12345'})
+
+ Rdio.run ['snag']
+ end
+ end
+
end

0 comments on commit c77d190

Please sign in to comment.