]>
git.r.bdr.sh - rbdr/lyricli.rb/blob - lib/lyricli/sources/rdio.rb
afb736d606069e9812092031c442fa86a39754a2
5 # Returns the name of the source, in snake_case
10 # The enable method should run all of the tasks needed to validate
11 # the source. In the case of Rdio it has to authenticate with OAuth.
14 @config = Lyricli
::Config
15 unless @config[:rdio_auth_token] && !
@config[:rdio_auth_token].empty
?
21 # Instantiates everything it needs to run.
23 @rdio = Rdio
::SimpleRdio.new([@config[:rdio_key], @config[:rdio_secret]], @config[:rdio_auth_token])
26 # The current_track method should return the name of the current
28 # @return [Hash] A hash containing the current `:song` and `:artist`.
29 def self.current_track
30 u
= @rdio.call('currentUser', {'extras' => 'lastSongPlayed'})
31 artist
= u
["result"]["lastSongPlayed"]["artist"]
32 song
= u
["result"]["lastSongPlayed"]["name"]
33 {artist
: artist
, song
: song
}
36 # The reset method resets any configurations it may have
43 # Signs in to rdio with our credentials and requests access for a new auth
46 rdio
= Rdio
::SimpleRdio.new([@config])
48 # Request Authorization
49 puts
"Follow this URL to authorize lyricli:"
50 auth_url
= rdio
.begin_authentication('oob')
52 Launchy
.open(auth_url
)
54 # Request Code, Obtain Token
55 print
"Please type the authorization code: "
56 auth_code
= gets
.chomp
57 token
= rdio
.complete_authentication(auth_code
)
59 @config[:rdio_auth_token] = token