Class: Kiik::Wallet::Client
- Inherits:
-
Object
- Object
- Kiik::Wallet::Client
- 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
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
Instance Method Summary collapse
- #card ⇒ Object
- #client ⇒ Object
- #create(type, options = {}, &block) ⇒ Object
- #detail(type, options = {}, &block) ⇒ Object
-
#initialize(wallet, options) ⇒ Client
constructor
A new instance of Client.
- #list(type, options = {}, &block) ⇒ Object
- #request(verb, uri, params = {}, &block) ⇒ Object
- #set_secret(secret, &block) ⇒ Object
- #token ⇒ Object
- #transaction ⇒ Object
- #use_token(new_token, &block) ⇒ Object
- #user ⇒ Object
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,) @id = [:api_id] @name = [:name] @email = [:email] @secret = [:api_secret] @access_token = [:access_token] @wallet = wallet @base_uri = '/clients/#{id}' end |
Instance Attribute Details
#access_token ⇒ Object (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 |
#email ⇒ Object (readonly)
Returns the value of attribute email.
12 13 14 |
# File 'lib/kiik/wallet/client.rb', line 12 def email @email end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/kiik/wallet/client.rb', line 12 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/kiik/wallet/client.rb', line 12 def name @name end |
#secret ⇒ Object (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
#card ⇒ Object
87 88 89 |
# File 'lib/kiik/wallet/client.rb', line 87 def card @card ||= Kiik::Wallet::Creditcard.new(self) end |
#client ⇒ Object
28 29 30 |
# File 'lib/kiik/wallet/client.rb', line 28 def client @wallet.client end |
#create(type, options = {}, &block) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/kiik/wallet/client.rb', line 69 def create(type, ={},&block) allow(type,:create) token = .delete(:token) case type when :user user.create(,&block) when :creditcard card.create(token,,&block) when :transaction transaction.create(token,.delete(:credit_card),,&block) end end |
#detail(type, options = {}, &block) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/kiik/wallet/client.rb', line 41 def detail(type,={},&block) allow(type,:detail) case type when :client request(:get, base_uri,{}, &block) when :creditcard token = .delete(:token) card.detail(token,,&block) end end |
#list(type, options = {}, &block) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/kiik/wallet/client.rb', line 54 def list(type,={},&block) allow(type,:list) case type when :creditcard token = .delete(:token) card.list(token,&block) end end |
#request(verb, uri, params = {}, &block) ⇒ Object
95 96 97 98 99 100 101 102 103 |
# 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) ⇒ Object
65 66 67 |
# File 'lib/kiik/wallet/client.rb', line 65 def set_secret(secret,&block) request(:put, base_uri, { :client => { :api_secret => secret } },&block) end |
#token ⇒ Object
24 25 26 |
# File 'lib/kiik/wallet/client.rb', line 24 def token @wallet.token end |
#transaction ⇒ Object
91 92 93 |
# File 'lib/kiik/wallet/client.rb', line 91 def transaction @transaction ||= Kiik::Wallet::Transaction.new(self) end |
#use_token(new_token, &block) ⇒ Object
32 33 34 35 36 37 38 39 |
# 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 ⇒ Object
83 84 85 |
# File 'lib/kiik/wallet/client.rb', line 83 def user @user ||= Kiik::Wallet::User.new(self) end |