Class: Lyricli::Sources::Rdio
- Inherits:
-
Object
- Object
- Lyricli::Sources::Rdio
- Defined in:
- lib/lyricli/sources/rdio.rb
Class Attribute Summary (collapse)
-
+ (Object) name
Returns the value of attribute name.
Class Method Summary (collapse)
-
+ (Object) create_auth_token
Signs in to rdio with our credentials and requests access for a new auth token.
-
+ (Object) enable
The enable method should run all of the tasks needed to validate the source.
-
+ (Object) reset
The reset method resets any configurations it may have.
Instance Method Summary (collapse)
-
- (Hash) current_track
The current_track method should return the name of the current artist and song.
-
- (Rdio) initialize
constructor
Instantiates everything it needs to run.
Constructor Details
- (Rdio) initialize
Instantiates everything it needs to run.
23 24 25 26 27 |
# File 'lib/lyricli/sources/rdio.rb', line 23 def initialize @name = 'rdio' @config = Lyricli::Configuration.instance @rdio = Rdio::SimpleRdio.new([@config["rdio_key"], @config["rdio_secret"]], @config["rdio_auth_token"]) end |
Class Attribute Details
+ (Object) name
Returns the value of attribute name
6 7 8 |
# File 'lib/lyricli/sources/rdio.rb', line 6 def name @name end |
Class Method Details
+ (Object) create_auth_token
Signs in to rdio with our credentials and requests access for a new auth token.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/lyricli/sources/rdio.rb', line 46 def self.create_auth_token @rdio = Rdio::SimpleRdio.new([@config["rdio_key"], @config["rdio_secret"]], @config["rdio_auth_token"]) # Request Authorization puts "Follow this URL to authorize lyricli:" auth_url = rdio.begin_authentication('oob') puts auth_url Launchy.open(auth_url) # Request Code, Obtain Token print "Please type the authorization code: " auth_code = gets.chomp token = rdio.complete_authentication(auth_code) @config["rdio_auth_token"] = token token end |
+ (Object) enable
The enable method should run all of the tasks needed to validate the source. In the case of Rdio it has to authenticate with OAuth.
13 14 15 16 17 18 19 20 |
# File 'lib/lyricli/sources/rdio.rb', line 13 def self.enable # Validation Code @config = Lyricli::Configuration.instance unless @config["rdio_auth_token"] && !@config["rdio_auth_token"].empty? create_auth_token end end |
+ (Object) reset
The reset method resets any configurations it may have
40 41 42 |
# File 'lib/lyricli/sources/rdio.rb', line 40 def self.reset # Reset Code end |
Instance Method Details
- (Hash) current_track
The current_track method should return the name of the current artist and song.
32 33 34 35 36 37 |
# File 'lib/lyricli/sources/rdio.rb', line 32 def current_track response = @rdio.call('currentUser', {'extras' => 'lastSongPlayed'}) artist = response["result"]["lastSongPlayed"]["artist"] song = response["result"]["lastSongPlayed"]["name"] {artist: artist, song: song} end |