Sha256: a358cf01584536e6649676d909c9b9655929fa8ae13370cbf234bb8c295310f4

Contents?: true

Size: 1.72 KB

Versions: 2

Compression:

Stored size: 1.72 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?(true)
      @response = zed
    end

    unless message.eql?("MFA")
      @accounts = zed.accounts if zed.class.method_defined? :accounts
      @transactions = zed.transactions if zed.class.method_defined? :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

2 entries across 2 versions & 1 rubygems

Version Path
plaid-kilt-0.7.7 lib/plaid/plaid_response.rb
plaid-kilt-0.7.6 lib/plaid/plaid_response.rb