plaid 4.1.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +23 -0
- data/.rubocop.yml +18 -0
- data/CHANGELOG.md +7 -0
- data/CONTRIBUTING.md +1 -1
- data/Gemfile.lock +58 -0
- data/README.md +50 -39
- data/Rakefile +7 -10
- data/lib/plaid.rb +40 -1
- data/lib/plaid/client.rb +72 -63
- data/lib/plaid/errors.rb +46 -41
- data/lib/plaid/middleware.rb +11 -6
- data/lib/plaid/models.rb +683 -0
- data/lib/plaid/products/accounts.rb +38 -35
- data/lib/plaid/products/auth.rb +32 -19
- data/lib/plaid/products/base_product.rb +69 -0
- data/lib/plaid/products/categories.rb +11 -8
- data/lib/plaid/products/credit_details.rb +31 -19
- data/lib/plaid/products/identity.rb +27 -11
- data/lib/plaid/products/income.rb +22 -11
- data/lib/plaid/products/institutions.rb +50 -28
- data/lib/plaid/products/item.rb +251 -136
- data/lib/plaid/products/processor.rb +104 -34
- data/lib/plaid/products/sandbox.rb +21 -20
- data/lib/plaid/products/transactions.rb +50 -45
- data/lib/plaid/version.rb +1 -1
- data/plaid.gemspec +10 -8
- metadata +51 -19
- data/circle.yml +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: faaa2fa4eb692b453290b83c1e25dd9881b74698
|
4
|
+
data.tar.gz: b35adebbfc727257f36168479cecc659a900e149
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ca822ff868b0525f132ba6c934ff223b7f3e33d49ec9e983defca591f1893ed652ee26023f3ff3acac627f2b9eabeae8a980ff3de2456f8251ad2841c8e05c6
|
7
|
+
data.tar.gz: 0e8023c4270011a064a383cd1c071b17940220bb59724782eb0acd268d213035ed8a8287c278590695191317581e56f446271aab31805632df16be76f91ca04b
|
@@ -0,0 +1,23 @@
|
|
1
|
+
version: 2
|
2
|
+
|
3
|
+
jobs:
|
4
|
+
build:
|
5
|
+
docker:
|
6
|
+
- image: circleci/ruby:2.3
|
7
|
+
steps:
|
8
|
+
- checkout
|
9
|
+
- run:
|
10
|
+
name: Bundle Install
|
11
|
+
command: bundle check || bundle install
|
12
|
+
- run:
|
13
|
+
name: Stubbed API test
|
14
|
+
command: bundle exec rake test
|
15
|
+
environment:
|
16
|
+
STUB_API: yes
|
17
|
+
- run:
|
18
|
+
name: Live API test
|
19
|
+
command: bundle exec rake test
|
20
|
+
- run:
|
21
|
+
name: Rubocop test
|
22
|
+
command: bundle exec rubocop
|
23
|
+
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.1
|
3
|
+
|
4
|
+
Style/FrozenStringLiteralComment:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Layout/IndentHeredoc:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Metrics/AbcSize:
|
11
|
+
Max: 20
|
12
|
+
|
13
|
+
Metrics/MethodLength:
|
14
|
+
Max: 20
|
15
|
+
|
16
|
+
Metrics/ParameterLists:
|
17
|
+
Max: 5
|
18
|
+
CountKeywordArgs: false
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# 5.0.0 23-Mar-2018
|
2
|
+
|
3
|
+
* Introduce true response objects instead of deep nested hashes. Any of the
|
4
|
+
three syntaxes can be used interchangeably for any API response:
|
5
|
+
`response['foo']['bar']`, `response[:foo][:bar]`, or `response.foo.bar`.
|
6
|
+
* Add Dwolla and Apex products.
|
7
|
+
|
1
8
|
# 4.1.0 04-Jan-2018
|
2
9
|
|
3
10
|
* Make `/item/remove` the primary Item removal endpoint
|
data/CONTRIBUTING.md
CHANGED
@@ -36,7 +36,7 @@ changes in API you'll need to update the pre-recorded responses. Here's how:
|
|
36
36
|
use this:
|
37
37
|
|
38
38
|
```
|
39
|
-
RECORD_MODE=all STUB_API=1 ruby -w -I"lib:test" -rminitest/pride test/test_which_fails.rb
|
39
|
+
RECORD_MODE=all STUB_API=1 ruby -w -I"lib:test" -rminitest/pride -rdotenv/load test/test_which_fails.rb
|
40
40
|
```
|
41
41
|
3. Run `rake vcr_hide_credentials`. This step is essential, because
|
42
42
|
newly recorded files will contain your real `client_id` and friends. This
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
plaid (5.0.0)
|
5
|
+
faraday
|
6
|
+
faraday_middleware
|
7
|
+
hashie (>= 3.4.3)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
ast (2.4.0)
|
13
|
+
dotenv (2.2.1)
|
14
|
+
faraday (0.14.0)
|
15
|
+
multipart-post (>= 1.2, < 3)
|
16
|
+
faraday_middleware (0.12.2)
|
17
|
+
faraday (>= 0.7.4, < 1.0)
|
18
|
+
hashie (3.5.7)
|
19
|
+
minitest (5.11.3)
|
20
|
+
minitest-around (0.4.1)
|
21
|
+
minitest (~> 5.0)
|
22
|
+
multipart-post (2.0.0)
|
23
|
+
parallel (1.12.1)
|
24
|
+
parser (2.5.0.4)
|
25
|
+
ast (~> 2.4.0)
|
26
|
+
powerpack (0.1.1)
|
27
|
+
rainbow (3.0.0)
|
28
|
+
rake (12.3.0)
|
29
|
+
rdoc (6.0.1)
|
30
|
+
rubocop (0.53.0)
|
31
|
+
parallel (~> 1.10)
|
32
|
+
parser (>= 2.5)
|
33
|
+
powerpack (~> 0.1)
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
35
|
+
ruby-progressbar (~> 1.7)
|
36
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
37
|
+
ruby-progressbar (1.9.0)
|
38
|
+
sdoc (1.0.0)
|
39
|
+
rdoc (>= 5.0)
|
40
|
+
unicode-display_width (1.3.0)
|
41
|
+
vcr (4.0.0)
|
42
|
+
|
43
|
+
PLATFORMS
|
44
|
+
ruby
|
45
|
+
|
46
|
+
DEPENDENCIES
|
47
|
+
bundler (~> 1.7)
|
48
|
+
dotenv
|
49
|
+
minitest (~> 5.10)
|
50
|
+
minitest-around (~> 0.4.0)
|
51
|
+
plaid!
|
52
|
+
rake (>= 10.0)
|
53
|
+
rubocop (~> 0.53.0)
|
54
|
+
sdoc (~> 1.0.0)
|
55
|
+
vcr (~> 4.0.0)
|
56
|
+
|
57
|
+
BUNDLED WITH
|
58
|
+
1.12.5
|
data/README.md
CHANGED
@@ -35,18 +35,31 @@ Create an instance of the client using the `client_id`, `secret`, and `public_ke
|
|
35
35
|
```ruby
|
36
36
|
require 'plaid'
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
client = Plaid::Client.new(env: :sandbox,
|
39
|
+
client_id: '***',
|
40
|
+
secret: '***',
|
41
|
+
public_key: '***')
|
43
42
|
```
|
44
43
|
|
45
44
|
The `env` field is the environment which the client will be running in. Your choices for the `env` field include:
|
45
|
+
|
46
46
|
- `:sandbox` allows you to do your initial integrations tests against preloaded data without being billed or making expensive API calls. More information about using the API sandbox can be found on the [API Sandbox documentation](https://plaid.com/docs/api#sandbox).
|
47
47
|
- `:development` allows you to test against both real and test accounts without being billed. More information about Plaid test accounts can be found in our [API documentation](https://plaid.com/docs/api/#sandbox).
|
48
48
|
- `:production` is the production environment where you can launch your production ready application and be charged for your Plaid usage.
|
49
49
|
|
50
|
+
### Tuning Faraday
|
51
|
+
|
52
|
+
The gem uses Faraday to wrap HTTPS connections, which allows you to tune certain params:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
client = Plaid::Client.new(env: :sandbox, client_id: '***', secret: '***', public_key: '***') do |builder|
|
56
|
+
Plaid::Client.build_default_connection(builder)
|
57
|
+
|
58
|
+
# Increase network timeout
|
59
|
+
builder.options[:timeout] = 60*20 # 20 minutes
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
50
63
|
## Examples
|
51
64
|
|
52
65
|
### Exchanging a Link public_token for a Plaid access_token
|
@@ -57,7 +70,7 @@ An example of the function's usage if you have a `public_token` in hand:
|
|
57
70
|
|
58
71
|
```ruby
|
59
72
|
response = client.item.public_token.exchange(public_token)
|
60
|
-
access_token = response
|
73
|
+
access_token = response.access_token
|
61
74
|
```
|
62
75
|
|
63
76
|
### Deleting an item
|
@@ -70,12 +83,8 @@ client = Plaid::Client.new(env: :sandbox,
|
|
70
83
|
secret: '***',
|
71
84
|
public_key: '***')
|
72
85
|
|
73
|
-
|
74
|
-
|
75
|
-
institution_id: 'ins_109509',
|
76
|
-
initial_products: %i(auth identity transactions))
|
77
|
-
|
78
|
-
access_token = response['access_token']
|
86
|
+
exchange_token_response = client.item.public_token.exchange('[Plaid Link public_token]')
|
87
|
+
access_token = exchange_token_response.access_token
|
79
88
|
|
80
89
|
# Provide the access_token for the Item you want to remove
|
81
90
|
client.item.remove(access_token)
|
@@ -90,15 +99,11 @@ client = Plaid::Client.new(env: :sandbox,
|
|
90
99
|
secret: '***',
|
91
100
|
public_key: '***')
|
92
101
|
|
93
|
-
|
94
|
-
|
95
|
-
institution_id: 'ins_109509',
|
96
|
-
initial_products: %i(auth identity transactions))
|
97
|
-
|
98
|
-
access_token = item_response['access_token']
|
102
|
+
exchange_token_response = client.item.public_token.exchange('[Plaid Link public_token]')
|
103
|
+
access_token = exchange_token_response.access_token
|
99
104
|
|
100
105
|
transaction_response = client.transactions.get(access_token, '2016-07-12', '2017-01-09')
|
101
|
-
transactions = transaction_response
|
106
|
+
transactions = transaction_response.transactions
|
102
107
|
|
103
108
|
# the transactions in the response are paginated, so make multiple calls while
|
104
109
|
# increasing the offset to retrieve all transactions
|
@@ -107,7 +112,7 @@ while transactions.length < transaction_response['total_transactions']
|
|
107
112
|
'2016-07-12',
|
108
113
|
'2017-01-09',
|
109
114
|
offset: transactions.length)
|
110
|
-
transactions += transaction_response
|
115
|
+
transactions += transaction_response.transactions
|
111
116
|
end
|
112
117
|
|
113
118
|
```
|
@@ -123,16 +128,11 @@ client = Plaid::Client.new(env: :sandbox,
|
|
123
128
|
secret: '***',
|
124
129
|
public_key: '***')
|
125
130
|
|
126
|
-
|
127
|
-
|
128
|
-
institution_id: 'ins_109509',
|
129
|
-
initial_products: %i(auth identity transactions))
|
130
|
-
|
131
|
-
access_token = item_response['access_token']
|
131
|
+
exchange_token_response = client.item.public_token.exchange('[Plaid Link public_token]')
|
132
|
+
access_token = exchange_token_response.access_token
|
132
133
|
|
133
134
|
auth_response = client.auth.get(access_token)
|
134
|
-
auth = auth_response
|
135
|
-
|
135
|
+
auth = auth_response.auth
|
136
136
|
```
|
137
137
|
|
138
138
|
### Create a Stripe bank_account_token
|
@@ -147,23 +147,22 @@ client = Plaid::Client.new(env: :sandbox,
|
|
147
147
|
public_key: '***')
|
148
148
|
|
149
149
|
exchange_token_response = client.item.public_token.exchange('[Plaid Link public_token]')
|
150
|
-
access_token = exchange_token_response
|
150
|
+
access_token = exchange_token_response.access_token
|
151
151
|
|
152
152
|
stripe_response = client.processor.stripe.bank_account_token.create(access_token, '[Account ID]')
|
153
|
-
bank_account_token = stripe_response
|
154
|
-
|
153
|
+
bank_account_token = stripe_response.stripe_bank_account_token
|
155
154
|
```
|
156
155
|
|
157
156
|
There are also a number of other methods you can use to retrieve data:
|
158
157
|
|
159
|
-
* `client.accounts.get(
|
160
|
-
* `client.accounts.balance.get(
|
161
|
-
* `client.auth.get(
|
162
|
-
* `client.identity.get(
|
163
|
-
* `client.transactions.get(
|
164
|
-
* `client.credit_details.get(
|
158
|
+
* `client.accounts.get(access_token, ...)`: accounts
|
159
|
+
* `client.accounts.balance.get(access_token, ...)`: real-time balances
|
160
|
+
* `client.auth.get(access_token, ...)`: auth
|
161
|
+
* `client.identity.get(access_token, ...)`: identity
|
162
|
+
* `client.transactions.get(access_token, ...)`: transactions
|
163
|
+
* `client.credit_details.get(access_token, ...)`: credit details
|
165
164
|
|
166
|
-
All of these methods return appropriate data. More information
|
165
|
+
All of these methods return appropriate data. More information can be found on the [API documentation](https://plaid.com/docs/api).
|
167
166
|
|
168
167
|
### Categories
|
169
168
|
|
@@ -199,9 +198,21 @@ Any methods making API calls will result in an exception raised unless the respo
|
|
199
198
|
Read more about response codes and their meaning in the
|
200
199
|
[Plaid documentation](https://plaid.com/docs/api).
|
201
200
|
|
201
|
+
## Response Objects
|
202
|
+
|
203
|
+
Any API call returns a response object which is accessible by dot notation
|
204
|
+
(`response.foo.bar`) or Symbols and Strings as keys: `response[:foo][:bar]`
|
205
|
+
and `response['foo']['bar']`. Expected keys for all types of responses are defined,
|
206
|
+
and any attempt to access an unknown key will cause `NoMethodError` exception.
|
207
|
+
|
208
|
+
These strict model checks can be disabled by setting `Plaid.relaxed_models = true`.
|
209
|
+
|
202
210
|
## Network Timeout
|
203
211
|
|
204
|
-
A network timeout value is
|
212
|
+
A network timeout value is currently defaulted at 600 seconds = 10 minutes.
|
213
|
+
Some requests from the Plaid API may take longer than others and we want to
|
214
|
+
make sure that all valid requests have a chance to complete. Adjust this value
|
215
|
+
if necessary (see "Tuning Faraday").
|
205
216
|
|
206
217
|
## Contributing
|
207
218
|
|
data/Rakefile
CHANGED
@@ -47,34 +47,31 @@ task :update_gh_pages do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
desc 'Generate rdoc and update gh-pages on GitHub'
|
50
|
-
task update_github_docs: %i
|
50
|
+
task update_github_docs: %i[rdoc update_gh_pages] do
|
51
51
|
sh 'git push origin gh-pages'
|
52
52
|
end
|
53
53
|
|
54
54
|
desc 'Hide real credentials in VCR cassettes'
|
55
55
|
task :vcr_hide_credentials do
|
56
|
-
|
57
|
-
all_creds = %w(PLAID_RUBY_CLIENT_ID PLAID_RUBY_SECRET PLAID_RUBY_PUBLIC_KEY)
|
56
|
+
all_creds = %w[PLAID_RUBY_CLIENT_ID PLAID_RUBY_SECRET PLAID_RUBY_PUBLIC_KEY]
|
58
57
|
|
59
58
|
all_creds.each do |cred|
|
60
|
-
|
59
|
+
raise "#{cred} is not set" unless ENV[cred]
|
61
60
|
end
|
62
61
|
|
63
62
|
Dir['test/vcr_cassettes/*'].each do |fn|
|
64
63
|
data = File.read(fn)
|
65
|
-
|
64
|
+
data0 = data.clone
|
66
65
|
|
67
66
|
all_creds.each do |cred|
|
68
67
|
data.gsub! ENV[cred], cred
|
69
68
|
end
|
70
69
|
|
71
|
-
|
72
|
-
|
70
|
+
next unless data != data0
|
71
|
+
File.open(fn, 'w') { |f| f.write data }
|
73
72
|
|
74
|
-
|
75
|
-
end
|
73
|
+
puts ">> Updated #{fn}"
|
76
74
|
end
|
77
|
-
|
78
75
|
end
|
79
76
|
|
80
77
|
task :test_stubbed do
|
data/lib/plaid.rb
CHANGED
@@ -2,9 +2,10 @@ require 'faraday'
|
|
2
2
|
require 'faraday_middleware'
|
3
3
|
|
4
4
|
require_relative 'plaid/middleware'
|
5
|
-
require_relative 'plaid/
|
5
|
+
require_relative 'plaid/products/base_product'
|
6
6
|
require_relative 'plaid/errors'
|
7
7
|
require_relative 'plaid/version'
|
8
|
+
require_relative 'plaid/models'
|
8
9
|
require_relative 'plaid/products/accounts'
|
9
10
|
require_relative 'plaid/products/auth'
|
10
11
|
require_relative 'plaid/products/categories'
|
@@ -16,3 +17,41 @@ require_relative 'plaid/products/item'
|
|
16
17
|
require_relative 'plaid/products/processor'
|
17
18
|
require_relative 'plaid/products/sandbox'
|
18
19
|
require_relative 'plaid/products/transactions'
|
20
|
+
require_relative 'plaid/client'
|
21
|
+
|
22
|
+
# Public: The namespace for all the things Plaid.
|
23
|
+
module Plaid
|
24
|
+
# Public: Get relaxed models state.
|
25
|
+
#
|
26
|
+
# We support two modes for parsing response bodies.
|
27
|
+
#
|
28
|
+
# Strict mode (default). Unknown attributes will cause NoMethodError.
|
29
|
+
#
|
30
|
+
# Relaxed mode. If a response contains an unknown
|
31
|
+
# attribute, it won't cause any error and will be accessible
|
32
|
+
# using brackets notation: `response['unknown_attribute']`.
|
33
|
+
#
|
34
|
+
# Returns truey value for relaxed mode and falsey for strict.
|
35
|
+
def relaxed_models?
|
36
|
+
defined?(@relaxed_models) && @relaxed_models
|
37
|
+
end
|
38
|
+
|
39
|
+
# Public: Sets value for relaxed_models.
|
40
|
+
def relaxed_models=(value)
|
41
|
+
@relaxed_models = value
|
42
|
+
end
|
43
|
+
|
44
|
+
module_function :relaxed_models?, :relaxed_models=
|
45
|
+
|
46
|
+
# Internal: Converts date objects to strings if needed.
|
47
|
+
#
|
48
|
+
# Takes in a string or a Date object and performs necessary operations to
|
49
|
+
# return a string representation of the Date.
|
50
|
+
#
|
51
|
+
# date - Date in Date object form or string form (YYYY-MM-DD).
|
52
|
+
#
|
53
|
+
# Returns a String with an ISO-8601 date.
|
54
|
+
def self.convert_to_date_string(date)
|
55
|
+
date.is_a?(String) ? date : date.to_date.strftime('%Y-%m-%d')
|
56
|
+
end
|
57
|
+
end
|
data/lib/plaid/client.rb
CHANGED
@@ -3,14 +3,15 @@ module Plaid
|
|
3
3
|
# Public: The main interface to Plaid API.
|
4
4
|
class Client
|
5
5
|
# Public: All possible environments for the client to use.
|
6
|
-
ENVIRONMENTS = %i
|
6
|
+
ENVIRONMENTS = %i[sandbox development production].freeze
|
7
7
|
|
8
8
|
# Public: The current environment in use (one of ENVIRONMENTS).
|
9
9
|
attr_reader :env
|
10
10
|
|
11
11
|
# Public: Construct a Client instance
|
12
12
|
#
|
13
|
-
# Optionally takes a block to allow overriding the default Faraday
|
13
|
+
# Optionally takes a block to allow overriding the default Faraday
|
14
|
+
# connection options.
|
14
15
|
#
|
15
16
|
# env - The Symbol (:sandbox, :development, :production)
|
16
17
|
# client_id - The String Plaid account client ID to authenticate requests
|
@@ -26,60 +27,62 @@ module Plaid
|
|
26
27
|
create_connection(&block)
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
|
-
def accounts
|
31
|
-
@accounts ||= Plaid::Accounts.new(self)
|
32
|
-
end
|
30
|
+
extend SubproductMixin
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
##
|
33
|
+
# :attr_reader:
|
34
|
+
# Public: The Plaid::Accounts product accessor.
|
35
|
+
subproduct :accounts
|
38
36
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
##
|
38
|
+
# :attr_reader:
|
39
|
+
# Public: The Plaid::Auth product accessor.
|
40
|
+
subproduct :auth
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
##
|
43
|
+
# :attr_reader:
|
44
|
+
# Public: The Plaid::Categories product accessor.
|
45
|
+
subproduct :categories
|
48
46
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
##
|
48
|
+
# :attr_reader:
|
49
|
+
# Public: The Plaid::CreditDetails product accessor.
|
50
|
+
subproduct :credit_details
|
53
51
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
##
|
53
|
+
# :attr_reader:
|
54
|
+
# Public: The Plaid::Identity product accessor.
|
55
|
+
subproduct :identity
|
58
56
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
57
|
+
##
|
58
|
+
# :attr_reader:
|
59
|
+
# Public: The Plaid::Income product accessor.
|
60
|
+
subproduct :income
|
63
61
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
62
|
+
##
|
63
|
+
# :attr_reader:
|
64
|
+
# Public: The Plaid::Institutions product accessor.
|
65
|
+
subproduct :institutions
|
68
66
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
##
|
68
|
+
# :attr_reader:
|
69
|
+
# Public: The Plaid::Item product accessor.
|
70
|
+
subproduct :item
|
73
71
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
72
|
+
##
|
73
|
+
# :attr_reader:
|
74
|
+
# Public: The Plaid::Processor product accessor.
|
75
|
+
subproduct :processor
|
78
76
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
77
|
+
##
|
78
|
+
# :attr_reader:
|
79
|
+
# Public: The Plaid::Sandbox product accessor.
|
80
|
+
subproduct :sandbox
|
81
|
+
|
82
|
+
##
|
83
|
+
# :attr_reader:
|
84
|
+
# Public: The Plaid::Transactions product accessor.
|
85
|
+
subproduct :transactions
|
83
86
|
|
84
87
|
# Public: Make a post request
|
85
88
|
#
|
@@ -100,7 +103,8 @@ module Plaid
|
|
100
103
|
def post_with_auth(path, payload)
|
101
104
|
@connection.post(
|
102
105
|
path,
|
103
|
-
payload.merge(client_id: @client_id, secret: @secret)
|
106
|
+
payload.merge(client_id: @client_id, secret: @secret)
|
107
|
+
).body
|
104
108
|
end
|
105
109
|
|
106
110
|
# Public: Make a post request with appended public key field.
|
@@ -113,8 +117,25 @@ module Plaid
|
|
113
117
|
@connection.post(path, payload.merge(public_key: @public_key)).body
|
114
118
|
end
|
115
119
|
|
120
|
+
# Public: Set Plaid defaults on the Faraday connection.
|
121
|
+
#
|
122
|
+
# builder - The Faraday builder object.
|
123
|
+
def self.build_default_connection(builder)
|
124
|
+
builder.options[:timeout] = Plaid::Middleware::NETWORK_TIMEOUT
|
125
|
+
builder.headers = Plaid::Middleware::NETWORK_HEADERS
|
126
|
+
builder.request :json
|
127
|
+
builder.use Plaid::Middleware
|
128
|
+
builder.response :json, content_type: /\bjson$/
|
129
|
+
builder.adapter Faraday.default_adapter
|
130
|
+
end
|
131
|
+
|
116
132
|
protected
|
117
133
|
|
134
|
+
# Internal: subproduct-generated methods depend on client method.
|
135
|
+
def client
|
136
|
+
self
|
137
|
+
end
|
138
|
+
|
118
139
|
# Internal: Gets the API hostname for given environment.
|
119
140
|
#
|
120
141
|
# env - The Symbol (:sandbox, :development, :production)
|
@@ -124,8 +145,8 @@ module Plaid
|
|
124
145
|
def api_host
|
125
146
|
unless ENVIRONMENTS.include?(@env)
|
126
147
|
raise ArgumentError,
|
127
|
-
|
128
|
-
|
148
|
+
"Invalid value for env (#{@env.inspect}): must be one of " +
|
149
|
+
ENVIRONMENTS.map(&:inspect) * ', '
|
129
150
|
end
|
130
151
|
|
131
152
|
"https://#{@env}.plaid.com"
|
@@ -134,22 +155,10 @@ module Plaid
|
|
134
155
|
# Internal: Initializes a new Plaid connection object via Faraday.
|
135
156
|
#
|
136
157
|
# Optionally takes a block to allow overriding the defaults.
|
137
|
-
def create_connection
|
158
|
+
def create_connection
|
138
159
|
@connection = Faraday.new(url: @api_host) do |builder|
|
139
|
-
block_given? ? yield(builder) : build_default_connection(builder)
|
160
|
+
block_given? ? yield(builder) : Client.build_default_connection(builder)
|
140
161
|
end
|
141
162
|
end
|
142
|
-
|
143
|
-
# Internal: Set Plaid defaults on the Faraday connection.
|
144
|
-
#
|
145
|
-
# builder - The Faraday builder object.
|
146
|
-
def build_default_connection(builder)
|
147
|
-
builder.options[:timeout] = Plaid::Middleware::NETWORK_TIMEOUT
|
148
|
-
builder.headers = Plaid::Middleware::NETWORK_HEADERS
|
149
|
-
builder.request :json
|
150
|
-
builder.use Plaid::Middleware
|
151
|
-
builder.response :json, content_type: /\bjson$/
|
152
|
-
builder.adapter Faraday.default_adapter
|
153
|
-
end
|
154
163
|
end
|
155
164
|
end
|