Class: Coinbase::Wallet::OAuthClient

Inherits:
NetHTTPClient show all
Defined in:
lib/coinbase/wallet/client.rb

Constant Summary

Constants inherited from APIClient

APIClient::CALLBACK_DIGEST

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from APIClient

#account, #accounts, #address, #address_transactions, #addresses, #auth_info, #buy, #buy_price, callback_signing_public_key, #callback_signing_public_key, #cancel_request, #checkout, #checkout_orders, #checkouts, #commit_buy, #commit_deposit, #commit_sell, #commit_withdrawal, #complete_request, #create_account, #create_address, #create_checkout, #create_checkout_order, #create_order, #currencies, #current_user, #delete, #delete_account, #deposit, #exchange_rates, #get, #historic_prices, #list_buy, #list_buys, #list_deposit, #list_deposits, #list_sell, #list_sells, #list_withdrawal, #list_withdrawals, #merchant, #notification, #notifications, #order, #orders, #payment_method, #payment_methods, #post, #primary_account, #put, #refund_order, #request, #resend_request, #sell, #sell_price, #send, #set_primary_account, #spot_price, #time, #transaction, #transactions, #transfer, #update_account, #update_current_user, #user, verify_callback, #verify_callback, whitelisted_certificates, #withdraw

Constructor Details

#initialize(options = {}) ⇒ OAuthClient

Returns a new instance of OAuthClient.



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

def initialize(options={})
  raise unless options.has_key? :access_token
  @access_token = options[:access_token]
  @refresh_token = options[:refresh_token]
  @oauth_uri = URI.parse(options[:api_url] || BASE_API_URL)
  super(@oauth_uri, options)
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



30
31
32
# File 'lib/coinbase/wallet/client.rb', line 30

def access_token
  @access_token
end

#refresh_tokenObject

Returns the value of attribute refresh_token.



30
31
32
# File 'lib/coinbase/wallet/client.rb', line 30

def refresh_token
  @refresh_token
end

Instance Method Details

#auth_headers(method, path, body) ⇒ Object



40
41
42
43
# File 'lib/coinbase/wallet/client.rb', line 40

def auth_headers(method, path, body)
  { 'Authorization' => "Bearer #{@access_token}",
    'CB-VERSION' => API_VERSION }
end

#authorize!(redirect_url, params = {}) ⇒ Object

Raises:

  • (NotImplementedError)


45
46
47
# File 'lib/coinbase/wallet/client.rb', line 45

def authorize!(redirect_url, params = {})
  raise NotImplementedError
end

#refresh!(params = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/coinbase/wallet/client.rb', line 60

def refresh!(params = {})
  params[:grant_type] = 'refresh_token'
  params[:refresh_token] ||= @refresh_token

  raise "Missing Parameter: refresh_token" unless params.has_key?(:refresh_token)

  out = nil
  post("/oauth/token", params) do |resp|
    out = APIObject.new(self, resp.body)
    # Update tokens to current instance
    # Developer should always persist them
    @access_token = out.access_token
    @refresh_token = out.refresh_token
    yield(out, resp) if block_given?
  end
  out
end

#revoke!(params = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/coinbase/wallet/client.rb', line 49

def revoke!(params = {})
  params[:token] ||= @access_token

  out = nil
  post("/oauth/revoke", params) do |resp|
    out = APIObject.new(self, resp.body)
    yield(out, resp) if block_given?
  end
  out
end