Class: Plaid::Client::Base

Inherits:
Object
  • Object
show all
Includes:
HTTParty, Bodies, Configurations, Logins
Defined in:
lib/plaid/client/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Bodies

#body, #body_delete_user, #body_entity, #body_init_user, #body_mfa, #body_mfa_mode, #body_mfa_webhook, #body_original, #body_retrieve, #body_test, #body_update_credentials, #credentials, #options

Methods included from Logins

#connect, #connect_delete_user, #connect_filter_response, #connect_init_user, #connect_step, #connect_step_specify_mode, #connect_step_webhook, #connect_update_credentials

Constructor Details

#initialize(user, e_mail, pass_word, institution, access_token = nil) ⇒ Base

Returns a new instance of Base.



25
26
27
28
29
30
31
32
# File 'lib/plaid/client/client.rb', line 25

def initialize(user, e_mail, pass_word, institution, access_token=nil)
  self.username = user
  self.email = e_mail
  self.password = pass_word
  self.institution = institution
  self.access_token = access_token unless access_token.blank?
  self.mfa_response ||= []
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



5
6
7
# File 'lib/plaid/client/client.rb', line 5

def access_token
  @access_token
end

#emailObject

Returns the value of attribute email.



5
6
7
# File 'lib/plaid/client/client.rb', line 5

def email
  @email
end

#endpointObject

Returns the value of attribute endpoint.



5
6
7
# File 'lib/plaid/client/client.rb', line 5

def endpoint
  @endpoint
end

#institutionObject

Returns the value of attribute institution.



5
6
7
# File 'lib/plaid/client/client.rb', line 5

def institution
  @institution
end

#is_mfa_initializedObject

Returns the value of attribute is_mfa_initialized.



5
6
7
# File 'lib/plaid/client/client.rb', line 5

def is_mfa_initialized
  @is_mfa_initialized
end

#mfa_messageObject

Returns the value of attribute mfa_message.



5
6
7
# File 'lib/plaid/client/client.rb', line 5

def mfa_message
  @mfa_message
end

#mfa_responseObject

Returns the value of attribute mfa_response.



5
6
7
# File 'lib/plaid/client/client.rb', line 5

def mfa_response
  @mfa_response
end

#mfa_typeObject

Returns the value of attribute mfa_type.



5
6
7
# File 'lib/plaid/client/client.rb', line 5

def mfa_type
  @mfa_type
end

#passwordObject

Returns the value of attribute password.



5
6
7
# File 'lib/plaid/client/client.rb', line 5

def password
  @password
end

#secretObject

Returns the value of attribute secret.



5
6
7
# File 'lib/plaid/client/client.rb', line 5

def secret
  @secret
end

#usernameObject

Returns the value of attribute username.



5
6
7
# File 'lib/plaid/client/client.rb', line 5

def username
  @username
end

Instance Method Details

#handle(response) ⇒ Object

generic method for handling the structure of the response. Only creates an error object if there is an error (business error) from Plaid.com. Yields to the block with calling function



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/plaid/client/client.rb', line 45

def handle(response)
  if response.code.eql? 200
    self.mfa_type = nil
    self.mfa_message = nil
    self.is_mfa_initialized = false
    yield(response) if block_given?
  elsif response.code.eql? 201        #mfa
    mfa_201 = PlaidResponse.new(response, "MFA")
    self.access_token = mfa_201.access_token
    self.mfa_type = mfa_201.raw_response.type
    self.mfa_response << mfa_201
    self.mfa_message = mfa_201.message
    self.is_mfa_initialized = mfa_201.is_mfa?
    mfa_201
  else
    PlaidError.new(response, "Error")
  end
end

#is_mfa?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/plaid/client/client.rb', line 71

def is_mfa?
  @is_mfa_initialized
end

#plaid_response_codesObject



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/plaid/client/client.rb', line 75

def plaid_response_codes
  {
    200 => "Success",
    201 => "MFA Required",
    400 => "Bad Request",
    401 => "Unauthorized",
    402 => "Request Failed",
    404 => "Cannot be Found",
    500 => "Server Error"
  }
end

#secrets(client_id, secret) ⇒ Object

for testing through IRB



65
66
67
68
69
# File 'lib/plaid/client/client.rb', line 65

def secrets(client_id, secret)
  self.client_id = client_id
  self.secret = secret
  "Set"
end

#settingsObject



34
35
36
37
38
39
40
41
42
# File 'lib/plaid/client/client.rb', line 34

def settings
  puts "Base URI: " + endpoint.to_s
  puts "Cert: " + certpath.to_s
  puts "User: " + self.username.to_s
  puts "Email: " + self.email.to_s
  puts "Plaid Client_id: " + self.client_id.to_s
  puts "Webhook address: " + webhook_address
  puts "Save full response: " + save_full_response.to_s
end