Class: SynapseClient::Customer
Instance Attribute Summary collapse
Attributes inherited from APIResource
#id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from APIResource
class_name, #refresh, #successful?, #to_hash, #url, url
Constructor Details
#initialize(options = {}) ⇒ Customer
Returns a new instance of Customer.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/synapse_client/customer.rb', line 10
def initialize(options = {})
options = Map.new(options)
@id = options[:id] || options[:user_id]
@email = options[:email]
@fullname = options[:fullname] || options[:name]
@phonenumber = options[:phonenumber] || options[:phone_number]
@ip_address = options[:ip_address]
@access_token = options[:access_token]
@refresh_token = options[:refresh_token]
@expires_in = options[:expires_in]
@username = options[:username]
@force_create = options[:force_create]
end
|
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
6
7
8
|
# File 'lib/synapse_client/customer.rb', line 6
def access_token
@access_token
end
|
#email ⇒ Object
Returns the value of attribute email.
5
6
7
|
# File 'lib/synapse_client/customer.rb', line 5
def email
@email
end
|
#expires_in ⇒ Object
Returns the value of attribute expires_in.
6
7
8
|
# File 'lib/synapse_client/customer.rb', line 6
def expires_in
@expires_in
end
|
#force_create ⇒ Object
Returns the value of attribute force_create.
8
9
10
|
# File 'lib/synapse_client/customer.rb', line 8
def force_create
@force_create
end
|
#fullname ⇒ Object
Returns the value of attribute fullname.
5
6
7
|
# File 'lib/synapse_client/customer.rb', line 5
def fullname
@fullname
end
|
#ip_address ⇒ Object
Returns the value of attribute ip_address.
5
6
7
|
# File 'lib/synapse_client/customer.rb', line 5
def ip_address
@ip_address
end
|
#phonenumber ⇒ Object
Returns the value of attribute phonenumber.
5
6
7
|
# File 'lib/synapse_client/customer.rb', line 5
def phonenumber
@phonenumber
end
|
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
6
7
8
|
# File 'lib/synapse_client/customer.rb', line 6
def refresh_token
@refresh_token
end
|
#username ⇒ Object
Returns the value of attribute username.
7
8
9
|
# File 'lib/synapse_client/customer.rb', line 7
def username
@username
end
|
Class Method Details
.api_resource_name ⇒ Object
27
28
29
|
# File 'lib/synapse_client/customer.rb', line 27
def self.api_resource_name
"user"
end
|
.create(opts = {}) ⇒ Object
31
32
33
|
# File 'lib/synapse_client/customer.rb', line 31
def self.create(opts={})
Customer.new(opts).create
end
|
.get_user(opts = {}) ⇒ Object
126
127
128
129
130
131
132
133
134
|
# File 'lib/synapse_client/customer.rb', line 126
def self.get_user(opts={})
response = SynapseClient.request(:post, url + "show", {:access_token => opts[:access_token]})
return response unless response.successful?
opts.delete(:expires_in) if opts[:expires_in].nil?
Customer.new(response.data.user.merge(opts))
end
|
.refresh_tokens(access_token, refresh_token) ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/synapse_client/customer.rb', line 111
def self.refresh_tokens(access_token, refresh_token)
rt = SynapseClient::RefreshedTokens.new({
:old_access_token => access_token,
:old_refresh_token => refresh_token
}).refresh_old_tokens
return rt if rt.instance_of?(SynapseClient::Error)
Map.new({
:access_token => rt.new_access_token,
:refresh_token => rt.new_refresh_token,
:expires_in => rt.new_expires_in
})
end
|
.retrieve(access_token, refresh_token) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/synapse_client/customer.rb', line 43
def self.retrieve(access_token, refresh_token)
response = Customer.get_user({
:access_token => access_token,
:refresh_token => refresh_token
})
unless response.successful?
new_tokens = Customer.refresh_tokens(access_token, refresh_token)
return new_tokens if new_tokens.instance_of?(SynapseClient::Error)
return Customer.get_user({
:access_token => new_tokens.access_token,
:refresh_token => new_tokens.refresh_token,
:expires_in => new_tokens.expires_in
})
end
response
end
|
Instance Method Details
#add_bank_account(params = {}) ⇒ Object
75
76
77
78
79
80
|
# File 'lib/synapse_client/customer.rb', line 75
def add_bank_account(params={})
BankAccount.add(params.merge({
:access_token => @access_token,
:fullname => @fullname
}))
end
|
#add_order(params = {}) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/synapse_client/customer.rb', line 99
def add_order(params={})
if SynapseClient.merchant_synapse_id.nil?
raise ArgumentError.new("You need to set SynapseClient.merchant_synapse_id before you can submit orders.")
else
Order.create(params.merge({
:access_token => @access_token,
:seller_id => params[:seller_id] || SynapseClient.merchant_synapse_id,
:bank_pay => "yes"
}))
end
end
|
#bank_accounts ⇒ Object
68
69
70
|
# File 'lib/synapse_client/customer.rb', line 68
def bank_accounts
BankAccount.all({:access_token => @access_token})
end
|
#create ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/synapse_client/customer.rb', line 35
def create
= {"REMOTE_ADDR" => @ip_address}
response = SynapseClient.request(:post, url + "create", to_hash, )
return response unless response.successful?
update_attributes(response.data)
end
|
#finish_linking_bank_account(params = {}) ⇒ Object
88
89
90
91
92
|
# File 'lib/synapse_client/customer.rb', line 88
def finish_linking_bank_account(params={})
BankAccount.finish_linking(params.merge({
:access_token => @access_token
}))
end
|
#link_bank_account(params = {}) ⇒ Object
82
83
84
85
86
|
# File 'lib/synapse_client/customer.rb', line 82
def link_bank_account(params={})
BankAccount.link(params.merge({
:access_token => @access_token
}))
end
|
#login ⇒ Object
63
64
65
|
# File 'lib/synapse_client/customer.rb', line 63
def login
end
|
#orders ⇒ Object
95
96
97
|
# File 'lib/synapse_client/customer.rb', line 95
def orders
Order.all({:access_token => @access_token})
end
|
#primary_bank_account ⇒ Object
71
72
73
|
# File 'lib/synapse_client/customer.rb', line 71
def primary_bank_account
@bank_accounts.select{|ba| ba.is_buyer_default}.first
end
|