Class: Smartfm::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/smartfm/core/auth.rb

Defined Under Namespace

Classes: Basic

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Auth

Returns a new instance of Auth.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/smartfm/core/auth.rb', line 15

def initialize(options = {})
  if options[:username] && options[:password]
    @mode = :basic_auth
    @auth_token = Basic.new(options[:username], options[:password])
  elsif options[:token] && options[:secret]
    @mode = :oauth
    @auth_token = OAuth::AccessToken.new(Smartfm::Auth.consumer, options[:token], options[:secret])
  else
    raise ArgumentError.new('{:auth => "oauth_access_token", :secret => "oauth_access_token_secret"} or {:username "smartfm_username", :password => "smartfm_password"} is needed')
  end
end

Instance Attribute Details

#auth_tokenObject Also known as: account

Returns the value of attribute auth_token.



4
5
6
# File 'lib/smartfm/core/auth.rb', line 4

def auth_token
  @auth_token
end

#modeObject

Returns the value of attribute mode.



4
5
6
# File 'lib/smartfm/core/auth.rb', line 4

def mode
  @mode
end

Class Method Details

.consumerObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/smartfm/core/auth.rb', line 27

def self.consumer
  @@consumer ||= OAuth::Consumer.new(
    Smartfm::Config.oauth_consumer_key,
    Smartfm::Config.oauth_consumer_secret,
    :http_method   => Smartfm::Config.oauth_http_method,
    :scheme        => Smartfm::Config.oauth_scheme,
    :site          => Smartfm::Config.api_base_url,
    :authorize_url => "#{Smartfm::Config.base_url}/oauth/authorize"
  )
end