Class: Kiik::Wallet::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/kiik/wallet/client.rb

Constant Summary collapse

ALLOWED_TYPES =
{
	:client => [ :create, :detail ],
	:user => [ :create ],
	:creditcard => [ :create, :detail ],
	:transaction => [ :create ]
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wallet, options) ⇒ Client

Returns a new instance of Client.



14
15
16
17
18
19
20
21
22
# 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

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



12
13
14
# File 'lib/kiik/wallet/client.rb', line 12

def access_token
  @access_token
end

#emailObject (readonly)

Returns the value of attribute email.



12
13
14
# File 'lib/kiik/wallet/client.rb', line 12

def email
  @email
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/kiik/wallet/client.rb', line 12

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/kiik/wallet/client.rb', line 12

def name
  @name
end

#secretObject (readonly)

Returns the value of attribute secret.



12
13
14
# File 'lib/kiik/wallet/client.rb', line 12

def secret
  @secret
end

Instance Method Details

#cardObject



84
85
86
# File 'lib/kiik/wallet/client.rb', line 84

def card
	@card ||= Kiik::Wallet::Creditcard.new(self)
end

#clientObject



28
29
30
# File 'lib/kiik/wallet/client.rb', line 28

def client
	@wallet.client
end

#create(type, options = {}, &block) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/kiik/wallet/client.rb', line 66

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) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/kiik/wallet/client.rb', line 38

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) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/kiik/wallet/client.rb', line 51

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 = {}, &block) ⇒ Object



92
93
94
95
96
97
98
99
100
# File 'lib/kiik/wallet/client.rb', line 92

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) ⇒ Object



62
63
64
# File 'lib/kiik/wallet/client.rb', line 62

def set_secret(secret,&block)
	request(:put, base_uri, { :client => { :api_secret => secret } },&block)
end

#tokenObject



24
25
26
# File 'lib/kiik/wallet/client.rb', line 24

def token
	@wallet.token
end

#transactionObject



88
89
90
# File 'lib/kiik/wallet/client.rb', line 88

def transaction
	@transaction ||= Kiik::Wallet::Transaction.new(self)
end

#use_token(new_token, &block) ⇒ Object



32
33
34
35
36
# File 'lib/kiik/wallet/client.rb', line 32

def use_token(new_token,&block)
  @wallet.client.token = new_token
  block.call(self)
  @wallet.client.token =  @wallet.token
end

#userObject



80
81
82
# File 'lib/kiik/wallet/client.rb', line 80

def user
	@user ||= Kiik::Wallet::User.new(self)
end