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,21 +1,27 @@
1
1
  module Plaid
2
2
  # Public: Class used to call the AccessToken sub-product.
3
- class AccessToken
4
- def initialize(client)
5
- @client = client
6
- end
7
-
3
+ class AccessToken < BaseProduct
8
4
  # Public: Rotate your access_token, keeping it attached to the item
9
5
  #
10
- # Does a POST /item/access_token/invalidate call which will give you a new access_token
11
- # allowing you to rotate access_tokens
6
+ # Does a POST /item/access_token/invalidate call which will give you a new
7
+ # access_token allowing you to rotate access_tokens.
12
8
  #
13
- # access_token - access_token to invalidate and rotate
9
+ # access_token - The String access_token to invalidate and rotate.
14
10
  #
15
- # Returns a parsed JSON with the new access_token and request id
11
+ # Returns an InvalidateResponse object with the new access_token and
12
+ # request id.
16
13
  def invalidate(access_token)
17
- payload = { access_token: access_token }
18
- @client.post_with_auth('item/access_token/invalidate', payload)
14
+ post_with_auth 'item/access_token/invalidate',
15
+ InvalidateResponse,
16
+ access_token: access_token
17
+ end
18
+
19
+ # Public: Response for /item/access_token/invalidate.
20
+ class InvalidateResponse < Models::BaseResponse
21
+ ##
22
+ # :attr_reader:
23
+ # Public: The String new access token.
24
+ property :new_access_token
19
25
  end
20
26
 
21
27
  # Public: Generate a new API access_token for a legacy access_token
@@ -25,136 +31,188 @@ module Plaid
25
31
  #
26
32
  # access_token_v1 - legacy access_token
27
33
  #
28
- # Returns a parsed JSON with the new access_token and request id
34
+ # Returns an UpdateVersionResponse object with new access_token and item
35
+ # ID.
29
36
  def update_version(access_token_v1)
30
- payload = { access_token_v1: access_token_v1 }
31
- @client.post_with_auth('item/access_token/update_version', payload)
37
+ post_with_auth 'item/access_token/update_version',
38
+ UpdateVersionResponse,
39
+ access_token_v1: access_token_v1
32
40
  end
33
- end
34
41
 
35
- # Public: Class used to call the Credentials sub-product.
36
- class Credentials
37
- def initialize(client)
38
- @client = client
42
+ # Public: Response for /item/access_token/update_version.
43
+ class UpdateVersionResponse < Models::BaseResponse
44
+ ##
45
+ # :attr_reader:
46
+ # Public: The String new access token for use.
47
+ property :access_token
48
+
49
+ ##
50
+ # :attr_reader:
51
+ # Public: The String item ID.
52
+ property :item_id
39
53
  end
54
+ end
40
55
 
56
+ # Public: Class used to call the Credentials sub-product.
57
+ class Credentials < BaseProduct
41
58
  # Public: Update credentials for an access_token.
42
59
  #
43
- # Does a POST /item/credentials/update call which is used to update credentials
44
- # if the credentials become no longer valid
60
+ # Does a POST /item/credentials/update call which is used to update
61
+ # credentials if the credentials become no longer valid.
45
62
  #
46
63
  # access_token - access_token who's item to update credentials for
47
64
  # credentials - New credentials
48
65
  #
49
- # Returns a parsed JSON of either an ItemStatus or MFA response
66
+ # Returns an UpdateResponse object with either an ItemStatus or MFA
67
+ # response.
50
68
  def update(access_token, credentials)
51
- payload = { access_token: access_token,
52
- credentials: credentials }
53
- @client.post_with_auth('item/credentials/update', payload)
69
+ post_with_auth 'item/credentials/update',
70
+ UpdateResponse,
71
+ access_token: access_token,
72
+ credentials: credentials
54
73
  end
55
- end
56
74
 
57
- # Public: Class used to call the PublicToken sub-product
58
- class PublicToken
59
- def initialize(client)
60
- @client = client
75
+ # Public: Response for /item/credentials/update.
76
+ class UpdateResponse < Models::BaseResponse
77
+ ##
78
+ # :attr_reader:
79
+ # Public: The item: Plaid::Models::Item.
80
+ property :item, coerce: Models::Item
61
81
  end
82
+ end
62
83
 
84
+ # Public: Class used to call the PublicToken sub-product
85
+ class PublicToken < BaseProduct
63
86
  # Public: Creates a public token from an access_token.
64
87
  #
65
- # Does a POST /item/public_token/create call which can be used to initialize Link
66
- # in update mode
88
+ # Does a POST /item/public_token/create call which can be used to
89
+ # initialize Link in update mode.
67
90
  #
68
91
  # access_token - access_token to create a public token for
69
92
  #
70
- # Returns a parsed JSON containing a public token and token info
93
+ # Returns a CreateResponse object with a public token and expiration info.
71
94
  def create(access_token)
72
- payload = { access_token: access_token }
73
- @client.post_with_auth('item/public_token/create', payload)
95
+ post_with_auth 'item/public_token/create',
96
+ CreateResponse,
97
+ access_token: access_token
98
+ end
99
+
100
+ # Public: Response for /item/public_token/create.
101
+ class CreateResponse < Models::BaseResponse
102
+ ##
103
+ # :attr_reader:
104
+ # Public: The String token.
105
+ property :public_token
106
+
107
+ ##
108
+ # :attr_reader:
109
+ # Public: The String token expiration time.
110
+ property :expiration
74
111
  end
75
112
 
76
113
  # Public: Exchange a public token for an access_token
77
114
  #
78
- # Does a POST /item/public_token/exchange call helps you exchange a public token
79
- # (possibly from Plaid Link) for an access_token you can use in the rest of your app
115
+ # Does a POST /item/public_token/exchange call helps you exchange a public
116
+ # token (possibly from Plaid Link) for an access_token you can use in the
117
+ # rest of your app.
80
118
  #
81
- # public_token - Public token to get an access_token from
119
+ # public_token - The Public token to get an access_token from.
82
120
  #
83
- # Returns a parsed JSON with an access_token and request id
121
+ # Returns an ExchangeResponse object with an access_token and request id.
84
122
  def exchange(public_token)
85
- payload = { public_token: public_token }
86
- @client.post_with_auth('item/public_token/exchange', payload)
123
+ post_with_auth 'item/public_token/exchange',
124
+ ExchangeResponse,
125
+ public_token: public_token
87
126
  end
88
- end
89
127
 
90
- # Public: Class used to call the Webhook sub-product
91
- class Webhook
92
- def initialize(client)
93
- @client = client
128
+ # Public: Response for /item/public_token/exchange.
129
+ class ExchangeResponse < Models::BaseResponse
130
+ ##
131
+ # :attr_reader:
132
+ # Public: The String access token for use with API.
133
+ property :access_token
134
+
135
+ ##
136
+ # :attr_reader:
137
+ # Public: The String item ID.
138
+ property :item_id
94
139
  end
140
+ end
95
141
 
96
- # Public: Update webhook for an access_token
142
+ # Public: Class used to call the Webhook sub-product
143
+ class Webhook < BaseProduct
144
+ # Public: Update webhook for an access_token.
97
145
  #
98
146
  # Does a POST /item/webhook/update call which is used to update webhook
99
- # for a particular access_token, webhooks are used to be notified when
100
- # transactions for an item are updated and ready
147
+ # for a particular access_token. Webhooks are used to be notified when
148
+ # transactions for an item are updated and ready.
101
149
  #
102
- # access_token - access_token who's item to update webhood for
103
- # webhook - a new webhook link
150
+ # access_token - The access_token of an item to update webhook for.
151
+ # webhook - The new webhook link.
104
152
  #
105
- # Returns a parsed JSON of either an ItemStatus or MFA response
153
+ # Returns an UpdateResponse object with either an ItemStatus or MFA
154
+ # response.
106
155
  def update(access_token, webhook)
107
- payload = { access_token: access_token,
108
- webhook: webhook }
109
- @client.post_with_auth('item/webhook/update', payload)
156
+ post_with_auth 'item/webhook/update',
157
+ UpdateResponse,
158
+ access_token: access_token,
159
+ webhook: webhook
160
+ end
161
+
162
+ # Public: Response for /item/webhook/update.
163
+ class UpdateResponse < Models::BaseResponse
164
+ ##
165
+ # :attr_reader:
166
+ # Public: The item: Plaid::Models::Item.
167
+ property :item, coerce: Models::Item
110
168
  end
111
169
  end
112
170
 
113
171
  # Public: Class used to call the Item product.
114
- class Item
115
- # Public: Memoized class instance to make requests from Plaid::AccessToken
116
- def access_token
117
- @access_token ||= Plaid::AccessToken.new(@client)
118
- end
172
+ class Item < BaseProduct
173
+ ##
174
+ # :attr_reader:
175
+ # Public: The Plaid::AccessToken product accessor.
176
+ subproduct :access_token
119
177
 
120
- # Public: Memoized class instance to make requests from Plaid::Credentials
121
- def credentials
122
- @credentials ||= Plaid::Credentials.new(@client)
123
- end
178
+ ##
179
+ # :attr_reader:
180
+ # Public: The Plaid::Credentials product accessor.
181
+ subproduct :credentials
124
182
 
125
- # Public: Memoized class instance to make requests from Plaid::PublicToken
126
- def public_token
127
- @public_token ||= Plaid::PublicToken.new(@client)
128
- end
183
+ ##
184
+ # :attr_reader:
185
+ # Public: The Plaid::PublicToken product accessor.
186
+ subproduct :public_token
129
187
 
130
- # Public: Memoized class instance to make requests from Plaid::Webhook
131
- def webhook
132
- @webhook ||= Plaid::Webhook.new(@client)
133
- end
134
-
135
- def initialize(client)
136
- @client = client
137
- end
188
+ ##
189
+ # :attr_reader:
190
+ # Public: The Plaid::Webhook product accessor.
191
+ subproduct :webhook
138
192
 
139
193
  # Public: Creates an item.
140
194
  #
141
195
  # Does a POST /item/create call which attemps to create a new item for you
142
- # possibly returning a success, error, or multi-factor authentication response
143
- #
144
- # credentials - Institution credentials to create item with
145
- # institution_id - Institution ID to create item with
146
- # initial_products - Initial products to create the item with i.e. ['transactions']
147
- # transactions_start_date - date at which to begin the item's initial transaction pull
148
- # (optional)
149
- # transactions_end_date - date at which to end the item's initial transaction pull
150
- # (optional)
151
- # transactions_await_results - if true, the initial transaction pull will be performed
152
- # synchronously (optional)
153
- # webhook - webhook to associate with the item (optional)
154
- # options - Additional options to merge into API request
155
- #
156
- # Returns a parsed JSON of item info including access_token and ItemStatus or
157
- # MFA response or error
196
+ # possibly returning a success, error, or multi-factor authentication
197
+ # response.
198
+ #
199
+ # credentials - Institution credentials to create item with.
200
+ # institution_id - Institution ID to create item with.
201
+ # initial_products - Initial products to create the item with,
202
+ # i.e. [:transactions].
203
+ # transactions_start_date - date at which to begin the item's initial
204
+ # transaction pull (optional).
205
+ # transactions_end_date - date at which to end the item's initial
206
+ # transaction pull (optional).
207
+ # transactions_await_results - if true, the initial transaction pull will
208
+ # be performed synchronously (optional).
209
+ # webhook - webhook to associate with the item
210
+ # (optional).
211
+ # options - Additional options to merge into API
212
+ # request.
213
+ #
214
+ # Returns an ItemResponse object with item info including access_token and
215
+ # ItemStatus, or MFA response or error.
158
216
  def create(credentials:,
159
217
  institution_id:,
160
218
  initial_products:,
@@ -164,67 +222,115 @@ module Plaid
164
222
  webhook: nil,
165
223
  options: nil)
166
224
 
167
- transactions_options = {}
168
- unless transactions_start_date.nil?
169
- transactions_options[:start_date] = Plaid.convert_to_date_string(transactions_start_date)
170
- end
171
- unless transactions_end_date.nil?
172
- transactions_options[:end_date] = Plaid.convert_to_date_string(transactions_end_date)
173
- end
174
- unless transactions_await_results.nil?
175
- transactions_options[:await_results] = transactions_await_results
176
- end
177
-
178
225
  options_payload = {}
179
- options_payload[:transactions] = transactions_options if transactions_options != {}
226
+
227
+ txn_options = transaction_options transactions_start_date,
228
+ transactions_end_date,
229
+ transactions_await_results
230
+
231
+ options_payload[:transactions] = txn_options if txn_options != {}
180
232
  options_payload[:webhook] = webhook unless webhook.nil?
181
233
  options_payload = options_payload.merge(options) unless options.nil?
182
234
 
183
- payload = { credentials: credentials,
184
- institution_id: institution_id,
185
- initial_products: initial_products,
186
- options: options_payload }
187
- @client.post_with_auth('item/create', payload)
235
+ post_with_auth 'item/create',
236
+ ItemResponse,
237
+ credentials: credentials,
238
+ institution_id: institution_id,
239
+ initial_products: initial_products,
240
+ options: options_payload
241
+ end
242
+
243
+ private def transaction_options(start_date, end_date, await_results)
244
+ {}.tap do |options|
245
+ options[:start_date] = Plaid.convert_to_date_string(start_date) \
246
+ if start_date
247
+
248
+ options[:end_date] = Plaid.convert_to_date_string(end_date) \
249
+ if end_date
250
+
251
+ options[:await_results] = await_results if await_results
252
+ end
253
+ end
254
+
255
+ # Public: Response for /item/create and /item/mfa endpoints.
256
+ class ItemResponse < Models::BaseResponse
257
+ ##
258
+ # :attr_reader:
259
+ # Public: The String access_token to use with API.
260
+ property :access_token
261
+
262
+ ##
263
+ # :attr_reader:
264
+ # Public: The Plaid::Models::Item object, returned if item has been
265
+ # successfully created.
266
+ property :item, coerce: Models::Item
267
+
268
+ ##
269
+ # :attr_reader:
270
+ # Public: The MFA/OTP device information: Plaid::Models::MFA::Device.
271
+ property :device, coerce: Models::MFA::Device
272
+
273
+ ##
274
+ # :attr_reader:
275
+ # Public: The list of devices to send the OTP to:
276
+ # Array of Plaid::Models::MFA::DeviceListElement.
277
+ property :device_list, coerce: Array[Models::MFA::DeviceListElement]
278
+
279
+ ##
280
+ # :attr_reader:
281
+ # Public: The String MFA type. E.g. "device_list", "device", "questions",
282
+ # "selections".
283
+ property :mfa_type
284
+
285
+ ##
286
+ # :attr_reader:
287
+ # Public: The Array of String MFA questions.
288
+ property :questions
289
+
290
+ ##
291
+ # :attr_reader:
292
+ # Public: The Array of MFA selections: Plaid::Models::MFA::Selection.
293
+ property :selections, coerce: Array[Models::MFA::Selection]
188
294
  end
189
295
 
190
296
  # Public: Submit an MFA step.
191
297
  #
192
- # Does a POST /item/mfa call which gives you the ability to response to an MFA
298
+ # Does a POST /item/mfa call which gives you the ability to respond to an
299
+ # MFA.
193
300
  #
194
- # access_token - To submit MFA step for
195
- # mfa_type - The MFA type indicated in the MFA response
196
- # responses - List of answers/responses to MFA
301
+ # access_token - To submit MFA step for.
302
+ # mfa_type - The MFA type indicated in the MFA response.
303
+ # responses - List of answers/responses to MFA.
197
304
  #
198
- # Returns a parsed JSON of ItemStatus or another MFA step
305
+ # Returns an ItemResponse instance.
199
306
  def mfa(access_token, mfa_type, responses)
200
- payload = { access_token: access_token,
201
- mfa_type: mfa_type,
202
- responses: responses }
203
- @client.post_with_auth('item/mfa', payload)
307
+ post_with_auth 'item/mfa',
308
+ ItemResponse,
309
+ access_token: access_token,
310
+ mfa_type: mfa_type,
311
+ responses: responses
204
312
  end
205
313
 
206
- # Public: Get information about an item
314
+ # Public: Get information about an item.
207
315
  #
208
- # Does a POST /item/get call which returns information about an item or ItemStatus
316
+ # Does a POST /item/get call which returns information about an item or
317
+ # ItemStatus.
209
318
  #
210
319
  # access_token - access_token who's item to fetch status for
211
320
  #
212
- # Returns a parsed JSON of item information
321
+ # Returns a GetResponse object with item information.
213
322
  def get(access_token)
214
- payload = { access_token: access_token }
215
- @client.post_with_auth('item/get', payload)
323
+ post_with_auth 'item/get',
324
+ GetResponse,
325
+ access_token: access_token
216
326
  end
217
327
 
218
- # Public: Deletes an item
219
- #
220
- # Does a POST /item/delete call which is used to delete an item
221
- #
222
- # access_token - access_token who's item to delete
223
- #
224
- # Returns a parsed JSON of delete result
225
- def delete(access_token)
226
- payload = { access_token: access_token }
227
- @client.post_with_auth('item/delete', payload)
328
+ # Public: Response for /item/get.
329
+ class GetResponse < Models::BaseResponse
330
+ ##
331
+ # :attr_reader:
332
+ # Public: The item: Plaid::Models::Item.
333
+ property :item, coerce: Models::Item
228
334
  end
229
335
 
230
336
  # Public: Removes an item
@@ -233,10 +339,19 @@ module Plaid
233
339
  #
234
340
  # access_token - access_token who's item to remove
235
341
  #
236
- # Returns a parsed JSON of remove result
342
+ # Returns a RemoveResponse object with remove result.
237
343
  def remove(access_token)
238
- payload = { access_token: access_token }
239
- @client.post_with_auth('item/remove', payload)
344
+ post_with_auth 'item/remove',
345
+ RemoveResponse,
346
+ access_token: access_token
347
+ end
348
+
349
+ # Public: Response for /item/remove.
350
+ class RemoveResponse < Models::BaseResponse
351
+ ##
352
+ # :attr_reader:
353
+ # Public: The Boolean flag meaning successful removal.
354
+ property :removed
240
355
  end
241
356
  end
242
357
  end