Class: DwollaV2::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/dwolla_v2/auth.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, params = {}) ⇒ Auth

Returns a new instance of Auth.



15
16
17
18
19
20
21
22
23
# File 'lib/dwolla_v2/auth.rb', line 15

def initialize client, params = {}
  @client = client
  @redirect_uri = params[:redirect_uri]
  @scope = params[:scope]
  @state = params[:state]
  @verified_account = params[:verified_account]
  @dwolla_landing = params[:dwolla_landing]
  freeze
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/dwolla_v2/auth.rb', line 3

def client
  @client
end

#dwolla_landingObject (readonly)

Returns the value of attribute dwolla_landing.



3
4
5
# File 'lib/dwolla_v2/auth.rb', line 3

def dwolla_landing
  @dwolla_landing
end

#redirect_uriObject (readonly)

Returns the value of attribute redirect_uri.



3
4
5
# File 'lib/dwolla_v2/auth.rb', line 3

def redirect_uri
  @redirect_uri
end

#scopeObject (readonly)

Returns the value of attribute scope.



3
4
5
# File 'lib/dwolla_v2/auth.rb', line 3

def scope
  @scope
end

#stateObject (readonly)

Returns the value of attribute state.



3
4
5
# File 'lib/dwolla_v2/auth.rb', line 3

def state
  @state
end

#verified_accountObject (readonly)

Returns the value of attribute verified_account.



3
4
5
# File 'lib/dwolla_v2/auth.rb', line 3

def 
  @verified_account
end

Class Method Details

.client(client, params = {}) ⇒ Object



5
6
7
# File 'lib/dwolla_v2/auth.rb', line 5

def self.client client, params = {}
  request_token client, {:grant_type => :client_credentials}.merge(params)
end

.refresh(client, token, params = {}) ⇒ Object



9
10
11
12
13
# File 'lib/dwolla_v2/auth.rb', line 9

def self.refresh client, token, params = {}
  refresh_token = token.respond_to?(:refresh_token) ? token.refresh_token : token[:refresh_token]
  raise ArgumentError.new "invalid refresh_token" unless refresh_token.is_a? String
  request_token client, {:grant_type => :refresh_token, :refresh_token => refresh_token}.merge(params)
end

Instance Method Details

#callback(params) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/dwolla_v2/auth.rb', line 29

def callback params
  raise ArgumentError.new "state does not match" if params[:state] != state
  Error.raise! params if params[:error]
  raise ArgumentError.new "code is required" unless params[:code].is_a? String
  params = {:code => params[:code], :redirect_uri => redirect_uri}.reject {|k,v| v.nil? }
  self.class.request_token client, {:grant_type => :authorization_code}.merge(params)
end

#urlObject



25
26
27
# File 'lib/dwolla_v2/auth.rb', line 25

def url
  "#{client.auth_url}?#{URI.encode_www_form(query)}"
end