]>
git.r.bdr.sh - rbdr/lyricli.rb/blob - lib/lyricli/sources/rdio.rb
d34795f512876d04b9c92641a7228f7278cb4c70
4 # This is the Source for rdio
13 # The enable method should run all of the tasks needed to validate
14 # the source. In the case of Rdio it has to authenticate with OAuth.
17 @config = Configuration
. instance
18 unless @config [ "rdio_auth_token" ] && !
@config [ "rdio_auth_token" ]. empty
?
23 puts
"Hello, rdio tends to be a bit aggressive and tends to have trouble with other sources. If you're having trouble, you can disable it temporarily. You will not have to reauthenticate."
28 # Instantiates everything it needs to run.
31 @config = Configuration
. instance
32 @rdio = ::Rdio::SimpleRdio . new ([ @config [ "rdio_key" ], @config [ "rdio_secret" ]], @config [ "rdio_auth_token" ])
35 # The current_track method should return the name of the current
38 # @return [Hash] A hash containing the current `:song` and `:artist`.
40 response
= @rdio . call ( 'currentUser' , { 'extras' => 'lastSongPlayed' })
41 artist
= response
[ "result" ][ "lastSongPlayed" ][ "artist" ]
42 song
= response
[ "result" ][ "lastSongPlayed" ][ "name" ]
43 { artist
: artist
, song
: song
}
46 # The reset method resets any configurations it may have
48 @config = Configuration
. instance
49 @config . delete ( "rdio_auth_token" )
52 # Signs in to rdio with our credentials and requests access for a new auth
54 def self . create_auth_token
55 rdio
= ::Rdio::SimpleRdio . new ([ @config [ "rdio_key" ], @config [ "rdio_secret" ]], @config [ "rdio_auth_token" ])
57 # Request Authorization
58 puts
"Follow this URL to authorize lyricli:"
59 auth_url
= rdio
. begin_authentication ( 'oob' )
61 ::Launchy . open ( auth_url
)
63 # Request Code, Obtain Token
64 print
"Please type the authorization code: "
65 auth_code
= gets
. chomp
66 token
= rdio
. complete_authentication ( auth_code
)
68 @config [ "rdio_auth_token" ] = token