Class: Rdio::RdioOAuth

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

Overview


Performs oob 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



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

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

    # Try to open using launchy, then if this doesn't work use
    # system open
    begin
      require 'rubygems'
      require 'launchy'
      Launchy.open url
    rescue Exception => e
      Rdio::logger.error e
      Rdio::logger.info 'Install the \'launchy\' gem to avoid this error'
      Rdio::logger.info 'Trying system \'open\''
      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.



21
22
23
# File 'lib/rdio/oauth.rb', line 21

def get_pin
  @get_pin
end

#keyObject

Returns the value of attribute key.



13
14
15
# File 'lib/rdio/oauth.rb', line 13

def key
  @key
end

#secretObject

Returns the value of attribute secret.



13
14
15
# File 'lib/rdio/oauth.rb', line 13

def secret
  @secret
end

Instance Method Details

#access_token(requires_auth = false) ⇒ Object

boolean -> AccessToken

Returns an appropriate oob access token. If requires_auth is true we'll return one needed for authenticated requests. Otherwise (default), we'll return one needed for unauthenticated requests.



58
59
60
# File 'lib/rdio/oauth.rb', line 58

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