Class: Coinbase::Wallet::APIClient

Inherits:
Object
  • Object
show all
Defined in:
lib/coinbase/wallet/api_client.rb

Direct Known Subclasses

EMHTTPClient, NetHTTPClient

Constant Summary collapse

CALLBACK_DIGEST =
OpenSSL::Digest.new("SHA256")

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.callback_signing_public_keyObject



712
713
714
715
716
717
# File 'lib/coinbase/wallet/api_client.rb', line 712

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__), 'coinbase-callback.pub'))
  @@callback_signing_public_key = OpenSSL::PKey::RSA.new(File.read(path))
end

.verify_callback(body, signature) ⇒ Object



705
706
707
708
709
710
# File 'lib/coinbase/wallet/api_client.rb', line 705

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

.whitelisted_certificatesObject



727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
# File 'lib/coinbase/wallet/api_client.rb', line 727

def self.whitelisted_certificates
  path = File.expand_path(File.join(File.dirname(__FILE__), 'ca-coinbase.crt'))

  certs = [ [] ]
  File.readlines(path).each do |line|
    next if ["\n","#"].include?(line[0])
    certs.last << line
    certs << [] if line == "-----END CERTIFICATE-----\n"
  end

  result = OpenSSL::X509::Store.new

  certs.each do |lines|
    next if lines.empty?
    cert = OpenSSL::X509::Certificate.new(lines.join)
    result.add_cert(cert)
  end

  result
end

Instance Method Details

#account(account_id, params = {}) ⇒ Object



131
132
133
134
135
136
137
138
# File 'lib/coinbase/wallet/api_client.rb', line 131

def (, params = {})
  out = nil
  get("/v2/accounts/#{}", params) do |resp|
    out = Account.new(self, resp.data)
    yield(out, resp) if block_given?
  end
  out
end

#accounts(params = {}) ⇒ Object

Accounts



122
123
124
125
126
127
128
129
# File 'lib/coinbase/wallet/api_client.rb', line 122

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



219
220
221
222
223
224
225
226
# File 'lib/coinbase/wallet/api_client.rb', line 219

def address(, address_id, params = {})
  out = nil
  get("/v2/accounts/#{}/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



228
229
230
231
232
233
234
235
# File 'lib/coinbase/wallet/api_client.rb', line 228

def address_transactions(, address_id, params = {})
  out = nil
  get("/v2/accounts/#{}/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

Addresses



210
211
212
213
214
215
216
217
# File 'lib/coinbase/wallet/api_client.rb', line 210

def addresses(, params = {})
  out = nil
  get("/v2/accounts/#{}/addresses", params) do |resp|
    out = resp.data.map { |item| Address.new(self, item) }
    yield(out, resp) if block_given?
  end
  out
end

#auth_headers(method, path, body) ⇒ Object

Raises:

  • (NotImplementedError)


4
5
6
# File 'lib/coinbase/wallet/api_client.rb', line 4

def auth_headers(method, path, body)
  raise NotImplementedError, "APIClient is not intended to be used directly"
end

#auth_info(params = {}) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/coinbase/wallet/api_client.rb', line 101

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

Raises:



357
358
359
360
361
362
363
364
365
366
# File 'lib/coinbase/wallet/api_client.rb', line 357

def buy(, params = {})
  raise APIError, "Missing parameter: 'amount' or 'total'" unless params.include? :amount or params.include? :total

  out = nil
  post("/v2/accounts/#{}/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/coinbase/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_keyObject



719
720
721
# File 'lib/coinbase/wallet/api_client.rb', line 719

def callback_signing_public_key
  Coinbase::Wallet::APIClient.callback_signing_public_key
end

#cancel_request(account_id, transaction_id, params = {}) ⇒ Object



318
319
320
321
322
323
324
325
# File 'lib/coinbase/wallet/api_client.rb', line 318

def cancel_request(, transaction_id, params = {})
  out = nil
  delete("/v2/accounts/#{}/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



596
597
598
599
600
601
602
603
# File 'lib/coinbase/wallet/api_client.rb', line 596

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



618
619
620
621
622
623
624
625
# File 'lib/coinbase/wallet/api_client.rb', line 618

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

Checkouts



587
588
589
590
591
592
593
594
# File 'lib/coinbase/wallet/api_client.rb', line 587

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



368
369
370
371
372
373
374
375
# File 'lib/coinbase/wallet/api_client.rb', line 368

def commit_buy(, transaction_id, params = {})
  out = nil
  post("/v2/accounts/#{}/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



452
453
454
455
456
457
458
459
# File 'lib/coinbase/wallet/api_client.rb', line 452

def commit_deposit(, transaction_id, params = {})
  out = nil
  post("/v2/accounts/#{}/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



409
410
411
412
413
414
415
416
# File 'lib/coinbase/wallet/api_client.rb', line 409

def commit_sell(, transaction_id, params = {})
  out = nil
  post("/v2/accounts/#{}/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



495
496
497
498
499
500
501
502
# File 'lib/coinbase/wallet/api_client.rb', line 495

def commit_withdrawal(, transaction_id, params = {})
  out = nil
  post("/v2/accounts/#{}/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



327
328
329
330
331
332
333
334
# File 'lib/coinbase/wallet/api_client.rb', line 327

def complete_request(, transaction_id, params = {})
  out = nil
  post("/v2/accounts/#{}/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



158
159
160
161
162
163
164
165
# File 'lib/coinbase/wallet/api_client.rb', line 158

def (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



237
238
239
240
241
242
243
244
# File 'lib/coinbase/wallet/api_client.rb', line 237

def create_address(, params = {})
  out = nil
  post("/v2/accounts/#{}/addresses", params) do |resp|
    out = Address.new(self, resp.data)
    yield(out, resp) if block_given?
  end
  out
end

#create_checkout(params = {}) ⇒ Object



605
606
607
608
609
610
611
612
613
614
615
616
# File 'lib/coinbase/wallet/api_client.rb', line 605

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



627
628
629
630
631
632
633
634
# File 'lib/coinbase/wallet/api_client.rb', line 627

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



558
559
560
561
562
563
564
565
566
567
568
569
# File 'lib/coinbase/wallet/api_client.rb', line 558

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

Market Data



11
12
13
14
15
16
17
18
# File 'lib/coinbase/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



92
93
94
95
96
97
98
99
# File 'lib/coinbase/wallet/api_client.rb', line 92

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



692
693
694
695
696
697
698
699
700
701
702
# File 'lib/coinbase/wallet/api_client.rb', line 692

def delete(path, params)
  headers = {}
  if params.has_key? :two_factor_token
    headers['CB-2FA-TOKEN'] = params[:two_factor_token]
    params.delete(:two_factor_token)
  end

  http_verb('DELETE', path, nil, headers) do |resp|
    yield(resp)
  end
end

#delete_account(account_id, params = {}) ⇒ Object



176
177
178
179
180
181
182
183
# File 'lib/coinbase/wallet/api_client.rb', line 176

def (, params = {})
  out = nil
  delete("/v2/accounts/#{}", params) do |resp|
    out = APIObject.new(self, resp.data)
    yield(out, resp) if block_given?
  end
  out
end

#deposit(account_id, params = {}) ⇒ Object



439
440
441
442
443
444
445
446
447
448
449
450
# File 'lib/coinbase/wallet/api_client.rb', line 439

def deposit(, params = {})
  [ :amount ].each do |param|
    raise APIError, "Missing parameter: #{param}" unless params.include? param
  end

  out = nil
  post("/v2/accounts/#{}/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/coinbase/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

HTTP Stuff



639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
# File 'lib/coinbase/wallet/api_client.rb', line 639

def get(path, params)
  uri = path
  if params.count > 0
    uri += "?#{URI.encode_www_form(params)}"
  end

  headers = {}
  if params.has_key? :two_factor_token
    headers['CB-2FA-TOKEN'] = params[:two_factor_token]
    params.delete(:two_factor_token)
  end

  http_verb('GET', uri, nil, headers) 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/coinbase/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



348
349
350
351
352
353
354
355
# File 'lib/coinbase/wallet/api_client.rb', line 348

def list_buy(, transaction_id, params = {})
  out = nil
  get("/v2/accounts/#{}/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

Buys



339
340
341
342
343
344
345
346
# File 'lib/coinbase/wallet/api_client.rb', line 339

def list_buys(, params={})
  out = nil
  get("/v2/accounts/#{}/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



430
431
432
433
434
435
436
437
# File 'lib/coinbase/wallet/api_client.rb', line 430

def list_deposit(, transaction_id, params = {})
  out = nil
  get("/v2/accounts/#{}/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

Deposits



421
422
423
424
425
426
427
428
# File 'lib/coinbase/wallet/api_client.rb', line 421

def list_deposits(, params={})
  out = nil
  get("/v2/accounts/#{}/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



389
390
391
392
393
394
395
396
# File 'lib/coinbase/wallet/api_client.rb', line 389

def list_sell(, transaction_id, params = {})
  out = nil
  get("/v2/accounts/#{}/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

Sells



380
381
382
383
384
385
386
387
# File 'lib/coinbase/wallet/api_client.rb', line 380

def list_sells(, params = {})
  out = nil
  get("/v2/accounts/#{}/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



473
474
475
476
477
478
479
480
# File 'lib/coinbase/wallet/api_client.rb', line 473

def list_withdrawal(, transaction_id, params = {})
  out = nil
  get("/v2/accounts/#{}/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

withdrawals



464
465
466
467
468
469
470
471
# File 'lib/coinbase/wallet/api_client.rb', line 464

def list_withdrawals(, params={})
  out = nil
  get("/v2/accounts/#{}/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

Merchants



528
529
530
531
532
533
534
535
# File 'lib/coinbase/wallet/api_client.rb', line 528

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



197
198
199
200
201
202
203
204
# File 'lib/coinbase/wallet/api_client.rb', line 197

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

Notifications



188
189
190
191
192
193
194
195
# File 'lib/coinbase/wallet/api_client.rb', line 188

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



549
550
551
552
553
554
555
556
# File 'lib/coinbase/wallet/api_client.rb', line 549

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

Orders



540
541
542
543
544
545
546
547
# File 'lib/coinbase/wallet/api_client.rb', line 540

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



516
517
518
519
520
521
522
523
# File 'lib/coinbase/wallet/api_client.rb', line 516

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

Payment Methods



507
508
509
510
511
512
513
514
# File 'lib/coinbase/wallet/api_client.rb', line 507

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



680
681
682
683
684
685
686
687
688
689
690
# File 'lib/coinbase/wallet/api_client.rb', line 680

def post(path, params)
  headers = {}
  if params.has_key? :two_factor_token
    headers['CB-2FA-TOKEN'] = params[:two_factor_token]
    params.delete(:two_factor_token)
  end

  http_verb('POST', path, params.to_json, headers) do |resp|
    yield(resp)
  end
end

#primary_account(params = {}) ⇒ Object



140
141
142
143
144
145
146
147
# File 'lib/coinbase/wallet/api_client.rb', line 140

def (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



668
669
670
671
672
673
674
675
676
677
678
# File 'lib/coinbase/wallet/api_client.rb', line 668

def put(path, params)
  headers = {}
  if params.has_key? :two_factor_token
    headers['CB-2FA-TOKEN'] = params[:two_factor_token]
    params.delete(:two_factor_token)
  end

  http_verb('PUT', path, params.to_json, headers) do |resp|
    yield(resp)
  end
end

#refund_order(order_id, params = {}) ⇒ Object



571
572
573
574
575
576
577
578
579
580
581
582
# File 'lib/coinbase/wallet/api_client.rb', line 571

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



295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/coinbase/wallet/api_client.rb', line 295

def request(, 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/#{}/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



309
310
311
312
313
314
315
316
# File 'lib/coinbase/wallet/api_client.rb', line 309

def resend_request(, transaction_id, params = {})
  out = nil
  post("/v2/accounts/#{}/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

Raises:



398
399
400
401
402
403
404
405
406
407
# File 'lib/coinbase/wallet/api_client.rb', line 398

def sell(, params = {})
  raise APIError, "Missing parameter: 'amount' or 'total'" unless params.include? :amount or params.include? :total

  out = nil
  post("/v2/accounts/#{}/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/coinbase/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



267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/coinbase/wallet/api_client.rb', line 267

def send(, params = {})
  [ :to, :amount ].each do |param|
    raise APIError, "Missing parameter: #{param}" unless params.include? param
  end
  params['type'] = 'send'

  out = nil
  post("/v2/accounts/#{}/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



149
150
151
152
153
154
155
156
# File 'lib/coinbase/wallet/api_client.rb', line 149

def (, params = {})
  out = nil
  post("/v2/accounts/#{}/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/coinbase/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/coinbase/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



258
259
260
261
262
263
264
265
# File 'lib/coinbase/wallet/api_client.rb', line 258

def transaction(, transaction_id, params = {})
  out = nil
  get("/v2/accounts/#{}/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

Transactions



249
250
251
252
253
254
255
256
# File 'lib/coinbase/wallet/api_client.rb', line 249

def transactions(, params = {})
  out = nil
  get("/v2/accounts/#{}/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



281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/coinbase/wallet/api_client.rb', line 281

def transfer(, params = {})
  [ :to, :amount ].each do |param|
    raise APIError, "Missing parameter: #{param}" unless params.include? param
  end
  params['type'] = 'transfer'

  out = nil
  post("/v2/accounts/#{}/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



167
168
169
170
171
172
173
174
# File 'lib/coinbase/wallet/api_client.rb', line 167

def (, params = {})
  out = nil
  put("/v2/accounts/#{}", params) do |resp|
    out = Account.new(self, resp.data)
    yield(out, resp) if block_given?
  end
  out
end

#update_current_user(params = {}) ⇒ Object



110
111
112
113
114
115
116
117
# File 'lib/coinbase/wallet/api_client.rb', line 110

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

Users



83
84
85
86
87
88
89
90
# File 'lib/coinbase/wallet/api_client.rb', line 83

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



723
724
725
# File 'lib/coinbase/wallet/api_client.rb', line 723

def verify_callback(body, signature)
  Coinbase::Wallet::APIClient.verify_callback(body, signature)
end

#withdraw(account_id, params = {}) ⇒ Object



482
483
484
485
486
487
488
489
490
491
492
493
# File 'lib/coinbase/wallet/api_client.rb', line 482

def withdraw(, params = {})
  [ :amount ].each do |param|
    raise APIError, "Missing parameter: #{param}" unless params.include? param
  end

  out = nil
  post("/v2/accounts/#{}/withdrawals", params) do |resp|
    out = Transfer.new(self, resp.data)
    yield(out, resp) if block_given?
  end
  out
end