]>
git.r.bdr.sh - rbdr/lyricli.rb/blob - lib/lyricli/sources/rdio.rb
83548b28af680c85f8794f50e4dc9f398ccb2b55
11 # The enable method should run all of the tasks needed to validate
12 # the source. In the case of Rdio it has to authenticate with OAuth.
15 @config = Lyricli
::Configuration.instance
16 unless @config["rdio_auth_token"] && !
@config["rdio_auth_token"].empty
?
22 # Instantiates everything it needs to run.
25 @config = Lyricli
::Configuration.instance
26 @rdio = Rdio
::SimpleRdio.new([@config["rdio_key"], @config["rdio_secret"]], @config["rdio_auth_token"])
29 # The current_track method should return the name of the current
31 # @return [Hash] A hash containing the current `:song` and `:artist`.
33 response
= @rdio.call('currentUser', {'extras' => 'lastSongPlayed'})
34 artist
= response
["result"]["lastSongPlayed"]["artist"]
35 song
= response
["result"]["lastSongPlayed"]["name"]
36 {artist
: artist
, song
: song
}
39 # The reset method resets any configurations it may have
44 # Signs in to rdio with our credentials and requests access for a new auth
46 def self.create_auth_token
47 @rdio = Rdio
::SimpleRdio.new([@config["rdio_key"], @config["rdio_secret"]], @config["rdio_auth_token"])
49 # Request Authorization
50 puts
"Follow this URL to authorize lyricli:"
51 auth_url
= rdio
.begin_authentication('oob')
53 Launchy
.open(auth_url
)
55 # Request Code, Obtain Token
56 print
"Please type the authorization code: "
57 auth_code
= gets
.chomp
58 token
= rdio
.complete_authentication(auth_code
)
60 @config["rdio_auth_token"] = token