class Coinbase::Wallet::OAuthClient

Attributes

access_token[RW]
refresh_token[RW]

Public Class Methods

new(options={}) click to toggle source
Calls superclass method Coinbase::Wallet::NetHTTPClient::new
# 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

Public Instance Methods

auth_headers(method, path, body) click to toggle source
# 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 = {}) click to toggle source
# File lib/coinbase/wallet/client.rb, line 45
def authorize!(redirect_url, params = {})
  raise NotImplementedError
end
refresh!(params = {}) { |out, resp| ... } click to toggle source
# 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 = {}) { |out, resp| ... } click to toggle source
# 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