Sha256: 314fa78f1e03ce969be1d963ee4381cfae37ff8916051e159b438c4e2b7661ca

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

require 'oauth/consumer'

class Iknow::Auth
  attr_accessor :mode, :auth_token

  class Basic
    attr_reader :username, :password

    def initialize(username, password)
      @username = username
      @password = password
    end
  end

  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

  def self.consumer
    @@consumer ||= OAuth::Consumer.new(
      Iknow::Config.oauth_consumer_key,
      Iknow::Config.oauth_consumer_secret,
      :http_method   => :get,
      :schema        => :query_string,
      :site          => Iknow::Config.iknow_api_base_url,
      :authorize_url => "#{Iknow::Config.iknow_base_url}/oauth/authorize"
    )
  end

  alias_method :account, :auth_token
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
nov-iknow-0.1.1 lib/iknow/core/auth.rb
nov-iknow-0.2.0 lib/iknow/core/auth.rb
iknow-0.1.1 lib/iknow/core/auth.rb
iknow-0.2.0 lib/iknow/core/auth.rb