Class: PlaidResponse

Inherits:
Object
  • Object
show all
Includes:
Plaid::Client::Configurations
Defined in:
lib/plaid/plaid_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, message = nil) ⇒ PlaidResponse

Returns a new instance of PlaidResponse.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/plaid/plaid_response.rb', line 17

def initialize(response, message=nil)
  @http_code = response.code
  zed = PlaidObject.new(response)

  if save_full_response.eql?(true)
    @response = zed
  end

  unless message.eql?("MFA")
    @accounts = zed.accounts
    @transactions = zed.transactions
    @is_mfa_initialized = false
  else
    manage_mfa_type(zed)
    @is_mfa_initialized = true
  end

  @access_token = zed.access_token
  @message = message if message
  zed = nil
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



7
8
9
# File 'lib/plaid/plaid_response.rb', line 7

def access_token
  @access_token
end

#accountsObject (readonly)

Returns the value of attribute accounts.



7
8
9
# File 'lib/plaid/plaid_response.rb', line 7

def accounts
  @accounts
end

#http_codeObject (readonly)

Returns the value of attribute http_code.



7
8
9
# File 'lib/plaid/plaid_response.rb', line 7

def http_code
  @http_code
end

#mfa_messageObject (readonly)

Returns the value of attribute mfa_message.



7
8
9
# File 'lib/plaid/plaid_response.rb', line 7

def mfa_message
  @mfa_message
end

#transactionsObject (readonly)

Returns the value of attribute transactions.



7
8
9
# File 'lib/plaid/plaid_response.rb', line 7

def transactions
  @transactions
end

Instance Method Details

#is_mfa?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/plaid/plaid_response.rb', line 51

def is_mfa?
  @is_mfa_initialized
end

#manage_mfa_type(zed) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/plaid/plaid_response.rb', line 59

def manage_mfa_type(zed)
  @mfa_type = zed.type

  if @mfa_type.eql?("device")
    @mfa_message = zed.mfa["message"]
  elsif @mfa_type.eql?("questions")
    @questions ||= []
    zed.mfa.each do |q|
      @questions << q.question
    end
    @mfa_message = @questions.reverse.pop
  elsif @mfa_type.eql?("list")
    @mfa_modes ||= []
    @mfa_message = "There are several ways to authenticate, or it will default to your email"
    zed.mfa.each do |q|
      @mfa_modes << q
    end
  end

end

#messageObject



43
44
45
# File 'lib/plaid/plaid_response.rb', line 43

def message
  @message.eql?("MFA") ? @message + ": " + @mfa_message : @message
end

#mfa_modesObject



55
56
57
# File 'lib/plaid/plaid_response.rb', line 55

def mfa_modes
  @mfa_modes
end

#mfa_typeObject



47
48
49
# File 'lib/plaid/plaid_response.rb', line 47

def mfa_type
  @message.eql?("MFA") ? @mfa_type : "Not a response from an MFA request to a bank"
end

#raw_responseObject



39
40
41
# File 'lib/plaid/plaid_response.rb', line 39

def raw_response
  @response
end