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.
27 28 29 30 31 |
# File 'lib/lyricli/sources/rdio.rb', line 27 def initialize @name = 'rdio' @config = 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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/lyricli/sources/rdio.rb', line 51 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 21 22 23 24 |
# File 'lib/lyricli/sources/rdio.rb', line 13 def self.enable # Validation Code @config = Configuration.instance unless @config["rdio_auth_token"] && !@config["rdio_auth_token"].empty? create_auth_token end puts "***" 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." puts "***" end |
+ (Object) reset
The reset method resets any configurations it may have
44 45 46 47 |
# File 'lib/lyricli/sources/rdio.rb', line 44 def self.reset @config = Configuration.instance @config.delete("rdio_auth_token") end |
Instance Method Details
- (Hash) current_track
The current_track method should return the name of the current artist and song.
36 37 38 39 40 41 |
# File 'lib/lyricli/sources/rdio.rb', line 36 def current_track response = @rdio.call('currentUser', {'extras' => 'lastSongPlayed'}) artist = response["result"]["lastSongPlayed"]["artist"] song = response["result"]["lastSongPlayed"]["name"] {artist: artist, song: song} end |