Class: Cwallet::Wallet::APIClient
- Inherits:
-
Object
- Object
- Cwallet::Wallet::APIClient
show all
- Defined in:
- lib/cwallet/wallet/api_client.rb
Constant Summary
collapse
- CALLBACK_DIGEST =
OpenSSL::Digest.new("SHA256")
Class Method Summary
collapse
Instance Method Summary
collapse
-
#account(account_id, params = {}) ⇒ Object
-
#accounts(params = {}) ⇒ Object
-
#address(account_id, address_id, params = {}) ⇒ Object
-
#address_transactions(account_id, address_id, params = {}) ⇒ Object
-
#addresses(account_id, params = {}) ⇒ Object
-
#auth_headers(method, path, body) ⇒ Object
-
#auth_info(params = {}) ⇒ Object
-
#buy(account_id, params = {}) ⇒ Object
-
#buy_price(params = {}) ⇒ Object
-
#callback_signing_public_key ⇒ Object
-
#cancel_request(account_id, transaction_id, params = {}) ⇒ Object
-
#checkout(checkout_id, params = {}) ⇒ Object
-
#checkout_orders(checkout_id, params = {}) ⇒ Object
-
#checkouts(params = {}) ⇒ Object
-
#commit_buy(account_id, transaction_id, params = {}) ⇒ Object
-
#commit_deposit(account_id, transaction_id, params = {}) ⇒ Object
-
#commit_sell(account_id, transaction_id, params = {}) ⇒ Object
-
#commit_withdrawal(account_id, transaction_id, params = {}) ⇒ Object
-
#complete_request(account_id, transaction_id, params = {}) ⇒ Object
-
#create_account(params = {}) ⇒ Object
-
#create_address(account_id, params = {}) ⇒ Object
-
#create_checkout(params = {}) ⇒ Object
-
#create_checkout_order(checkout_id, params = {}) ⇒ Object
-
#create_order(params = {}) ⇒ Object
-
#currencies(params = {}) ⇒ Object
-
#current_user(params = {}) ⇒ Object
-
#delete(path, params) ⇒ Object
-
#delete_account(account_id, params = {}) ⇒ Object
-
#deposit(account_id, params = {}) ⇒ Object
-
#exchange_rates(params = {}) ⇒ Object
-
#get(path, params) ⇒ Object
-
#historic_prices(params = {}) ⇒ Object
-
#list_buy(account_id, transaction_id, params = {}) ⇒ Object
-
#list_buys(account_id, params = {}) ⇒ Object
-
#list_deposit(account_id, transaction_id, params = {}) ⇒ Object
-
#list_deposits(account_id, params = {}) ⇒ Object
-
#list_sell(account_id, transaction_id, params = {}) ⇒ Object
-
#list_sells(account_id, params = {}) ⇒ Object
-
#list_withdrawal(account_id, transaction_id, params = {}) ⇒ Object
-
#list_withdrawals(account_id, params = {}) ⇒ Object
-
#merchant(merchant_id, params = {}) ⇒ Object
-
#notification(notification_id, params = {}) ⇒ Object
-
#notifications(params = {}) ⇒ Object
-
#order(order_id, params = {}) ⇒ Object
-
#orders(params = {}) ⇒ Object
-
#payment_method(payment_method_id, params = {}) ⇒ Object
-
#payment_methods(params = {}) ⇒ Object
-
#post(path, params) ⇒ Object
-
#primary_account(params = {}) ⇒ Object
-
#put(path, params) ⇒ Object
-
#refund_order(order_id, params = {}) ⇒ Object
-
#request(account_id, params = {}) ⇒ Object
-
#resend_request(account_id, transaction_id, params = {}) ⇒ Object
-
#sell(account_id, params = {}) ⇒ Object
-
#sell_price(params = {}) ⇒ Object
-
#send(account_id, params = {}) ⇒ Object
-
#set_primary_account(account_id, params = {}) ⇒ Object
-
#spot_price(params = {}) ⇒ Object
-
#time(params = {}) ⇒ Object
-
#transaction(account_id, transaction_id, params = {}) ⇒ Object
-
#transactions(account_id, params = {}) ⇒ Object
-
#transfer(account_id, params = {}) ⇒ Object
-
#update_account(account_id, params = {}) ⇒ Object
-
#update_current_user(params = {}) ⇒ Object
-
#user(user_id, params = {}) ⇒ Object
-
#verify_callback(body, signature) ⇒ Object
-
#withdraw(account_id, params = {}) ⇒ Object
Class Method Details
.callback_signing_public_key ⇒ Object
726
727
728
729
730
731
|
# File 'lib/cwallet/wallet/api_client.rb', line 726
def self.callback_signing_public_key
@@callback_signing_public_key ||= nil
return @@callback_signing_public_key if @@callback_signing_public_key
path = File.expand_path(File.join(File.dirname(__FILE__), 'cpub.pub'))
@@callback_signing_public_key = OpenSSL::PKey::RSA.new(File.read(path))
end
|
.create_user(params) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/cwallet/wallet/api_client.rb', line 83
def self.create_user(params)
req = Net::HTTP::Post.new("/v2/user")
req.body = params.to_json
req['Content-Type'] = 'application/json'
req['User-Agent'] = "cwallet/ruby/#{Cwallet::Wallet::VERSION}"
uri = URI.parse(params[:api_url] || Cwallet::Wallet::BASE_API_URL)
conn = Net::HTTP.new(uri.host, uri.port)
conn.use_ssl = true
resp = conn.request(req)
User.new(self, JSON.parse(resp.body)['data'])
end
|
.verify_callback(body, signature) ⇒ Object
719
720
721
722
723
724
|
# File 'lib/cwallet/wallet/api_client.rb', line 719
def self.verify_callback(body, signature)
return false unless callback_signing_public_key
callback_signing_public_key.verify(CALLBACK_DIGEST, signature.unpack("m0")[0], body)
rescue OpenSSL::PKey::RSAError, ArgumentError
false
end
|
Instance Method Details
#account(account_id, params = {}) ⇒ Object
145
146
147
148
149
150
151
152
|
# File 'lib/cwallet/wallet/api_client.rb', line 145
def account(account_id, params = {})
out = nil
get("/v2/accounts/#{account_id}", params) do |resp|
out = Account.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#accounts(params = {}) ⇒ Object
136
137
138
139
140
141
142
143
|
# File 'lib/cwallet/wallet/api_client.rb', line 136
def accounts(params = {})
out = nil
get("/v2/accounts", params) do |resp|
out = resp.data.map { |item| Account.new(self, item) }
yield(out, resp) if block_given?
end
out
end
|
#address(account_id, address_id, params = {}) ⇒ Object
233
234
235
236
237
238
239
240
|
# File 'lib/cwallet/wallet/api_client.rb', line 233
def address(account_id, address_id, params = {})
out = nil
get("/v2/accounts/#{account_id}/addresses/#{address_id}", params) do |resp|
out = Address.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#address_transactions(account_id, address_id, params = {}) ⇒ Object
242
243
244
245
246
247
248
249
|
# File 'lib/cwallet/wallet/api_client.rb', line 242
def address_transactions(account_id, address_id, params = {})
out = nil
get("/v2/accounts/#{account_id}/addresses/#{address_id}/transactions", params) do |resp|
out = resp.data.map { |item| Transaction.new(self, item) }
yield(out, resp) if block_given?
end
out
end
|
#addresses(account_id, params = {}) ⇒ Object
224
225
226
227
228
229
230
231
|
# File 'lib/cwallet/wallet/api_client.rb', line 224
def addresses(account_id, params = {})
out = nil
get("/v2/accounts/#{account_id}/addresses", params) do |resp|
out = resp.data.map { |item| Address.new(self, item) }
yield(out, resp) if block_given?
end
out
end
|
4
5
6
|
# File 'lib/cwallet/wallet/api_client.rb', line 4
def (method, path, body)
raise NotImplementedError, "APIClient is not intended to be used directly"
end
|
#auth_info(params = {}) ⇒ Object
115
116
117
118
119
120
121
122
|
# File 'lib/cwallet/wallet/api_client.rb', line 115
def auth_info(params = {})
out = nil
get("/v2/user/auth", params) do |resp|
out = APIObject.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#buy(account_id, params = {}) ⇒ Object
371
372
373
374
375
376
377
378
379
380
|
# File 'lib/cwallet/wallet/api_client.rb', line 371
def buy(account_id, params = {})
raise APIError, "Missing parameter: 'amount' or 'total'" unless params.include? :amount or params.include? :total
out = nil
post("/v2/accounts/#{account_id}/buys", params) do |resp|
out = Transfer.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#buy_price(params = {}) ⇒ Object
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/cwallet/wallet/api_client.rb', line 29
def buy_price(params = {})
out = nil
pair = determine_currency_pair(params)
get("/v2/prices/#{pair}/buy", params) do |resp|
out = APIObject.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#callback_signing_public_key ⇒ Object
733
734
735
|
# File 'lib/cwallet/wallet/api_client.rb', line 733
def callback_signing_public_key
Cwallet::Wallet::APIClient.callback_signing_public_key
end
|
#cancel_request(account_id, transaction_id, params = {}) ⇒ Object
332
333
334
335
336
337
338
339
|
# File 'lib/cwallet/wallet/api_client.rb', line 332
def cancel_request(account_id, transaction_id, params = {})
out = nil
delete("/v2/accounts/#{account_id}/transactions/#{transaction_id}", params) do |resp|
out = APIObject.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#checkout(checkout_id, params = {}) ⇒ Object
610
611
612
613
614
615
616
617
|
# File 'lib/cwallet/wallet/api_client.rb', line 610
def checkout(checkout_id, params = {})
out = nil
get("/v2/checkouts/#{checkout_id}", params) do |resp|
out = Checkout.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#checkout_orders(checkout_id, params = {}) ⇒ Object
632
633
634
635
636
637
638
639
|
# File 'lib/cwallet/wallet/api_client.rb', line 632
def checkout_orders(checkout_id, params = {})
out = nil
get("/v2/checkouts/#{checkout_id}/orders", params) do |resp|
out = resp.data.map { |item| Order.new(self, item) }
yield(out, resp) if block_given?
end
out
end
|
#checkouts(params = {}) ⇒ Object
601
602
603
604
605
606
607
608
|
# File 'lib/cwallet/wallet/api_client.rb', line 601
def checkouts(params = {})
out = nil
get("/v2/checkouts", params) do |resp|
out = resp.data.map { |item| Checkout.new(self, item) }
yield(out, resp) if block_given?
end
out
end
|
#commit_buy(account_id, transaction_id, params = {}) ⇒ Object
382
383
384
385
386
387
388
389
|
# File 'lib/cwallet/wallet/api_client.rb', line 382
def commit_buy(account_id, transaction_id, params = {})
out = nil
post("/v2/accounts/#{account_id}/buys/#{transaction_id}/commit", params) do |resp|
out = Transfer.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#commit_deposit(account_id, transaction_id, params = {}) ⇒ Object
466
467
468
469
470
471
472
473
|
# File 'lib/cwallet/wallet/api_client.rb', line 466
def commit_deposit(account_id, transaction_id, params = {})
out = nil
post("/v2/accounts/#{account_id}/deposits/#{transaction_id}/commit", params) do |resp|
out = APIObject.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#commit_sell(account_id, transaction_id, params = {}) ⇒ Object
423
424
425
426
427
428
429
430
|
# File 'lib/cwallet/wallet/api_client.rb', line 423
def commit_sell(account_id, transaction_id, params = {})
out = nil
post("/v2/accounts/#{account_id}/sells/#{transaction_id}/commit", params) do |resp|
out = Transfer.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#commit_withdrawal(account_id, transaction_id, params = {}) ⇒ Object
509
510
511
512
513
514
515
516
|
# File 'lib/cwallet/wallet/api_client.rb', line 509
def commit_withdrawal(account_id, transaction_id, params = {})
out = nil
post("/v2/accounts/#{account_id}/withdrawals/#{transaction_id}/commit", params) do |resp|
out = APIObject.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#complete_request(account_id, transaction_id, params = {}) ⇒ Object
341
342
343
344
345
346
347
348
|
# File 'lib/cwallet/wallet/api_client.rb', line 341
def complete_request(account_id, transaction_id, params = {})
out = nil
post("/v2/accounts/#{account_id}/transactions/#{transaction_id}/complete", params) do |resp|
out = APIObject.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#create_account(params = {}) ⇒ Object
172
173
174
175
176
177
178
179
|
# File 'lib/cwallet/wallet/api_client.rb', line 172
def create_account(params = {})
out = nil
post("/v2/accounts", params) do |resp|
out = Account.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#create_address(account_id, params = {}) ⇒ Object
251
252
253
254
255
256
257
258
|
# File 'lib/cwallet/wallet/api_client.rb', line 251
def create_address(account_id, params = {})
out = nil
post("/v2/accounts/#{account_id}/addresses", params) do |resp|
out = Address.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#create_checkout(params = {}) ⇒ Object
619
620
621
622
623
624
625
626
627
628
629
630
|
# File 'lib/cwallet/wallet/api_client.rb', line 619
def create_checkout(params = {})
[ :amount, :currency, :name ].each do |param|
fail APIError, "Missing parameter: #{param}" unless params.include? param
end
out = nil
post("/v2/checkouts", params) do |resp|
out = Checkout.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#create_checkout_order(checkout_id, params = {}) ⇒ Object
641
642
643
644
645
646
647
648
|
# File 'lib/cwallet/wallet/api_client.rb', line 641
def create_checkout_order(checkout_id, params={})
out = nil
post("/v2/checkouts/#{checkout_id}/orders", params) do |resp|
out = Order.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#create_order(params = {}) ⇒ Object
572
573
574
575
576
577
578
579
580
581
582
583
|
# File 'lib/cwallet/wallet/api_client.rb', line 572
def create_order(params = {})
[ :amount, :currency, :name ].each do |param|
fail APIError, "Missing parameter: #{param}" unless params.include? param
end
out = nil
post("/v2/orders", params) do |resp|
out = Order.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#currencies(params = {}) ⇒ Object
11
12
13
14
15
16
17
18
|
# File 'lib/cwallet/wallet/api_client.rb', line 11
def currencies(params = {})
out = nil
get("/v2/currencies", params) do |resp|
out = resp.data.map { |item| APIObject.new(self, item) }
yield(out, resp) if block_given?
end
out
end
|
#current_user(params = {}) ⇒ Object
106
107
108
109
110
111
112
113
|
# File 'lib/cwallet/wallet/api_client.rb', line 106
def current_user(params = {})
out = nil
get("/v2/user", params) do |resp|
out = CurrentUser.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#delete(path, params) ⇒ Object
706
707
708
709
710
711
712
713
714
715
716
|
# File 'lib/cwallet/wallet/api_client.rb', line 706
def delete(path, params)
= {}
if params.has_key? :two_factor_token
['CB-2FA-TOKEN'] = params[:two_factor_token]
params.delete(:two_factor_token)
end
http_verb('DELETE', path, nil, ) do |resp|
yield(resp)
end
end
|
#delete_account(account_id, params = {}) ⇒ Object
190
191
192
193
194
195
196
197
|
# File 'lib/cwallet/wallet/api_client.rb', line 190
def delete_account(account_id, params = {})
out = nil
delete("/v2/accounts/#{account_id}", params) do |resp|
out = APIObject.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#deposit(account_id, params = {}) ⇒ Object
453
454
455
456
457
458
459
460
461
462
463
464
|
# File 'lib/cwallet/wallet/api_client.rb', line 453
def deposit(account_id, params = {})
[ :amount ].each do |param|
raise APIError, "Missing parameter: #{param}" unless params.include? param
end
out = nil
post("/v2/accounts/#{account_id}/deposits", params) do |resp|
out = Transfer.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#exchange_rates(params = {}) ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/cwallet/wallet/api_client.rb', line 20
def exchange_rates(params = {})
out = nil
get("/v2/exchange-rates", params) do |resp|
out = APIObject.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#get(path, params) ⇒ Object
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
|
# File 'lib/cwallet/wallet/api_client.rb', line 653
def get(path, params)
uri = path
if params.count > 0
uri += "?#{URI.encode_www_form(params)}"
end
= {}
if params.has_key? :two_factor_token
['CB-2FA-TOKEN'] = params[:two_factor_token]
params.delete(:two_factor_token)
end
http_verb('GET', uri, nil, ) do |resp|
if params[:fetch_all] == true &&
resp.body.has_key?('pagination') &&
resp.body['pagination']['next_uri'] != nil
params[:starting_after] = resp.body['data'].last['id']
get(path, params) do |page|
body = resp.body
body['data'] += page.data
resp.body = body
yield(resp)
end
else
yield(resp)
end
end
end
|
#historic_prices(params = {}) ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/cwallet/wallet/api_client.rb', line 62
def historic_prices(params = {})
out = nil
get("/v2/prices/historic", params) do |resp|
out = APIObject.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#list_buy(account_id, transaction_id, params = {}) ⇒ Object
362
363
364
365
366
367
368
369
|
# File 'lib/cwallet/wallet/api_client.rb', line 362
def list_buy(account_id, transaction_id, params = {})
out = nil
get("/v2/accounts/#{account_id}/buys/#{transaction_id}", params) do |resp|
out = Transfer.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#list_buys(account_id, params = {}) ⇒ Object
353
354
355
356
357
358
359
360
|
# File 'lib/cwallet/wallet/api_client.rb', line 353
def list_buys(account_id, params={})
out = nil
get("/v2/accounts/#{account_id}/buys", params) do |resp|
out = resp.data.map { |item| Transfer.new(self, item) }
yield(out, resp) if block_given?
end
out
end
|
#list_deposit(account_id, transaction_id, params = {}) ⇒ Object
444
445
446
447
448
449
450
451
|
# File 'lib/cwallet/wallet/api_client.rb', line 444
def list_deposit(account_id, transaction_id, params = {})
out = nil
get("/v2/accounts/#{account_id}/deposits/#{transaction_id}", params) do |resp|
out = Transfer.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#list_deposits(account_id, params = {}) ⇒ Object
435
436
437
438
439
440
441
442
|
# File 'lib/cwallet/wallet/api_client.rb', line 435
def list_deposits(account_id, params={})
out = nil
get("/v2/accounts/#{account_id}/deposits", params) do |resp|
out = resp.data.map { |item| Transfer.new(self, item) }
yield(out, resp) if block_given?
end
out
end
|
#list_sell(account_id, transaction_id, params = {}) ⇒ Object
403
404
405
406
407
408
409
410
|
# File 'lib/cwallet/wallet/api_client.rb', line 403
def list_sell(account_id, transaction_id, params = {})
out = nil
get("/v2/accounts/#{account_id}/sells/#{transaction_id}", params) do |resp|
out = Transfer.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#list_sells(account_id, params = {}) ⇒ Object
394
395
396
397
398
399
400
401
|
# File 'lib/cwallet/wallet/api_client.rb', line 394
def list_sells(account_id, params = {})
out = nil
get("/v2/accounts/#{account_id}/sells", params) do |resp|
out = resp.data.map { |item| Transfer.new(self, item) }
yield(out, resp) if block_given?
end
out
end
|
#list_withdrawal(account_id, transaction_id, params = {}) ⇒ Object
487
488
489
490
491
492
493
494
|
# File 'lib/cwallet/wallet/api_client.rb', line 487
def list_withdrawal(account_id, transaction_id, params = {})
out = nil
get("/v2/accounts/#{account_id}/withdrawals/#{transaction_id}", params) do |resp|
out = Transfer.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#list_withdrawals(account_id, params = {}) ⇒ Object
478
479
480
481
482
483
484
485
|
# File 'lib/cwallet/wallet/api_client.rb', line 478
def list_withdrawals(account_id, params={})
out = nil
get("/v2/accounts/#{account_id}/withdrawals", params) do |resp|
out = resp.data.map { |item| Transfer.new(self, item) }
yield(out, resp) if block_given?
end
out
end
|
#merchant(merchant_id, params = {}) ⇒ Object
542
543
544
545
546
547
548
549
|
# File 'lib/cwallet/wallet/api_client.rb', line 542
def merchant(merchant_id, params = {})
out = nil
get("/v2/merchants/#{merchant_id}", params) do |resp|
out = APIObject.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#notification(notification_id, params = {}) ⇒ Object
211
212
213
214
215
216
217
218
|
# File 'lib/cwallet/wallet/api_client.rb', line 211
def notification(notification_id, params = {})
out = nil
get("/v2/notifications/#{notification_id}", params) do |resp|
out = APIObject.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#notifications(params = {}) ⇒ Object
202
203
204
205
206
207
208
209
|
# File 'lib/cwallet/wallet/api_client.rb', line 202
def notifications(params = {})
out = nil
get("/v2/notifications", params) do |resp|
out = resp.data.map { |item| APIObject.new(self, item) }
yield(out, resp) if block_given?
end
out
end
|
#order(order_id, params = {}) ⇒ Object
563
564
565
566
567
568
569
570
|
# File 'lib/cwallet/wallet/api_client.rb', line 563
def order(order_id, params = {})
out = nil
get("/v2/orders/#{order_id}", params) do |resp|
out = Order.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#orders(params = {}) ⇒ Object
554
555
556
557
558
559
560
561
|
# File 'lib/cwallet/wallet/api_client.rb', line 554
def orders(params = {})
out = nil
get("/v2/orders", params) do |resp|
out = resp.data.map { |item| Order.new(self, item) }
yield(out, resp) if block_given?
end
out
end
|
#payment_method(payment_method_id, params = {}) ⇒ Object
530
531
532
533
534
535
536
537
|
# File 'lib/cwallet/wallet/api_client.rb', line 530
def payment_method(payment_method_id, params = {})
out = nil
get("/v2/payment-methods/#{payment_method_id}", params) do |resp|
out = APIObject.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#payment_methods(params = {}) ⇒ Object
521
522
523
524
525
526
527
528
|
# File 'lib/cwallet/wallet/api_client.rb', line 521
def payment_methods(params = {})
out = nil
get("/v2/payment-methods", params) do |resp|
out = resp.data.map { |item| APIObject.new(self, item) }
yield(out, resp) if block_given?
end
out
end
|
#post(path, params) ⇒ Object
694
695
696
697
698
699
700
701
702
703
704
|
# File 'lib/cwallet/wallet/api_client.rb', line 694
def post(path, params)
= {}
if params.has_key? :two_factor_token
['CB-2FA-TOKEN'] = params[:two_factor_token]
params.delete(:two_factor_token)
end
http_verb('POST', path, params.to_json, ) do |resp|
yield(resp)
end
end
|
#primary_account(params = {}) ⇒ Object
154
155
156
157
158
159
160
161
|
# File 'lib/cwallet/wallet/api_client.rb', line 154
def primary_account(params = {})
out = nil
get("/v2/accounts/primary", params) do |resp|
out = Account.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#put(path, params) ⇒ Object
682
683
684
685
686
687
688
689
690
691
692
|
# File 'lib/cwallet/wallet/api_client.rb', line 682
def put(path, params)
= {}
if params.has_key? :two_factor_token
['CB-2FA-TOKEN'] = params[:two_factor_token]
params.delete(:two_factor_token)
end
http_verb('PUT', path, params.to_json, ) do |resp|
yield(resp)
end
end
|
#refund_order(order_id, params = {}) ⇒ Object
585
586
587
588
589
590
591
592
593
594
595
596
|
# File 'lib/cwallet/wallet/api_client.rb', line 585
def refund_order(order_id, params={})
[ :currency ].each do |param|
fail APIError, "Missing parameter: #{param}" unless params.include? param
end
out = nil
post("/v2/orders/#{order_id}/refund", params) do |resp|
out = Order.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#request(account_id, params = {}) ⇒ Object
309
310
311
312
313
314
315
316
317
318
319
320
321
|
# File 'lib/cwallet/wallet/api_client.rb', line 309
def request(account_id, params = {})
[ :to, :amount, :currency ].each do |param|
raise APIError, "Missing parameter: #{param}" unless params.include? param
end
params['type'] = 'request'
out = nil
post("/v2/accounts/#{account_id}/transactions", params) do |resp|
out = Request.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#resend_request(account_id, transaction_id, params = {}) ⇒ Object
323
324
325
326
327
328
329
330
|
# File 'lib/cwallet/wallet/api_client.rb', line 323
def resend_request(account_id, transaction_id, params = {})
out = nil
post("/v2/accounts/#{account_id}/transactions/#{transaction_id}/resend", params) do |resp|
out = APIObject.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#sell(account_id, params = {}) ⇒ Object
412
413
414
415
416
417
418
419
420
421
|
# File 'lib/cwallet/wallet/api_client.rb', line 412
def sell(account_id, params = {})
raise APIError, "Missing parameter: 'amount' or 'total'" unless params.include? :amount or params.include? :total
out = nil
post("/v2/accounts/#{account_id}/sells", params) do |resp|
out = Transfer.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#sell_price(params = {}) ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/cwallet/wallet/api_client.rb', line 40
def sell_price(params = {})
out = nil
pair = determine_currency_pair(params)
get("/v2/prices/#{pair}/sell", params) do |resp|
out = APIObject.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#send(account_id, params = {}) ⇒ Object
281
282
283
284
285
286
287
288
289
290
291
292
293
|
# File 'lib/cwallet/wallet/api_client.rb', line 281
def send(account_id, params = {})
[ :to, :amount ].each do |param|
raise APIError, "Missing parameter: #{param}" unless params.include? param
end
params['type'] = 'send'
out = nil
post("/v2/accounts/#{account_id}/transactions", params) do |resp|
out = Transaction.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#set_primary_account(account_id, params = {}) ⇒ Object
163
164
165
166
167
168
169
170
|
# File 'lib/cwallet/wallet/api_client.rb', line 163
def set_primary_account(account_id, params = {})
out = nil
post("/v2/accounts/#{account_id}/primary", params) do |resp|
out = Account.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#spot_price(params = {}) ⇒ Object
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/cwallet/wallet/api_client.rb', line 51
def spot_price(params = {})
out = nil
pair = determine_currency_pair(params)
get("/v2/prices/#{pair}/spot", params) do |resp|
out = APIObject.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#time(params = {}) ⇒ Object
71
72
73
74
75
76
77
78
|
# File 'lib/cwallet/wallet/api_client.rb', line 71
def time(params = {})
out = nil
get("/v2/time", params) do |resp|
out = APIObject.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#transaction(account_id, transaction_id, params = {}) ⇒ Object
272
273
274
275
276
277
278
279
|
# File 'lib/cwallet/wallet/api_client.rb', line 272
def transaction(account_id, transaction_id, params = {})
out = nil
get("/v2/accounts/#{account_id}/transactions/#{transaction_id}", params) do |resp|
out = Transaction.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#transactions(account_id, params = {}) ⇒ Object
263
264
265
266
267
268
269
270
|
# File 'lib/cwallet/wallet/api_client.rb', line 263
def transactions(account_id, params = {})
out = nil
get("/v2/accounts/#{account_id}/transactions", params) do |resp|
out = resp.data.map { |item| Transaction.new(self, item) }
yield(out, resp) if block_given?
end
out
end
|
#transfer(account_id, params = {}) ⇒ Object
295
296
297
298
299
300
301
302
303
304
305
306
307
|
# File 'lib/cwallet/wallet/api_client.rb', line 295
def transfer(account_id, params = {})
[ :to, :amount ].each do |param|
raise APIError, "Missing parameter: #{param}" unless params.include? param
end
params['type'] = 'transfer'
out = nil
post("/v2/accounts/#{account_id}/transactions", params) do |resp|
out = Transaction.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#update_account(account_id, params = {}) ⇒ Object
181
182
183
184
185
186
187
188
|
# File 'lib/cwallet/wallet/api_client.rb', line 181
def update_account(account_id, params = {})
out = nil
put("/v2/accounts/#{account_id}", params) do |resp|
out = Account.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#update_current_user(params = {}) ⇒ Object
124
125
126
127
128
129
130
131
|
# File 'lib/cwallet/wallet/api_client.rb', line 124
def update_current_user(params = {})
out = nil
put("/v2/user", params) do |resp|
out = CurrentUser.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#user(user_id, params = {}) ⇒ Object
97
98
99
100
101
102
103
104
|
# File 'lib/cwallet/wallet/api_client.rb', line 97
def user(user_id, params = {})
out = nil
get("/v2/users/#{user_id}", params) do |resp|
out = User.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|
#verify_callback(body, signature) ⇒ Object
737
738
739
|
# File 'lib/cwallet/wallet/api_client.rb', line 737
def verify_callback(body, signature)
Cwallet::Wallet::APIClient.verify_callback(body, signature)
end
|
#withdraw(account_id, params = {}) ⇒ Object
496
497
498
499
500
501
502
503
504
505
506
507
|
# File 'lib/cwallet/wallet/api_client.rb', line 496
def withdraw(account_id, params = {})
[ :amount ].each do |param|
raise APIError, "Missing parameter: #{param}" unless params.include? param
end
out = nil
post("/v2/accounts/#{account_id}/withdrawals", params) do |resp|
out = Transfer.new(self, resp.data)
yield(out, resp) if block_given?
end
out
end
|