X-Git-Url: https://git.r.bdr.sh/rbdr/lyricli.rb/blobdiff_plain/b8498f5c67d736e9724e124e85aa36a58648afef..823e558b5cd2ec219d0fc7226c54f2ee7ad807d2:/lib/lyricli/sources/rdio.rb diff --git a/lib/lyricli/sources/rdio.rb b/lib/lyricli/sources/rdio.rb index afb736d..83548b2 100644 --- a/lib/lyricli/sources/rdio.rb +++ b/lib/lyricli/sources/rdio.rb @@ -1,35 +1,38 @@ module Lyricli module Sources - module Rdio + class Rdio - # Returns the name of the source, in snake_case - def self.name - "rdio" + class << self + attr_accessor :name end + @name = "rdio" + # 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. def self.enable # Validation Code - @config = Lyricli::Config - unless @config[:rdio_auth_token] && !@config[:rdio_auth_token].empty? + @config = Lyricli::Configuration.instance + unless @config["rdio_auth_token"] && !@config["rdio_auth_token"].empty? create_auth_token end end # Instantiates everything it needs to run. - def self.start - @rdio = Rdio::SimpleRdio.new([@config[:rdio_key], @config[:rdio_secret]], @config[:rdio_auth_token]) + def initialize + @name = 'rdio' + @config = Lyricli::Configuration.instance + @rdio = Rdio::SimpleRdio.new([@config["rdio_key"], @config["rdio_secret"]], @config["rdio_auth_token"]) end # The current_track method should return the name of the current # artist and song. # @return [Hash] A hash containing the current `:song` and `:artist`. - def self.current_track - u = @rdio.call('currentUser', {'extras' => 'lastSongPlayed'}) - artist = u["result"]["lastSongPlayed"]["artist"] - song = u["result"]["lastSongPlayed"]["name"] + def current_track + response = @rdio.call('currentUser', {'extras' => 'lastSongPlayed'}) + artist = response["result"]["lastSongPlayed"]["artist"] + song = response["result"]["lastSongPlayed"]["name"] {artist: artist, song: song} end @@ -38,12 +41,10 @@ module Lyricli # Reset Code end - private - # Signs in to rdio with our credentials and requests access for a new auth # token. - def create_auth_token - rdio = Rdio::SimpleRdio.new([@config]) + 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:" @@ -56,7 +57,7 @@ module Lyricli auth_code = gets.chomp token = rdio.complete_authentication(auth_code) - @config[:rdio_auth_token] = token + @config["rdio_auth_token"] = token token end