Class: SynapsePayRest::Institution

Inherits:
Object
  • Object
show all
Defined in:
lib/synapse_pay_rest/models/institution/institution.rb

Overview

Represents an institution record and holds methods for getting institution instances from API calls. This is built on top of the SynapsePayRest::Institution class and is intended to make it easier to use the API without knowing payload formats or knowledge of REST.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Institution

Note:

Do not call directly. Use other class method to instantiate via API action.

Returns a new instance of Institution.



45
46
47
# File 'lib/synapse_pay_rest/models/institution/institution.rb', line 45

def initialize(**options)
  options.each { |key, value| instance_variable_set("@#{key}", value) }
end

Instance Attribute Details

#bank_codeObject (readonly)

Returns the value of attribute bank_code.



8
9
10
# File 'lib/synapse_pay_rest/models/institution/institution.rb', line 8

def bank_code
  @bank_code
end

#bank_nameObject (readonly)

Returns the value of attribute bank_name.



8
9
10
# File 'lib/synapse_pay_rest/models/institution/institution.rb', line 8

def bank_name
  @bank_name
end

#clientObject (readonly)

Returns the value of attribute client.



8
9
10
# File 'lib/synapse_pay_rest/models/institution/institution.rb', line 8

def client
  @client
end

#featuresObject (readonly)

Returns the value of attribute features.



8
9
10
# File 'lib/synapse_pay_rest/models/institution/institution.rb', line 8

def features
  @features
end

#forgotten_passwordObject (readonly)

Returns the value of attribute forgotten_password.



8
9
10
# File 'lib/synapse_pay_rest/models/institution/institution.rb', line 8

def forgotten_password
  @forgotten_password
end

#is_activeObject (readonly)

Returns the value of attribute is_active.



8
9
10
# File 'lib/synapse_pay_rest/models/institution/institution.rb', line 8

def is_active
  @is_active
end

#logoObject (readonly)

Returns the value of attribute logo.



8
9
10
# File 'lib/synapse_pay_rest/models/institution/institution.rb', line 8

def 
  @logo
end

#tx_history_monthsObject (readonly)

Returns the value of attribute tx_history_months.



8
9
10
# File 'lib/synapse_pay_rest/models/institution/institution.rb', line 8

def tx_history_months
  @tx_history_months
end

Class Method Details

.all(client:) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
33
# File 'lib/synapse_pay_rest/models/institution/institution.rb', line 29

def all(client:)
  raise ArgumentError, 'client must be a SynapsePayRest::Client' unless client.is_a?(Client)
  response = client.institutions.get()
  multiple_from_response(client, response['banks'])
end

.from_response(client, response) ⇒ Object

Note:

Shouldn’t need to call this directly.

Creates an Institution from a response hash.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/synapse_pay_rest/models/institution/institution.rb', line 15

def from_response(client, response)
  args = {
    client:                       client,
    bank_code:                    response['bank_code'],
    bank_name:                    response['bank_name'],
    features:                     response['features'],
    forgotten_password:           response['forgotten_password'],
    is_active:                    response['is_active'],
    logo:                         response['logo'],
    tx_history_months:            response['tx_history_months']
  }
  self.new(args)
end

.multiple_from_response(client, response) ⇒ Object

Calls from_response on each member of a response collection.



36
37
38
39
# File 'lib/synapse_pay_rest/models/institution/institution.rb', line 36

def multiple_from_response(client, response)
  return [] if response.empty?
  response.map { |institution_data| from_response(client.dup, institution_data)}
end