plaid 4.1.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,41 +1,33 @@
1
1
  module Plaid
2
2
  # Public: Class used to call the Balance product.
3
- class Balance
4
- def initialize(client)
5
- @client = client
6
- end
7
-
3
+ class Balance < BaseProduct
8
4
  # Public: Get information about all available balances.
9
5
  #
10
- # Does a POST /accounts/balance/get call to get real-time balance information for all
11
- # accounts associated with the access_token's item
6
+ # Does a POST /accounts/balance/get call to get real-time balance
7
+ # information for all accounts associated with the access_token's item.
12
8
  #
13
- # access_token - access_token who's item to fetch balances for
14
- # account_ids - Specific account ids to fetch balances for (optional)
15
- # options - Additional options to be merged into API request
9
+ # access_token - The String access_token for the item to fetch balances
10
+ # for.
11
+ # account_ids - The Array with specific account IDs to fetch balances for
12
+ # (optional).
13
+ # options - Additional options to be merged into the request
14
+ # (optional).
16
15
  #
17
- # Returns a parsed JSON of balance response
16
+ # Returns the AccountsResponse object with accounts information.
18
17
  def get(access_token, account_ids: nil, options: nil)
19
- options_payload = {}
20
- options_payload[:account_ids] = account_ids unless account_ids.nil?
21
- options_payload = options_payload.merge(options) unless options.nil?
22
-
23
- payload = { access_token: access_token,
24
- options: options_payload }
25
- @client.post_with_auth('accounts/balance/get', payload)
18
+ post_with_auth 'accounts/balance/get',
19
+ AccountsResponse,
20
+ build_payload(access_token,
21
+ account_ids: account_ids,
22
+ options: options)
26
23
  end
27
24
  end
28
25
 
29
26
  # Public: Class used to call the Accounts product.
30
- class Accounts
31
- # Public: Memoized class instance to make requests from Plaid::Balance
32
- def balance
33
- @balance ||= Plaid::Balance.new(@client)
34
- end
35
-
36
- def initialize(client)
37
- @client = client
38
- end
27
+ class Accounts < BaseProduct
28
+ ##
29
+ # Public: The Plaid::Balance product accessor.
30
+ subproduct :balance
39
31
 
40
32
  # Public: Get information about all available accounts.
41
33
  #
@@ -46,15 +38,26 @@ module Plaid
46
38
  # account_ids - Specific account ids to fetch accounts for (optional)
47
39
  # options - Additional options to be merged into API request
48
40
  #
49
- # Returns a parsed JSON of account information
41
+ # Returns the AccountsResponse object with accounts information.
50
42
  def get(access_token, account_ids: nil, options: nil)
51
- options_payload = {}
52
- options_payload[:account_ids] = account_ids unless account_ids.nil?
53
- options_payload = options_payload.merge(options) unless options.nil?
54
-
55
- payload = { access_token: access_token,
56
- options: options_payload }
57
- @client.post_with_auth('accounts/get', payload)
43
+ post_with_auth 'accounts/get',
44
+ AccountsResponse,
45
+ build_payload(access_token,
46
+ account_ids: account_ids,
47
+ options: options)
58
48
  end
59
49
  end
50
+
51
+ # Public: The response wrapper for /accounts/get and /accounts/balance/get.
52
+ class AccountsResponse < Models::BaseResponse
53
+ ##
54
+ # :attr_reader:
55
+ # Public: The item: Plaid::Models::Item.
56
+ property :item, coerce: Models::Item
57
+
58
+ ##
59
+ # :attr_reader:
60
+ # Public: The list of accounts: Array of Plaid::Models::Account.
61
+ property :accounts, coerce: Array[Models::Account]
62
+ end
60
63
  end
@@ -1,29 +1,42 @@
1
1
  module Plaid
2
2
  # Public: Class used to call the Auth product.
3
- class Auth
4
- def initialize(client)
5
- @client = client
6
- end
7
-
3
+ class Auth < BaseProduct
8
4
  # Public: Get information about account and routing numbers for checking
9
- # and savings accounts
5
+ # and savings accounts.
10
6
  #
11
- # Does a POST /auth/get call which returns high level account information along with
12
- # account and routing numbers for checking and savings accounts
7
+ # Does a POST /auth/get call which returns high level account information
8
+ # along with account and routing numbers for checking and savings
9
+ # accounts.
13
10
  #
14
- # access_token - access_token who's item to fetch Auth for
15
- # account_ids - Specific account ids to fetch numbers for (optional)
16
- # options - Additional options to merge into API request
11
+ # access_token - access_token who's item to fetch Auth for.
12
+ # account_ids - Specific account ids to fetch numbers for (optional).
13
+ # options - Additional options to merge into API request.
17
14
  #
18
- # Returns a parsed JSON of Auth information
15
+ # Returns AuthResponse.
19
16
  def get(access_token, account_ids: nil, options: nil)
20
- options_payload = {}
21
- options_payload[:account_ids] = account_ids unless account_ids.nil?
22
- options_payload = options_payload.merge(options) unless options.nil?
23
-
24
- payload = { access_token: access_token,
25
- options: options_payload }
26
- @client.post_with_auth('auth/get', payload)
17
+ post_with_auth 'auth/get',
18
+ AuthResponse,
19
+ build_payload(access_token,
20
+ account_ids: account_ids,
21
+ options: options)
27
22
  end
28
23
  end
24
+
25
+ # Public: Response wrapper for /accounts/get and /accounts/balance/get
26
+ class AuthResponse < Models::BaseResponse
27
+ ##
28
+ # :attr_reader:
29
+ # Public: The list of accounts: Array of Plaid::Models::Account.
30
+ property :accounts, coerce: Array[Models::Account]
31
+
32
+ ##
33
+ # :attr_reader:
34
+ # Public: The list of account numbers: Array of Plaid::Models::Number.
35
+ property :numbers, coerce: Array[Models::Number]
36
+
37
+ ##
38
+ # :attr_reader:
39
+ # Public: The item: Plaid::Models::Item.
40
+ property :item, coerce: Models::Item
41
+ end
29
42
  end
@@ -0,0 +1,69 @@
1
+ module Plaid
2
+ # Internal: Support for subproduct metaprogramming
3
+ #
4
+ # Allows to write
5
+ #
6
+ # class SomeProduct
7
+ # subproduct :cool, Plaid::Cool
8
+ # end
9
+ #
10
+ # You may even skip the class part:
11
+ #
12
+ # class SomeProduct
13
+ # subproduct :foo_bar
14
+ # end
15
+ #
16
+ # will use Plaid::FooBar.
17
+ module SubproductMixin
18
+ def subproduct(name, klass = nil)
19
+ unless klass
20
+ class_name = name.to_s.split('_').map(&:capitalize).join
21
+ klass = Plaid.const_get(class_name)
22
+ end
23
+
24
+ define_method(name) do
25
+ ivar = "@#{name}"
26
+
27
+ if instance_variable_defined?(ivar)
28
+ instance_variable_get(ivar)
29
+ else
30
+ instance_variable_set(ivar, klass.new(client))
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ # Internal: The base class for all client products
37
+ class BaseProduct
38
+ def initialize(client)
39
+ @client = client
40
+ end
41
+
42
+ attr_reader :client
43
+
44
+ extend SubproductMixin
45
+
46
+ protected
47
+
48
+ # Internal: Build a simple payload with access_token, options, and
49
+ # account_ids.
50
+ def build_payload(access_token, account_ids: nil, options: nil)
51
+ options_payload = {}
52
+ options_payload[:account_ids] = account_ids unless account_ids.nil?
53
+ options_payload.merge!(options) unless options.nil?
54
+
55
+ { access_token: access_token,
56
+ options: options_payload }
57
+ end
58
+
59
+ # Internal: Do a POST to API and capture it into a response object.
60
+ def post_with_auth(path, response_class, payload)
61
+ response_class.new(client.post_with_auth(path, payload))
62
+ end
63
+
64
+ # Internal: Do a POST to API and capture it into a response object.
65
+ def post_with_public_key(path, response_class, payload)
66
+ response_class.new(client.post_with_public_key(path, payload))
67
+ end
68
+ end
69
+ end
@@ -1,18 +1,21 @@
1
1
  module Plaid
2
2
  # Public: Class used to call the Categories product.
3
- class Categories
4
- def initialize(client)
5
- @client = client
6
- end
7
-
3
+ class Categories < BaseProduct
8
4
  # Public: Get information about all Plaid categories
9
5
  #
10
6
  # Does a POST /categories/get call to retrieve a list of all categories.
11
7
  #
12
- # Returns a parsed JSON of a list of categories
8
+ # Returns the CategoriesResponse object with a list of categories.
13
9
  def get
14
- payload = {}
15
- @client.post('categories/get', payload)
10
+ CategoriesResponse.new(client.post('categories/get', {}))
16
11
  end
17
12
  end
13
+
14
+ # Public: Response wrapper for /categories/get.
15
+ class CategoriesResponse < Models::BaseResponse
16
+ ##
17
+ # :attr_reader:
18
+ # Public: Categories: Array of Plaid::Models::Category.
19
+ property :categories, coerce: Array[Models::Category]
20
+ end
18
21
  end
@@ -1,28 +1,40 @@
1
1
  module Plaid
2
2
  # Public: Class used to call the CreditDetails product.
3
- class CreditDetails
4
- def initialize(client)
5
- @client = client
6
- end
7
-
8
- # Public: Get information about all available credit_details
3
+ class CreditDetails < BaseProduct
4
+ # Public: Get information about all available credit_details.
9
5
  #
10
- # Does a POST /credit_details/get call which fetches credit details associated with
11
- # and access_token's item
6
+ # Does a POST /credit_details/get call which fetches credit details
7
+ # associated with an access_token's item.
12
8
  #
13
- # access_token - access_token who's item to fetch credit_details for
14
- # account_ids - Specific account ids to fetch credit_details for (optional)
9
+ # access_token - access_token of an item to fetch credit details for.
10
+ # account_ids - Specific account ids to fetch credit details for
11
+ # (optional).
15
12
  #
16
- # Returns a parsed JSON of credit_details information
13
+ # Returns the CreditDetailsResponse object with credit details info.
17
14
  def get(access_token, account_ids: nil)
18
- options_payload = {}
19
- options_payload[:account_ids] = account_ids unless account_ids.nil?
20
- payload = {
21
- access_token: access_token,
22
- options: options_payload
23
- }
24
-
25
- @client.post_with_auth('credit_details/get', payload)
15
+ post_with_auth 'credit_details/get',
16
+ CreditDetailsResponse,
17
+ build_payload(access_token,
18
+ account_ids: account_ids)
26
19
  end
27
20
  end
21
+
22
+ # Public: Response wrapper for /credit_details/get.
23
+ class CreditDetailsResponse < Models::BaseResponse
24
+ ##
25
+ # :attr_reader:
26
+ # Public: The list of accounts: Array of Plaid::Models::Account.
27
+ property :accounts, coerce: Array[Models::Account]
28
+
29
+ ##
30
+ # :attr_reader:
31
+ # Public: The list of credit details: Array of
32
+ # Plaid::Models::CreditDetails.
33
+ property :credit_details, coerce: Array[Models::CreditDetails]
34
+
35
+ ##
36
+ # :attr_reader:
37
+ # Public: The item: Plaid::Models::Item.
38
+ property :item, coerce: Models::Item
39
+ end
28
40
  end
@@ -1,20 +1,36 @@
1
1
  module Plaid
2
2
  # Public: Class used to call the Identity product.
3
- class Identity
4
- def initialize(client)
5
- @client = client
6
- end
7
-
8
- # Public: Get Identity information
3
+ class Identity < BaseProduct
4
+ # Public: Get Identity information.
9
5
  #
10
- # Does a POST /identity/get call to retrieve all info for a given access_token's item
6
+ # Does a POST /identity/get call to retrieve all info for a given
7
+ # access_token's item.
11
8
  #
12
- # access_token - access_token who's item to fetch Identity data for
9
+ # access_token - access_token who's item to fetch Identity data for.
13
10
  #
14
- # Returns a parsed JSON of Identity information
11
+ # Returns the IdentityResponse object with Identity info.
15
12
  def get(access_token)
16
- payload = { access_token: access_token }
17
- @client.post_with_auth('identity/get', payload)
13
+ post_with_auth 'identity/get',
14
+ IdentityResponse,
15
+ access_token: access_token
18
16
  end
19
17
  end
18
+
19
+ # Public: Response for /identity/get.
20
+ class IdentityResponse < Models::BaseResponse
21
+ ##
22
+ # :attr_reader:
23
+ # Public: The list of accounts: Array of Plaid::Models::Account.
24
+ property :accounts, coerce: Array[Models::Account]
25
+
26
+ ##
27
+ # :attr_reader:
28
+ # Public: Identity information: Plaid::Models::Identity.
29
+ property :identity, coerce: Models::Identity
30
+
31
+ ##
32
+ # :attr_reader:
33
+ # Public: The item: Plaid::Models::Item.
34
+ property :item, coerce: Models::Item
35
+ end
20
36
  end
@@ -1,20 +1,31 @@
1
1
  module Plaid
2
2
  # Public: Class used to call the Income product.
3
- class Income
4
- def initialize(client)
5
- @client = client
6
- end
7
-
8
- # Public: Get information about user incomes
3
+ class Income < BaseProduct
4
+ # Public: Get information about user incomes.
9
5
  #
10
- # Does a POST /income/get call which returns income info for an access_tokeni's item
6
+ # Does a POST /income/get call which returns income info for an
7
+ # access_token's item.
11
8
  #
12
- # access_token - access_token who's item to fetch income for
9
+ # access_token - access_token whose item to fetch income for.
13
10
  #
14
- # Returns a parsed JSON of income information
11
+ # Returns the IncomeResponse object with Income info.
15
12
  def get(access_token)
16
- payload = { access_token: access_token }
17
- @client.post_with_auth('income/get', payload)
13
+ post_with_auth 'income/get',
14
+ IncomeResponse,
15
+ access_token: access_token
18
16
  end
19
17
  end
18
+
19
+ # Public: Income product response.
20
+ class IncomeResponse < Models::BaseResponse
21
+ ##
22
+ # :attr_reader:
23
+ # Public: The item: Plaid::Models::Item.
24
+ property :item, coerce: Models::Item
25
+
26
+ ##
27
+ # :attr_reader:
28
+ # Public: Income information: Plaid::Models::Income.
29
+ property :income, coerce: Models::Income
30
+ end
20
31
  end
@@ -1,54 +1,76 @@
1
1
  module Plaid
2
2
  # Public: Class used to call the Institutions product.
3
- class Institutions
4
- def initialize(client)
5
- @client = client
6
- end
7
-
8
- # Public: Get information about Plaid institutions
3
+ class Institutions < BaseProduct
4
+ # Public: Get information about Plaid institutions.
9
5
  #
10
- # Does a POST /institutions/get call pulls a list of supported Plaid institutions
11
- # with the information for each institution
6
+ # Does a POST /institutions/get call pulls a list of supported Plaid
7
+ # institutions with the information for each institution.
12
8
  #
13
- # count - Amount of institutions to pull
14
- # offset - Offset to start pulling institutions
15
- # options - Options for filtering institutions
9
+ # count - Amount of institutions to pull.
10
+ # offset - Offset to start pulling institutions.
11
+ # options - Options for filtering institutions.
16
12
  #
17
- # Returns a parsed JSON of listed institution information
13
+ # Returns a MultipleInstitutionsResponse instance.
18
14
  def get(count:, offset:, options: nil)
19
15
  payload = { count: count,
20
16
  offset: offset }
21
17
  payload[:options] = options unless options.nil?
22
18
 
23
- @client.post_with_auth('institutions/get', payload)
19
+ post_with_auth 'institutions/get',
20
+ MultipleInstitutionsResponse,
21
+ payload
24
22
  end
25
23
 
26
- # Public: Get information about a Plaid institution by ID
24
+ # Public: Get information about a Plaid institution by ID.
27
25
  #
28
26
  # Does a POST /institutions/get_by_id call which allows you to pull
29
- # information for an institution by ID
27
+ # information for an institution by ID.
30
28
  #
31
- # institution_id - Specific institution id to fetch information for
29
+ # institution_id - Specific institution id to fetch information for.
32
30
  #
33
- # Returns a parsed JSON of institution info for your institution id
31
+ # Returns a SingleInstitutionResponse instance.
34
32
  def get_by_id(institution_id)
35
- payload = { institution_id: institution_id }
36
- @client.post_with_public_key('institutions/get_by_id', payload)
33
+ post_with_public_key 'institutions/get_by_id',
34
+ SingleInstitutionResponse,
35
+ institution_id: institution_id
37
36
  end
38
37
 
39
- # Public: Get information about all available institutions matching your query
38
+ # Public: Get information about all available institutions matching your
39
+ # query.
40
40
  #
41
- # Does a POST /institutions/search call which allows you to pull a list of institutions
42
- # using a query parameter
41
+ # Does a POST /institutions/search call which allows you to pull a list of
42
+ # institutions using a query parameter.
43
43
  #
44
- # query - Search query to attempt to match institutions to
45
- # producs - Product supported filter (optional)
44
+ # query - Search query to attempt to match institutions to.
45
+ # products - Product supported filter (optional).
46
46
  #
47
- # Returns a parsed JSON listing institution information
47
+ # Returns a MultipleInstitutionsResponse instance.
48
48
  def search(query, products = nil)
49
- payload = { query: query,
50
- products: products }
51
- @client.post_with_public_key('institutions/search', payload)
49
+ post_with_public_key 'institutions/search',
50
+ MultipleInstitutionsResponse,
51
+ query: query,
52
+ products: products
52
53
  end
53
54
  end
55
+
56
+ # Public: Response for institutions search returning a single institution.
57
+ class SingleInstitutionResponse < Models::BaseResponse
58
+ ##
59
+ # :attr_reader:
60
+ # Public: Institution info: Plaid::Models::Institution.
61
+ property :institution, coerce: Models::Institution
62
+ end
63
+
64
+ # Public: Response for institutions search returning multiple institutions.
65
+ class MultipleInstitutionsResponse < Models::BaseResponse
66
+ ##
67
+ # :attr_reader:
68
+ # Public: Institutions info: Array of Plaid::Models::Institution.
69
+ property :institutions, coerce: Array[Models::Institution]
70
+
71
+ ##
72
+ # :attr_reader:
73
+ # Public: The total number of search results.
74
+ property :total
75
+ end
54
76
  end