class DwollaV2::Token

Constants

HTTP_METHODS

Attributes

access_token[R]
account_id[R]
app_id[R]
client[R]
expires_in[R]
refresh_token[R]
scope[R]

Public Class Methods

new(client, params) click to toggle source
# File lib/dwolla_v2/token.rb, line 12
def initialize client, params
  @client = client
  @access_token  = get_param params, :access_token
  @refresh_token = get_param params, :refresh_token
  @expires_in    = get_param params, :expires_in
  @scope         = get_param params, :scope
  @app_id        = get_param params, :app_id
  @account_id    = get_param params, :account_id
  conn
  freeze
end

Private Class Methods

full_url(client, path) click to toggle source
# File lib/dwolla_v2/token.rb, line 78
def self.full_url client, path
  path = path[:_links][:self][:href] if path.is_a? Hash
  path = path.sub /^https?:\/\/[^\/]*/, ""
  if path.start_with? client.api_url
    path
  elsif path.start_with? "/"
    client.api_url + path
  else
    "#{client.api_url}/#{path}"
  end
end

Public Instance Methods

[](key) click to toggle source
# File lib/dwolla_v2/token.rb, line 24
def [] key
  instance_variable_get :"@#{key}"
end
inspect() click to toggle source
# File lib/dwolla_v2/token.rb, line 46
def inspect
  Util.pretty_inspect self.class.name,
    client: client, access_token: access_token, refresh_token: refresh_token,
    expires_in: expires_in, scope: scope, app_id: app_id, account_id: account_id
end
stringify_keys() click to toggle source
# File lib/dwolla_v2/token.rb, line 28
def stringify_keys
  {
    "access_token"  => access_token,
    "refresh_token" => refresh_token,
    "expires_in"    => expires_in,
    "scope"         => scope,
    "app_id"        => app_id,
    "account_id"    => account_id
  }.reject {|k,v| v.nil? }
end

Private Instance Methods

conn() click to toggle source
# File lib/dwolla_v2/token.rb, line 54
def conn
  @conn ||= Faraday.new do |f|
    f.request :authorization, :Bearer, access_token if access_token
    f.headers[:accept] = "application/vnd.dwolla.v1.hal+json"
    f.request :multipart
    f.request :json
    f.use SetUserAgent
    f.use HandleErrors
    f.use DeepSuperHasherizeResponseBody
    f.use DeepParseIso8601ResponseBody
    f.response :json, :content_type => /\bjson$/
    client.faraday.call(f) if client.faraday
    f.adapter Faraday.default_adapter unless client.faraday
  end
end
get_param(params, key) click to toggle source
# File lib/dwolla_v2/token.rb, line 70
def get_param params, key
  if params.respond_to? key
    params.public_send key
  else
    params[key]
  end
end