class DwollaV2::Client
Constants
- ENVIRONMENTS
Attributes
auths[R]
id[R]
key[R]
secret[R]
tokens[R]
Public Class Methods
new(**opts) { |self| ... }
click to toggle source
# File lib/dwolla_v2/client.rb, line 23 def initialize **opts opts[:id] ||= opts[:key] raise ArgumentError.new ":key is required" unless opts[:id].is_a? String raise ArgumentError.new ":secret is required" unless opts[:secret].is_a? String @id = opts[:id] @secret = opts[:secret] self.environment = opts[:environment] if opts.has_key?(:environment) yield self if block_given? conn @auths = Portal.new self, Auth @tokens = Portal.new self, Token @token_manager = TokenManager.new(self) freeze end
Public Instance Methods
api_url()
click to toggle source
# File lib/dwolla_v2/client.rb, line 96 def api_url ENVIRONMENTS[environment][:api_url] end
auth(params = {})
click to toggle source
# File lib/dwolla_v2/client.rb, line 73 def auth(params = {}) DwollaV2::Auth.new(self, params) end
auth_url()
click to toggle source
# File lib/dwolla_v2/client.rb, line 88 def auth_url ENVIRONMENTS[environment][:auth_url] end
conn()
click to toggle source
# File lib/dwolla_v2/client.rb, line 59 def conn @conn ||= Faraday.new do |f| f.request :authorization, :basic, id, secret f.request :url_encoded f.use SetUserAgent f.use HandleErrors f.use DeepSuperHasherizeResponseBody f.use DeepParseIso8601ResponseBody f.response :json, :content_type => /\bjson$/ faraday.call(f) if faraday f.adapter Faraday.default_adapter unless faraday end end
environment(env = nil)
click to toggle source
# File lib/dwolla_v2/client.rb, line 44 def environment env = nil self.environment = env unless env.nil? @environment || :production end
environment=(env)
click to toggle source
# File lib/dwolla_v2/client.rb, line 38 def environment= env env = :"#{env}" raise ArgumentError.new "invalid environment" unless ENVIRONMENTS.has_key? env @environment = env end
faraday(&block)
click to toggle source
# File lib/dwolla_v2/client.rb, line 54 def faraday &block @faraday = block if block @faraday end
inspect()
click to toggle source
# File lib/dwolla_v2/client.rb, line 100 def inspect Util.pretty_inspect self.class.name, key: id, environment: environment end
on_grant(&callback)
click to toggle source
# File lib/dwolla_v2/client.rb, line 49 def on_grant &callback @on_grant = callback if callback @on_grant end
refresh_token(params = {})
click to toggle source
# File lib/dwolla_v2/client.rb, line 77 def refresh_token(params = {}) unless params.is_a?(Hash) && params.has_key?(:refresh_token) raise ArgumentError.new(":refresh_token is required") end auths.refresh(params, params) end
token(params = {})
click to toggle source
# File lib/dwolla_v2/client.rb, line 84 def token(params = {}) tokens.new(params) end
token_url()
click to toggle source
# File lib/dwolla_v2/client.rb, line 92 def token_url ENVIRONMENTS[environment][:token_url] end
Private Instance Methods
current_token()
click to toggle source
# File lib/dwolla_v2/client.rb, line 106 def current_token @token_manager.get_token end