Class: DwollaV2::Client
- Inherits:
-
Object
- Object
- DwollaV2::Client
- Defined in:
- lib/dwolla_v2/client.rb
Constant Summary collapse
- ENVIRONMENTS =
{ :production => { :auth_url => "https://www.dwolla.com/oauth/v2/authenticate", :token_url => "https://www.dwolla.com/oauth/v2/token", :api_url => "https://api.dwolla.com" }, :sandbox => { :auth_url => "https://sandbox.dwolla.com/oauth/v2/authenticate", :token_url => "https://sandbox.dwolla.com/oauth/v2/token", :api_url => "https://api-sandbox.dwolla.com" } }
Instance Attribute Summary collapse
-
#auths ⇒ Object
readonly
Returns the value of attribute auths.
-
#id ⇒ Object
(also: #key)
readonly
Returns the value of attribute id.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Instance Method Summary collapse
- #api_url ⇒ Object
- #auth_url ⇒ Object
- #conn ⇒ Object
- #environment(env = nil) ⇒ Object
- #environment=(env) ⇒ Object
- #faraday(&block) ⇒ Object
-
#initialize(opts) {|_self| ... } ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
- #on_grant(&callback) ⇒ Object
- #token_url ⇒ Object
Constructor Details
#initialize(opts) {|_self| ... } ⇒ Client
Returns a new instance of Client.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dwolla_v2/client.rb', line 19 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] yield self if block_given? conn @auths = Portal.new self, Auth @tokens = Portal.new self, Token freeze end |
Instance Attribute Details
#auths ⇒ Object (readonly)
Returns the value of attribute auths.
16 17 18 |
# File 'lib/dwolla_v2/client.rb', line 16 def auths @auths end |
#id ⇒ Object (readonly) Also known as: key
Returns the value of attribute id.
16 17 18 |
# File 'lib/dwolla_v2/client.rb', line 16 def id @id end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
16 17 18 |
# File 'lib/dwolla_v2/client.rb', line 16 def secret @secret end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
16 17 18 |
# File 'lib/dwolla_v2/client.rb', line 16 def tokens @tokens end |
Instance Method Details
#api_url ⇒ Object
75 76 77 |
# File 'lib/dwolla_v2/client.rb', line 75 def api_url ENVIRONMENTS[environment][:api_url] end |
#auth_url ⇒ Object
67 68 69 |
# File 'lib/dwolla_v2/client.rb', line 67 def auth_url ENVIRONMENTS[environment][:auth_url] end |
#conn ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/dwolla_v2/client.rb', line 53 def conn @conn ||= Faraday.new do |f| f.request :basic_auth, 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) ⇒ Object
38 39 40 41 |
# File 'lib/dwolla_v2/client.rb', line 38 def environment env = nil self.environment = env unless env.nil? @environment || :production end |
#environment=(env) ⇒ Object
32 33 34 35 36 |
# File 'lib/dwolla_v2/client.rb', line 32 def environment= env env = :"#{env}" raise ArgumentError.new "invalid environment" unless ENVIRONMENTS.has_key? env @environment = env end |
#faraday(&block) ⇒ Object
48 49 50 51 |
# File 'lib/dwolla_v2/client.rb', line 48 def faraday &block @faraday = block if block @faraday end |
#inspect ⇒ Object
79 80 81 |
# File 'lib/dwolla_v2/client.rb', line 79 def inspect Util.pretty_inspect self.class.name, key: id, secret: secret, environment: environment end |
#on_grant(&callback) ⇒ Object
43 44 45 46 |
# File 'lib/dwolla_v2/client.rb', line 43 def on_grant &callback @on_grant = callback if callback @on_grant end |
#token_url ⇒ Object
71 72 73 |
# File 'lib/dwolla_v2/client.rb', line 71 def token_url ENVIRONMENTS[environment][:token_url] end |