plaid 1.7.1 → 2.0.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -0
  3. data/CONTRIBUTING.md +15 -0
  4. data/LICENSE +20 -0
  5. data/README.md +215 -63
  6. data/Rakefile +50 -4
  7. data/UPGRADING.md +45 -0
  8. data/bin/console +13 -0
  9. data/bin/setup +8 -0
  10. data/lib/plaid.rb +51 -88
  11. data/lib/plaid/account.rb +144 -0
  12. data/lib/plaid/category.rb +62 -0
  13. data/lib/plaid/client.rb +67 -0
  14. data/lib/plaid/connector.rb +168 -0
  15. data/lib/plaid/errors.rb +24 -14
  16. data/lib/plaid/income.rb +106 -0
  17. data/lib/plaid/info.rb +65 -0
  18. data/lib/plaid/institution.rb +240 -0
  19. data/lib/plaid/risk.rb +34 -0
  20. data/lib/plaid/transaction.rb +123 -0
  21. data/lib/plaid/user.rb +430 -0
  22. data/lib/plaid/version.rb +1 -1
  23. data/plaid.gemspec +20 -12
  24. metadata +58 -62
  25. data/.gitignore +0 -15
  26. data/.rspec +0 -2
  27. data/.travis.yml +0 -5
  28. data/LICENSE.txt +0 -22
  29. data/PUBLISHING.md +0 -21
  30. data/lib/plaid/config.rb +0 -19
  31. data/lib/plaid/connection.rb +0 -109
  32. data/lib/plaid/models/account.rb +0 -24
  33. data/lib/plaid/models/category.rb +0 -17
  34. data/lib/plaid/models/exchange_token_response.rb +0 -11
  35. data/lib/plaid/models/info.rb +0 -12
  36. data/lib/plaid/models/institution.rb +0 -22
  37. data/lib/plaid/models/transaction.rb +0 -24
  38. data/lib/plaid/models/user.rb +0 -189
  39. data/spec/plaid/config_spec.rb +0 -67
  40. data/spec/plaid/connection_spec.rb +0 -191
  41. data/spec/plaid/error_spec.rb +0 -10
  42. data/spec/plaid/models/account_spec.rb +0 -37
  43. data/spec/plaid/models/category_spec.rb +0 -16
  44. data/spec/plaid/models/institution_spec.rb +0 -19
  45. data/spec/plaid/models/transaction_spec.rb +0 -28
  46. data/spec/plaid/models/user_spec.rb +0 -172
  47. data/spec/plaid_spec.rb +0 -263
  48. data/spec/spec_helper.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 331976cd945495c539e38747adbe9c2ff36722c5
4
- data.tar.gz: 7f875ded55c1c8deaae0e034f54b49df31121d5f
3
+ metadata.gz: 4c62ea201045ddda027e83f884439932f0082e16
4
+ data.tar.gz: ec7d5dc05c5e46d3354e4ba22bdda8991eef288a
5
5
  SHA512:
6
- metadata.gz: db782030a2e91663aa203212b919fbca03da6839757587aa2b8a59dc99daa0100d1e56e794dbcae558b7ca5257b8ddd07f098cba183ddff1bf8ff9a40b609a65
7
- data.tar.gz: ba4af752bcf6d6df50512217878c20aa8414c59fee9f266aff3b752f66cf875cb13b63134e4deb8cfe83ac88da06ed252486bfc49e2ad5242d5d8f5b19ee3902
6
+ metadata.gz: cd341de88925e995b587a8aefcc6f5a02b0943497d2f26cfe54332a733c4c75e71a82eee39afa5b17403bad198d67fb1da67e4a241c5a7ecd0443c547a0e8659
7
+ data.tar.gz: b5b9e8c56523456773b27f579ddbab5def4a49d551a7d28399f75cf8eb2a3d3ae2ac43c881e425ca72cf459cde18d9676a3d56e5aa4da926930227957cb1816b
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 2.0.0.alpha. 06-May-2016
2
+
3
+ * Rewrite everything.
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,15 @@
1
+ # Contributing
2
+
3
+ 1. Make one or more atomic commits, and ensure that each commit has a
4
+ descriptive commit message. Commit messages should be line wrapped
5
+ at 72 characters.
6
+
7
+ 2. Make sure that there are tests for the code you wrote.
8
+
9
+ 3. Make sure that you've documented all public methods using [TomDoc](http://tomdoc.org/).
10
+
11
+ 4. Run `rake test`, and address any errors. Preferably, fix commits
12
+ in place using `git rebase` or `git commit --amend` to make the
13
+ changes easier to review.
14
+
15
+ 5. Open a pull request.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Plaid Technologies, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,16 +1,6 @@
1
- # Plaid [![Build Status](https://travis-ci.org/plaid/plaid-ruby.svg?branch=release_v_1.0.0)](https://travis-ci.org/plaid/plaid-ruby) [![Gem Version](https://badge.fury.io/rb/plaid.svg)](http://badge.fury.io/rb/plaid)
1
+ # Plaid [![Build Status](https://travis-ci.org/plaid/plaid-ruby.svg)](https://travis-ci.org/plaid/plaid-ruby) [![Gem Version](https://badge.fury.io/rb/plaid.svg)](http://badge.fury.io/rb/plaid)
2
2
 
3
- Ruby bindings for the Plaid API
4
-
5
- ## Notes
6
-
7
- This version is a beta version that contains failing tests for the new 'info' endpoint. While these have been tested individually on real accounts the tests here will fail with the test accounts supplied. These will be updated soon with test credentials.
8
-
9
- Latest stable version: **1.7.1**
10
-
11
- This version removes the need to use 'type' in each additional call.
12
-
13
- **Warning: If you have been using any version < 1 please switch to the correct branch (V0.1.6). Installing without specifying a version from RubyGems results in V1.1 build. **
3
+ Ruby bindings for the Plaid API.
14
4
 
15
5
  ## Installation
16
6
 
@@ -20,106 +10,268 @@ Add this line to your application's Gemfile:
20
10
  gem 'plaid'
21
11
  ```
22
12
 
23
- And install
13
+ And then execute:
24
14
 
25
15
  $ bundle
26
16
 
27
- Or install it system wide as:
17
+ Or install it yourself as:
28
18
 
29
19
  $ gem install plaid
30
20
 
21
+ The gem supports Ruby 2.x only.
22
+
31
23
  ## Usage
32
24
 
33
- Please read the great documentation at http://plaid.com/docs/ for more information.
25
+ This gem wraps the Plaid API, which is fully described in the [documentation](http://plaid.com/docs).
26
+
27
+ The RubyDoc for the gem is available [here](http://plaid.github.io/plaid-ruby).
28
+
29
+ ### Configuring access to Plaid
34
30
 
35
- ### Configuring Plaid
36
- Configure the gem with your customer id, secret key, and the environment path you would like to use.
31
+ Configure the gem with your client id, secret, and the environment you would like to use.
37
32
 
38
33
  ```ruby
39
34
  Plaid.config do |p|
40
- p.customer_id = 'Plaid provided customer ID here'
41
- p.secret = 'Plaid provided secret key here'
42
- p.environment_location = 'URL for the development or production environment'
43
- # i.e. 'https://tartan.plaid.com/' for development, or
44
- # 'https://api.plaid.com/' for production
35
+ p.client_id = '<<< Plaid provided client ID >>>'
36
+ p.secret = '<<< Plaid provided secret key >>>'
37
+ p.env = :tartan # or :api for production
45
38
  end
46
39
  ```
47
40
 
48
- ### Creating a new Plaid User
49
- Authenticate a user to your desired level of api access (auth / connect).
41
+ ### Creating a new User
42
+
43
+ ```ruby
44
+ user = Plaid::User.create(:connect, 'wells', 'plaid_test', 'plaid_good')
45
+ ```
46
+
47
+ This call will do a `POST /connect`. The response will contain account information and transactions
48
+ for last 30 days, which you can find in `user.accounts` and `user.initial_transactions`, accordingly.
49
+
50
+ If the authentication requires a pin, you can pass it as a named parameter:
51
+
52
+ ```ruby
53
+ user = Plaid::User.create(:income, 'usaa', 'plaid_test', 'plaid_good', 'wells', pin: '1234')
54
+ ```
55
+
56
+ To add options such as `login_only` or `webhook`, use `options` argument:
57
+
58
+ ```ruby
59
+ user = Plaid::User.create(:connect, 'wells', 'plaid_test', 'plaid_good',
60
+ options: { login_only: true, webhook: 'https://example.org/callbacks/plaid')
61
+ ```
62
+
63
+ The first argument for `Plaid::User.create` is always a product you want to add the user to (like,
64
+ `:connect`, `:auth`, `:info`, `:income`, or `:risk`). The user object is bound to the product, and subsequent
65
+ calls like `user.update` or `user.delete` are done for this product (i.e., `PATCH /info` and `DELETE /info`
66
+ for `:info`).
67
+
68
+ ### Instantiating a User with an existing access token
69
+
70
+ If you've already added the user and saved the access token, you should use `User.load`:
71
+
72
+ ```ruby
73
+ user = Plaid::User.load(:risk, 'access_token')
74
+ ```
75
+
76
+ This won't make any API requests by itself, just set the product and the token in the `User` instance.
77
+
78
+ ### Exchanging a Link public token for a Plaid access token
79
+
80
+ If you have a Link public token, use `User.exchange_token`:
81
+
82
+ ```ruby
83
+ user = Plaid::User.exchange_token('public_token') # bound to :connect product
84
+ ```
85
+
86
+ With more options:
87
+
88
+ ```ruby
89
+ user2 = Plaid::User.exchange_token('public_token', account_id: '...', product: :auth)
90
+ ```
91
+
92
+ ### Upgrading and changing the current product
93
+
94
+ Plaid supports upgrading a user, i.e. adding it to another product:
95
+
96
+ ```ruby
97
+ # Create a user in Connect
98
+ user = Plaid::User.create(:connect, 'wells', 'plaid_test', 'plaid_good')
99
+
100
+ # Upgrade this user, attaching it to Auth as well (makes a request to /upgrade).
101
+ auth_user = user.upgrade(:auth)
102
+ ```
103
+
104
+ The `auth_user` will be a different instance of `User`, attached to Auth, but the access token will be the same.
105
+
106
+ Sometimes you know that the user has already been added to another product. To get a `User` instance with
107
+ same access token, but different current product, use `User.for_product`:
108
+
109
+ ```ruby
110
+ # Get a user attached to Connect
111
+ user = Plaid::User.load(:connect, 'access_token')
112
+
113
+ # Makes no requests
114
+ info_user = user.for_product(:info)
115
+ ```
116
+
117
+ Basically it's the same as:
50
118
 
51
119
  ```ruby
52
- user = Plaid.add_user('auth', 'plaid_test', 'plaid_good', 'wells')
120
+ info_user = Plaid::User.load(:info, 'access_token')
53
121
  ```
54
122
 
55
- If the authentication requires a pin, you can pass it in as the fifth argument:
123
+ ### MFA (Multi-Factor Authorization)
124
+
125
+ If MFA is requested by the financial institution, the `User.create` call would behave
126
+ a bit differently:
56
127
 
57
128
  ```ruby
58
- user = Plaid.add_user('auth', 'plaid_test', 'plaid_good', 'usaa', '1234')
129
+ user = Plaid::User.create(:auth, 'wells', 'plaid_test', 'plaid_good')
130
+
131
+ user.accounts #=> nil
132
+ user.mfa? #=> true
133
+ user.mfa_type #=> :questions
134
+ user.mfa #=> [{question: "What's the nickname of the person who created Ruby?"}]
59
135
  ```
60
136
 
61
- To add options such as `login_only` or `webhooks`, use the sixth argument:
137
+ In this case you'll have to submit the answer to the question:
62
138
 
63
139
  ```ruby
64
- user = Plaid.add_user('auth', 'plaid_test', 'plaid_good', 'wells', nil, { login_only: true, webhooks: 'https://example.org/callbacks/plaid')
140
+ user.mfa_step('matz') # This is the correct answer!
141
+
142
+ user.mfa? #=> false
143
+ user.mfa_type #=> nil
144
+ user.mfa #=> nil
145
+ user.accounts #=> [<Plaid::Account ...>, ...]
65
146
  ```
66
147
 
67
- ### Restoring a Plaid User using an access token
148
+ The code-based MFA workflow is similar. Basically you need to call `user.mfa_step(...)`
149
+ until `user.mfa?` becomes false.
150
+
151
+ ### Obtaining user-related data
152
+
153
+ If you have a live `User` instance, you can use following methods
154
+ (independent of instance's current product):
155
+
156
+ * `user.transactions(...)`. Makes a `/connect/get` request.
157
+ * `user.auth(sync: false)`. Makes an `/auth/get` request.
158
+ * `user.info(sync: false)`. Makes an `/info/get` request.
159
+ * `user.income(sync: false)`. Makes an `/income/get` request.
160
+ * `user.risk(sync: false)`. Makes an `/risk/get` request.
161
+ * `user.balance`. Makes an `/balance` request.
162
+
163
+ All of these methods return appropriate data, but they also update the cached `user.accounts`. That is,
164
+ if you user has access to Auth and Risk products, the following code:
68
165
 
69
166
  ```ruby
70
- user = Plaid.set_user('access_token')
167
+ user = User.load(:auth, 'access_token')
168
+ user.auth
169
+ user.risk
71
170
  ```
171
+ will result in `user.accounts` having both routing number and risk information for all the accounts. The
172
+ subsequent `user.balance` call will just update the current balance, not touching the routing and risk information.
173
+
174
+ The `sync` flag, if set to true, will result in updating the information from the server even if it has already been
175
+ loaded. Otherwise cached information will be returned:
72
176
 
73
177
  ```ruby
74
- user = Plaid.set_user('access_token', ['connect'])
178
+ user = User.load(:auth, 'access_token') # Just set the token
179
+ user.auth # POST /auth/get
180
+ user.auth # No POST, return cached info
181
+ user.auth(sync: true) # POST /auth/get again
75
182
  ```
76
183
 
77
- ### Exchanging a Link public_token for a Plaid access_token
184
+ Same goes for other methods, except `User#transactions` and `User#balance` which always make requests to the API.
185
+
186
+ ### Categories
187
+
188
+ You can request category information:
78
189
 
79
190
  ```ruby
191
+ cats = Plaid::Category.all # Array of all known categories
192
+ cat = Plaid::Category.get('17001013') # A single category by its ID
193
+ ```
194
+
195
+ ### Institutions
196
+
197
+ Financial institution information is available via `Plaid::Institution` and `Plaid::LongTailInstitution`:
198
+
199
+ ```ruby
200
+ insts = Plaid::Institution.all # Array of all major financial institutions
201
+ inst = Plaid::Institution.get('5301a93ac140de84910000e0') # A single institution by its ID
202
+
203
+ lti = Plaid::LongTailInstitution.get('bofa') # A single one
204
+ ltis = Plaid::LongTailInstitution.all(count: 20, offset: 20) # A page
205
+ res = Plaid::LongTailInstitution.search(query: 'c') # Lookup by name
206
+ ```
207
+
208
+ ### Custom clients
209
+
210
+ It's possible to use several Plaid environments and/or credentials in one app by
211
+ explicit instantiation of `Plaid::Client`:
212
+
213
+ ```ruby
214
+ # Configuring the global client (Plaid.client) which is used by default
80
215
  Plaid.config do |p|
81
- p.customer_id = 'test_id'
82
- p.secret = 'test_secret'
83
- p.environment_location = 'https://tartan.plaid.com'
216
+ p.client_id = 'client_id_1'
217
+ p.secret = 'secret_1'
218
+ p.env = :tartan
84
219
  end
85
220
 
86
- # Exchange a Link public_token for a Plaid access_token
87
- exchangeTokenResponse = Plaid.exchange_token('test,chase,connected')
88
- # Optionally include an account_id
89
- exchangeTokenResponse = Plaid.exchange_token('test,chase,connected', 'account_id')
221
+ # Creating a custom client
222
+ api = Plaid::Client.new(client_id: 'client_id_2', 'secret_2', env: :api)
90
223
 
91
- # Use the API access_token to initialize a user
92
- # Note: This example assumes you are using Link with the "auth" product
93
- user = Plaid.set_user(exchangeTokenResponse.access_token, ['auth'])
224
+ # Tartan user (using default client)
225
+ user1 = Plaid::User.create(:connect, 'wells', 'plaid_test', 'plaid_good')
94
226
 
95
- # Retrieve the user's accounts
96
- user.get('auth')
227
+ # Api user (using api client)
228
+ user2 = Plaid::User.create(:connect, 'wells', 'plaid_test', 'plaid_good', client: api)
97
229
 
98
- # Print the name of each account
99
- user.accounts.each { |account| print account.meta['name'] + "\n"}
230
+ # Lookup a long tail institution in production
231
+ res = Plaid::LongTailInstitution.search(query: 'c', client: api)
100
232
  ```
101
233
 
102
- ## Semantic Versioning
234
+ The `client` option can be passed to the following methods:
235
+
236
+ * `User.create`
237
+ * `User.load`
238
+ * `User.exchange_token`
239
+ * `Category.all`
240
+ * `Category.get`
241
+ * `Institution.all`
242
+ * `Institution.get`
243
+ * `LongTailInstitution.all`
244
+ * `LongTailInstitution.search`
245
+ * `LongTailInstitution.get`
246
+
247
+ ### Errors
248
+
249
+ Any methods making API calls will result in an exception raised unless the response code is "200: Success" or
250
+ "201: MFA Required".
251
+
252
+ `Plaid::BadRequestError` is raised when status code is "400: Bad Request".
253
+
254
+ `Plaid::UnauthorizedError` is raised when status code is "401: Unauthorized".
255
+
256
+ `Plaid::RequestFailedError` is raised when status code is "402: Request Failed".
257
+
258
+ `Plaid::NotFoundError` is raised when status code is "404: Cannot be Found".
259
+
260
+ `Plaid::ServerError` is raised when status code is "50X: Server Error".
103
261
 
104
- Methods marked with `API: public` are officially supported by the gem maintainers. Since
105
- we are using semantic versioning (http://semver.org/spec/v2.0.0.html), the maintainers are
106
- committed to backwards-compatibility support for these API calls when we update the Minor
107
- version. So for example, going from version 1.4.x to 1.5.x will not change these public
108
- API calls.
262
+ Read more about response codes and their meaning in the
263
+ [Plaid documentation](https://plaid.com/docs/api/#response-codes).
109
264
 
110
- However, we may change these method signatures or even the gem architecture when updating
111
- the Major number. For example, we have some breaking changes in mind with version 2.0
265
+ ## Development
112
266
 
113
- Methods marked with `API: semi-private` are used internally for consistency. While it is
114
- possible to monkey-patch against them for your own use, the maintainers make no guarantees
115
- on backwards compatibility.
267
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
116
268
 
117
- ## Learn More
269
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
118
270
 
119
- Learn about the full functionality of the library on our [Wiki](https://github.com/plaid/plaid-ruby/wiki)
271
+ ## Contributing
120
272
 
121
- ## Contribute
273
+ Bug reports and pull requests are welcome on GitHub at https://github.com/plaid/plaid-ruby. See also [contributing guidelines](CONTRIBUTING.md).
122
274
 
123
- We highly encourage helping out with the gem. Either adding more tests, building new helper classes, fixing bugs, or anything to increase overall quality.
275
+ ## License
124
276
 
125
- Learn more about best practices, submitting a pull request, and rules for the build on our [Wiki](https://github.com/plaid/plaid-ruby/wiki/Contribute!)
277
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,8 +1,54 @@
1
- require 'rake'
2
- require 'rspec/core/rake_task'
3
1
  require 'bundler/gem_tasks'
2
+ require 'sdoc'
3
+ require 'rdoc/task'
4
+ require 'rake/testtask'
5
+ require 'fileutils'
4
6
 
5
- RSpec::Core::RakeTask.new(:spec)
7
+ RDoc::Task.new do |rdoc|
8
+ rdoc.rdoc_dir = 'doc/rdoc'
9
+ rdoc.generator = 'sdoc'
10
+ rdoc.main = 'README.md'
6
11
 
7
- task :default => :spec
12
+ rdoc.rdoc_files.include('README.md', 'LICENSE', 'UPGRADING.md',
13
+ 'CONTRIBUTING.md', 'CHANGELOG.md', 'lib/**/*.rb')
14
+ rdoc.markup = 'tomdoc'
15
+ end
8
16
 
17
+ Rake::TestTask.new do |t|
18
+ t.libs << 'test'
19
+ t.test_files = FileList['test/test*.rb']
20
+ t.verbose = true
21
+ t.ruby_opts << '-rminitest/pride'
22
+ end
23
+
24
+ desc 'Update the gh-pages branch with doc/rdoc contents'
25
+ task :update_gh_pages do
26
+ tmpdir = Dir::Tmpname.create('plaid_docs') {}
27
+
28
+ desc = `git describe`.chomp
29
+
30
+ sh "git clone --shared . #{tmpdir}"
31
+
32
+ Dir.chdir(tmpdir) do
33
+ sh 'git checkout gh-pages'
34
+ FileUtils.rm_rf Dir.glob("#{tmpdir}/*")
35
+ end
36
+
37
+ FileUtils.cp_r Dir.glob('doc/rdoc/*'), tmpdir
38
+
39
+ Dir.chdir(tmpdir) do
40
+ sh 'git add .'
41
+ sh 'git add --update .'
42
+ sh "git commit --allow-empty -m 'Regenerate docs for #{desc}'"
43
+ sh 'git push'
44
+ end
45
+
46
+ FileUtils.rm_rf tmpdir
47
+ end
48
+
49
+ desc 'Generate rdoc and update gh-pages on GitHub'
50
+ task update_github_docs: %i(rdoc update_gh_pages) do
51
+ sh 'git push origin gh-pages'
52
+ end
53
+
54
+ task default: :test