Sha256: 7ead51743dcae2fabb934f89d206f46ccb83648e9ca8473b53489d313bef60ec

Contents?: true

Size: 1.65 KB

Versions: 3

Compression:

Stored size: 1.65 KB

Contents

class PlaidResponse
  include Plaid::Client::Configurations

  require 'plaid/plaid_object'
  require 'plaid/client/configuration'

  attr_reader :http_code, :mfa_message, :accounts, :transactions, :access_token

  @response = nil
  @message = "N/A"
  @mfa_type
  @mfa_message
  @questions = nil
  @mfa_modes = nil
  @is_mfa_initialized = false

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

    if save_full_response.eql?(save_full_response)
      @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

  def raw_response
    @response
  end

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

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

  def is_mfa?
    @is_mfa_initialized
  end

  def mfa_modes
    @mfa_modes
  end

  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

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
plaid-kilt-0.5.4 lib/plaid/plaid_response.rb
plaid-kilt-0.5.2 lib/plaid/plaid_response.rb
plaid-kilt-0.5.1 lib/plaid/plaid_response.rb