This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Rdio deskop methods to DesktopBridge
- Loading branch information
Showing
4 changed files
with
125 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Rdio | ||
class DesktopBridge | ||
|
||
def apple_script(cmd) | ||
`osascript -e '#{cmd}'` | ||
end | ||
|
||
def tell_rdio(cmd) | ||
apple_script "tell app \"Rdio\" to #{cmd}" | ||
end | ||
|
||
def current_track | ||
tell_rdio('name of the current track').gsub(/\n/, '') | ||
end | ||
|
||
def current_artist | ||
tell_rdio('artist of the current track').gsub(/\n/, '') | ||
end | ||
|
||
def current_album | ||
tell_rdio('album of the current track').gsub(/\n/, '') | ||
end | ||
|
||
def now_playing(text=nil) | ||
text ||= "Now playing: %{track} / %{artist} / %{album}" | ||
text % { | ||
:artist => current_artist, | ||
:track => current_track, | ||
:album => current_album | ||
} | ||
end | ||
|
||
def set_volume(pct = 30) | ||
tell_rdio "set the sound volume to #{pct}" | ||
end | ||
|
||
def rdio_url(protocol = 'http') | ||
path = tell_rdio 'rdio url of the current track' | ||
"#{protocol}://www.rdio.com#{path}" | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require 'spec_helper' | ||
|
||
describe 'Rdio::DesktopBridge' do | ||
|
||
before do | ||
@bridge = Rdio::DesktopBridge.new | ||
end | ||
|
||
it "sends AppleScript to Rdio.app" do | ||
@bridge.should_receive(:apple_script). | ||
with("tell app \"Rdio\" to name of the current track") | ||
|
||
@bridge.tell_rdio("name of the current track") | ||
end | ||
|
||
it "gets the name of the current track" do | ||
@bridge.should_receive(:apple_script). | ||
with("tell app \"Rdio\" to name of the current track"). | ||
and_return("Hurt\n") | ||
|
||
track = @bridge.current_track | ||
expect(track).to eq('Hurt') | ||
end | ||
|
||
it "gets the name of the current artist" do | ||
@bridge.should_receive(:apple_script). | ||
with("tell app \"Rdio\" to artist of the current track"). | ||
and_return("Johnny Cash\n") | ||
|
||
artist = @bridge.current_artist | ||
expect(artist).to eq('Johnny Cash') | ||
end | ||
|
||
it "gets the name of the current album" do | ||
@bridge.should_receive(:apple_script). | ||
with("tell app \"Rdio\" to album of the current track"). | ||
and_return("The Man Comes Around\n") | ||
|
||
album = @bridge.current_album | ||
expect(album).to eq('The Man Comes Around') | ||
end | ||
|
||
context "displaying now playing info" do | ||
|
||
before do | ||
@bridge.stub(:current_track).and_return("Hurt") | ||
@bridge.stub(:current_artist).and_return("Johnny Cash") | ||
@bridge.stub(:current_album).and_return("The Man Comes Around") | ||
end | ||
|
||
it "displays track, artist, and album by default" do | ||
expect(@bridge.now_playing).to \ | ||
eq("Now playing: Hurt / Johnny Cash / The Man Comes Around") | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters