Permalink
Browse files

Adds lyrics command

  • Loading branch information...
1 parent d3bca7a commit fb05c0ec3bc2cb278b7f706eebe9d406d27f8e45 @pengwynn committed Jan 31, 2013
Showing with 207 additions and 0 deletions.
  1. +5 −0 Gemfile.lock
  2. +21 −0 lib/rdio.rb
  3. +1 −0 rdio-cli.gemspec
  4. +45 −0 spec/fixtures/hurt.txt
  5. +32 −0 spec/fixtures/layla.txt
  6. +33 −0 spec/rdio_spec.rb
  7. +70 −0 spec/spec_helper.rb
View
@@ -10,6 +10,7 @@ GEM
remote: http://rubygems.org/
specs:
addressable (2.3.2)
+ crack (0.3.1)
diff-lcs (1.1.3)
gli (2.5.2)
highline (1.6.15)
@@ -27,6 +28,9 @@ GEM
rspec-expectations (2.12.0)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.0)
+ webmock (1.8.7)
+ addressable (>= 2.2.7)
+ crack (>= 0.1.7)
PLATFORMS
ruby
@@ -37,3 +41,4 @@ DEPENDENCIES
rdoc
rspec (~> 2.12.0)
rspec-mocks (~> 2.12.0)
+ webmock
View
@@ -37,6 +37,15 @@ def self.authorize_api
say "You're all set. see `rdio help` for usage"
end
+ def self.lyrics_for(artist, title)
+ uri = URI('http://makeitpersonal.co/lyrics')
+ params = { :artist => artist, :title => title }
+ uri.query = URI.encode_www_form(params)
+
+ res = Net::HTTP.get_response(uri)
+ return res.body
+ end
+
def self.rdio_config
{
:consumer_key => @consumer_key,
@@ -204,6 +213,18 @@ def self.add_to_collection(tracks)
end
end
+ skips_pre
+ desc 'Show lyrics for a track'
+ command :lyrics do |c|
+ c.flag :artist
+ c.flag :title
+ c.action do |global_options,options,args|
+ artist = options[:artist] || bridge.current_artist
+ title = options[:title] || bridge.current_track
+ say lyrics_for(artist, title)
+ end
+ end
+
### Authenticated methods
desc 'Show the current Rdio user'
View
@@ -23,5 +23,6 @@ spec = Gem::Specification.new do |s|
s.add_development_dependency('rdoc')
s.add_development_dependency('rspec', '~> 2.12.0')
s.add_development_dependency('rspec-mocks', '~> 2.12.0')
+ s.add_development_dependency 'webmock'
s.add_runtime_dependency('gli','2.5.2')
end
View
@@ -0,0 +1,45 @@
+I hurt myself today
+To see if I still feel
+I focus on the pain
+The only thing that's real
+
+The needle tears a hole
+The old familiar sting
+Try to kill it all away
+But I remember everything
+
+What have I become
+My sweetest friend
+Everyone I know
+Goes away in the end
+
+And you could have it all
+My empire of dirt
+I will let you down
+I will make you hurt
+
+I wear this crown of thorns
+Upon my liars chair
+Full of broken thoughts
+I cannot repair
+
+Beneath the stains of time
+The feelings disappear
+You are someone else
+I am still right here
+
+What have I become
+My sweetest friend
+Everyone I know
+Goes away in the end
+
+And you could have it all
+My empire of dirt
+I will let you down
+I will make you hurt
+
+If I could start again
+A million miles away
+I would keep myself
+I would find a way
+
View
@@ -0,0 +1,32 @@
+
+What will you do when you get lonely
+And nobody's waiting by your side?
+You've been running and hiding much too long
+You know, it's just your foolish pride
+
+Layla, you got me on my knees
+Layla, I'm begging darling, please
+Layla, darling, won't you ease my worried mind?
+
+I tried to give you consolation
+When your old man had let you down
+Like a fool, I fell in love with you
+You turned my whole world upside down
+
+Layla, you got me on my knees
+Layla, I'm begging darling, please
+Layla, darling, won't you ease my worried mind?
+
+Let's make the best of the situation
+Before I finally go insane
+Please don't say "We'll never find a way"
+And tell me all my love's in vain
+
+Layla, you got me on my knees
+Layla, I'm begging darling, please
+Layla, darling, won't you ease my worried mind?
+
+Layla, you got me on my knees
+Layla, I'm begging darling, please
+Layla, darling, won't you ease my worried mind?
+
View
@@ -149,4 +149,37 @@
end
end
+ context "lyrics" do
+
+ before do
+ Rdio::DesktopBridge.any_instance.stub(:current_artist).and_return 'Johnny Cash'
+ Rdio::DesktopBridge.any_instance.stub(:current_track).and_return 'Hurt'
+ end
+
+ it "looks up lyrics for current track" do
+ stub = stub_get("http://makeitpersonal.co/lyrics?artist=Johnny%20Cash&title=Hurt").
+ to_return(:body => fixture('hurt.txt'))
+
+ HighLine.any_instance.should_receive(:say)
+ Rdio.run %w(lyrics)
+
+ expect(stub).to have_been_made
+ end
+
+ it "looks up lyrics for any artist and title" do
+ stub = stub_get("http://makeitpersonal.co/lyrics?artist=Eric%20Clapton&title=Layla").
+ to_return(:body => fixture('layla.txt'))
+
+ HighLine.any_instance.should_receive(:say)
+ Rdio.run [
+ 'lyrics',
+ '--artist=Eric Clapton',
+ '--title=Layla'
+ ]
+
+ expect(stub).to have_been_made
+ end
+
+ end
+
end
View
@@ -18,3 +18,73 @@
require 'rdio'
require 'rspec/mocks'
+require 'webmock/rspec'
+
+def a_delete(url)
+ a_request(:delete, rdio_url(url))
+end
+
+def a_get(url)
+ a_request(:get, rdio_url(url))
+end
+
+def a_patch(url)
+ a_request(:patch, rdio_url(url))
+end
+
+def a_post(url)
+ a_request(:post, rdio_url(url))
+end
+
+def a_put(url)
+ a_request(:put, rdio_url(url))
+end
+
+def stub_delete(url)
+ stub_request(:delete, rdio_url(url))
+end
+
+def stub_get(url)
+ stub_request(:get, rdio_url(url))
+end
+
+def stub_head(url)
+ stub_request(:head, rdio_url(url))
+end
+
+def stub_patch(url)
+ stub_request(:patch, rdio_url(url))
+end
+
+def stub_post(url)
+ stub_request(:post, rdio_url(url))
+end
+
+def stub_put(url)
+ stub_request(:put, rdio_url(url))
+end
+
+def fixture_path
+ File.expand_path("../fixtures", __FILE__)
+end
+
+def fixture(file)
+ File.new(fixture_path + '/' + file)
+end
+
+def json_response(file)
+ {
+ :body => fixture(file),
+ :headers => {
+ :content_type => 'application/json; charset=utf-8'
+ }
+ }
+end
+
+def rdio_url(url)
+ if url =~ /^http/
+ url
+ else
+ "https://api.rdio.com#{url}"
+ end
+end

0 comments on commit fb05c0e

Please sign in to comment.