Class: Plaid::Institution
- Inherits:
-
Object
- Object
- Plaid::Institution
- Defined in:
- lib/plaid/institution.rb
Overview
Public: A class encapsulating information about a Financial Institution supported by Plaid.
Instance Attribute Summary collapse
-
#credentials ⇒ Object
readonly
Public: The Hash with credential labels, how they are exactly named by the institution.
-
#has_mfa ⇒ Object
(also: #has_mfa?)
readonly
Public: The Boolean flag telling if the institution requires MFA.
-
#id ⇒ Object
readonly
Public: The String institution ID.
-
#mfa ⇒ Object
readonly
Public: The Hash with MFA options available.
-
#name ⇒ Object
readonly
Public: The String institution name.
-
#products ⇒ Object
readonly
Public: An Array with Symbol product names supported by the institution.
-
#type ⇒ Object
readonly
Public: The String institution shortname, or “type” per Plaid API docs.
Class Method Summary collapse
-
.all(count: 50, offset: 0, products: nil, client: nil) ⇒ Object
Public: Get information about the Financial Institutions currently supported by Plaid.
-
.get(id, client: nil) ⇒ Object
Public: Get information about a given Financial Institution.
-
.search(query: nil, product: nil, client: nil) ⇒ Object
Public: Search Financial Institutions.
-
.search_by_id(id, client: nil) ⇒ Object
Public: Lookup a Financial Institution by ID.
Instance Method Summary collapse
-
#initialize(fields) ⇒ Institution
constructor
Internal: Initialize an Institution with given fields.
-
#inspect ⇒ Object
(also: #to_s)
Public: Get a String representation of the institution.
Constructor Details
#initialize(fields) ⇒ Institution
Internal: Initialize an Institution with given fields.
37 38 39 40 41 42 43 44 45 |
# File 'lib/plaid/institution.rb', line 37 def initialize(fields) @id = fields['id'] @name = fields['name'] @type = fields['type'] @has_mfa = fields['has_mfa'] @mfa = fields['mfa'] @credentials = fields['credentials'] @products = fields['products'].map(&:to_sym) end |
Instance Attribute Details
#credentials ⇒ Object (readonly)
Public: The Hash with credential labels, how they are exactly named by the institution. E.g. “Online ID”, “password”: “Password”.
29 30 31 |
# File 'lib/plaid/institution.rb', line 29 def credentials @credentials end |
#has_mfa ⇒ Object (readonly) Also known as: has_mfa?
Public: The Boolean flag telling if the institution requires MFA.
16 17 18 |
# File 'lib/plaid/institution.rb', line 16 def has_mfa @has_mfa end |
#id ⇒ Object (readonly)
Public: The String institution ID. E.g. “5301a93ac140de84910000e0”.
6 7 8 |
# File 'lib/plaid/institution.rb', line 6 def id @id end |
#mfa ⇒ Object (readonly)
Public: The Hash with MFA options available. E.g. [“code”, “list”, “questions(3)”]. In this case you are allowed to request a list of possible MFA options, use code-based MFA and questions MFA (there are 3 questions).
25 26 27 |
# File 'lib/plaid/institution.rb', line 25 def mfa @mfa end |
#name ⇒ Object (readonly)
Public: The String institution name. E.g. “Bank of America”.
9 10 11 |
# File 'lib/plaid/institution.rb', line 9 def name @name end |
#products ⇒ Object (readonly)
Public: An Array with Symbol product names supported by the institution. E.g. [:connect, :auth, :balance, :info, :income, :risk]. See Plaid::PRODUCTS.
34 35 36 |
# File 'lib/plaid/institution.rb', line 34 def products @products end |
#type ⇒ Object (readonly)
Public: The String institution shortname, or “type” per Plaid API docs. E.g. “bofa”.
13 14 15 |
# File 'lib/plaid/institution.rb', line 13 def type @type end |
Class Method Details
.all(count: 50, offset: 0, products: nil, client: nil) ⇒ Object
Public: Get information about the Financial Institutions currently supported by Plaid.
Does a POST /institutions/all call. The result is paginated (count, offset params) and filtered by products. If the products param is specified, only institutions which support all of the products mentioned will be returned.
count - The Integer number of results to retrieve (default: 50). offset - The Integer number of results to skip forward from the
beginning of the list (default: 0).
products - The Array of product Symbols (see Plaid::PRODUCTS) or nil.
E.g. [:connect, :auth]. Default: nil.
client - The Plaid::Client instance used to connect
(default: Plaid.client).
Returns an Array of Institution instances.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/plaid/institution.rb', line 77 def self.all(count: 50, offset: 0, products: nil, client: nil) conn = Connector.new(:institutions, :all, auth: true, client: client) payload = { count: count, offset: offset } if products payload[:products] = MultiJson.encode(Array(products)) end resp = conn.post(payload) Page.new(resp['total_count'], resp['results'].map { |item| new(item) }) end |
.get(id, client: nil) ⇒ Object
Public: Get information about a given Financial Institution.
Does a GET /institutions/all/:id call.
id - the String institution ID (e.g. “5301a93ac140de84910000e0”, or
"ins_109263").
client - The Plaid::Client instance used to connect
(default: Plaid.client).
Returns an Institution instance or raises Plaid::NotFoundError if institution with given id is not found.
105 106 107 |
# File 'lib/plaid/institution.rb', line 105 def self.get(id, client: nil) new Connector.new('institutions/all', id, client: client).get end |
.search(query: nil, product: nil, client: nil) ⇒ Object
Public: Search Financial Institutions.
query - The String search query to match against the full list of
institutions. Partial matches are returned making this useful
for autocompletion purposes.
product - The Symbol product name to filter by, one of Plaid::PRODUCTS
(e.g. :info, :connect, etc.). Only valid when query is
specified. If nil, results are not filtered by product
(default: nil).
client - The Plaid::Client instance used to connect
(default: Plaid.client).
Returns an Array of SearchResultInstitution.
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/plaid/institution.rb', line 122 def self.search(query: nil, product: nil, client: nil) raise ArgumentError, 'query must be specified' \ unless query.is_a?(String) && !query.empty? payload = { q: query } payload[:p] = product.to_s if product resp = Connector.new('institutions/all', :search, client: client).get(payload) resp.map { |inst| SearchResultInstitution.new(inst) } end |
.search_by_id(id, client: nil) ⇒ Object
Public: Lookup a Financial Institution by ID.
Does a GET /institutions/all/search call with id param.
id - the String institution ID (e.g. ‘bofa’). client - The Plaid::Client instance used to connect
(default: Plaid.client).
Returns an SearchResultInstitution instance or nil if institution with given id is not found.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/plaid/institution.rb', line 143 def self.search_by_id(id, client: nil) client ||= Plaid.client # If client_id is set, use it, no authentication otherwise auth = client && !client.client_id.nil? conn = Connector.new('institutions/all', :search, auth: auth, client: client) resp = conn.get(id: id) case resp when Hash SearchResultInstitution.new resp when Array raise 'Non-empty array returned by /institutions/all/search with id' \ unless resp.empty? nil else raise 'Unexpected result returned by /institutions/all/search with id: ' \ "#{resp.inspect}" end end |
Instance Method Details
#inspect ⇒ Object Also known as: to_s
Public: Get a String representation of the institution.
Returns a String.
50 51 52 53 |
# File 'lib/plaid/institution.rb', line 50 def inspect "#<Plaid::Institution id=#{id.inspect}, type=#{type.inspect}, " \ "name=#{name.inspect}>" end |