]>
git.r.bdr.sh - rbdr/lyricli.rb/blob - lib/lyricli/sources/rdio.rb
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 = Configuration
. instance
16 unless @config [ "rdio_auth_token" ] && !
@config [ "rdio_auth_token" ]. empty
?
21 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."
26 # Instantiates everything it needs to run.
29 @config = Configuration
. instance
30 @rdio = ::Rdio::SimpleRdio . new ([ @config [ "rdio_key" ], @config [ "rdio_secret" ]], @config [ "rdio_auth_token" ])
33 # The current_track method should return the name of the current
35 # @return [Hash] A hash containing the current `:song` and `:artist`.
37 response
= @rdio . call ( 'currentUser' , { 'extras' => 'lastSongPlayed' })
38 artist
= response
[ "result" ][ "lastSongPlayed" ][ "artist" ]
39 song
= response
[ "result" ][ "lastSongPlayed" ][ "name" ]
40 { artist
: artist
, song
: song
}
43 # The reset method resets any configurations it may have
45 @config = Configuration
. instance
46 @config . delete ( "rdio_auth_token" )
49 # Signs in to rdio with our credentials and requests access for a new auth
51 def self . create_auth_token
52 rdio
= ::Rdio::SimpleRdio . new ([ @config [ "rdio_key" ], @config [ "rdio_secret" ]], @config [ "rdio_auth_token" ])
54 # Request Authorization
55 puts
"Follow this URL to authorize lyricli:"
56 auth_url
= rdio
. begin_authentication ( 'oob' )
58 ::Launchy . open ( auth_url
)
60 # Request Code, Obtain Token
61 print
"Please type the authorization code: "
62 auth_code
= gets
. chomp
63 token
= rdio
. complete_authentication ( auth_code
)
65 @config [ "rdio_auth_token" ] = token