Class: Iknow::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/iknow/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/iknow/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(Iknow::Auth.consumer, options[:token], options[:secret])
  else
    raise ArgumentError.new('{:auth => "oauth_access_token", :secret => "oauth_access_token_secret"} or {:username "iknow_username", :password => "iknow_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/iknow/core/auth.rb', line 4

def auth_token
  @auth_token
end

#modeObject

Returns the value of attribute mode.



4
5
6
# File 'lib/iknow/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/iknow/core/auth.rb', line 27

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