class Kiik::Wallet::Client

Constants

ALLOWED_TYPES

Attributes

access_token[R]
email[R]
id[R]
name[R]
secret[R]

Public Class Methods

new(wallet,options) click to toggle source
# File lib/kiik/wallet/client.rb, line 14
def initialize(wallet,options)
    @id = options[:api_id]
    @name = options[:name]
    @email = options[:email]
    @secret = options[:api_secret]
    @access_token = options[:access_token]
    @wallet = wallet
    @base_uri = '/clients/#{id}'
end

Public Instance Methods

card() click to toggle source
# File lib/kiik/wallet/client.rb, line 87
def card
    @card ||= Kiik::Wallet::Creditcard.new(self)
end
client() click to toggle source
# File lib/kiik/wallet/client.rb, line 28
def client
    @wallet.client
end
create(type, options={},&block) click to toggle source
# File lib/kiik/wallet/client.rb, line 69
def create(type, options={},&block)
    allow(type,:create)

    token = options.delete(:token)
    case type
    when :user
        user.create(options,&block)
    when :creditcard
        card.create(token,options,&block)
    when :transaction
        transaction.create(token,options.delete(:credit_card),options,&block)
    end
end
detail(type,options={},&block) click to toggle source
# File lib/kiik/wallet/client.rb, line 41
def detail(type,options={},&block)
    allow(type,:detail)

    case type
    when :client
        request(:get, base_uri,{}, &block)
    when :creditcard
        token = options.delete(:token)
        card.detail(token,options,&block)
    end

end
list(type,options={},&block) click to toggle source
# File lib/kiik/wallet/client.rb, line 54
def list(type,options={},&block)
    allow(type,:list)

    case type
    when :creditcard
        token = options.delete(:token)
        card.list(token,&block)
    end

end
request(verb, uri, params = {}) { |parsed| ... } click to toggle source
# File lib/kiik/wallet/client.rb, line 95
def request(verb, uri, params = {}, &block)
    response = @wallet.client.request(verb, "/#{@wallet.version}#{uri}", request_params(params))

    if block_given?
        yield(response.parsed)
    else
        response.parsed
    end
end
set_secret(secret,&block) click to toggle source
# File lib/kiik/wallet/client.rb, line 65
def set_secret(secret,&block)
    request(:put, base_uri, { :client => { :api_secret => secret } },&block)
end
token() click to toggle source
# File lib/kiik/wallet/client.rb, line 24
def token
    @wallet.token
end
transaction() click to toggle source
# File lib/kiik/wallet/client.rb, line 91
def transaction
    @transaction ||= Kiik::Wallet::Transaction.new(self)
end
use_token(new_token,&block) click to toggle source
# File lib/kiik/wallet/client.rb, line 32
def use_token(new_token,&block)
  @wallet.client.token = new_token
  begin
    block.call(self)
  ensure
    @wallet.client.token =  @wallet.token
  end
end
user() click to toggle source
# File lib/kiik/wallet/client.rb, line 83
def user
    @user ||= Kiik::Wallet::User.new(self)
end

Private Instance Methods

allow(type,method) click to toggle source
# File lib/kiik/wallet/client.rb, line 106
def allow(type,method)
    raise TypeNotSupported.new("The #{type} is not supported by this api") if !ALLOWED_TYPES.include?(type)
    raise MethodNotAllowedForType.new("This type: #{type} don't allow this method.") if !ALLOWED_TYPES[type].include?(method)
end
request_params(params={}) click to toggle source
# File lib/kiik/wallet/client.rb, line 111
def request_params(params={})
    p = { 
        :params => {},
        :body => params.to_json,
        :headers => {
            'Accept' => 'application/json',
            'Content-type' => 'application/json'
        }
    }
    p
end