Class: Rdio::RdioOAuth

Inherits:
Object show all
Defined in:
lib/rdio/oauth.rb

Overview


Performs OAuth authentication based on a key and secret


Constant Summary collapse

SITE =
'http://api.rdio.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, secret) ⇒ RdioOAuth

Returns a new instance of RdioOAuth.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rdio/oauth.rb', line 21

def initialize(key,secret)
  @key = key
  @secret = secret
  @get_pin = lambda do |url|

    # Try to open using launchy, then if this doesn't work us open
    begin
      require 'rubygems'
      require 'launchy'
      Launchy.open url
    rescue Exception => e
      Rdio::log.error e
      Rdio::log.info 'Install the \'launchy\' gem to avoid this error'
      system 'open',url
    end
    
    oauth_verifier = nil
    while not oauth_verifier or oauth_verifier == ''
      print 'Enter the 4-digit PIN> '
      STDOUT.flush
      oauth_verifier = gets.strip
    end
    return oauth_verifier
  end
end

Instance Attribute Details

#get_pinObject

string -> string

Set this to allow a different way to enter the pin found for authorization. By default it will open a browser and repeatedly ask the user for input from the console.



19
20
21
# File 'lib/rdio/oauth.rb', line 19

def get_pin
  @get_pin
end

Instance Method Details

#access_token(requires_auth = false) ⇒ Object



47
48
49
# File 'lib/rdio/oauth.rb', line 47

def access_token(requires_auth=false)
  requires_auth ? access_token_auth : access_token_no_auth
end