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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/CONTRIBUTING.md +15 -0
- data/LICENSE +20 -0
- data/README.md +215 -63
- data/Rakefile +50 -4
- data/UPGRADING.md +45 -0
- data/bin/console +13 -0
- data/bin/setup +8 -0
- data/lib/plaid.rb +51 -88
- data/lib/plaid/account.rb +144 -0
- data/lib/plaid/category.rb +62 -0
- data/lib/plaid/client.rb +67 -0
- data/lib/plaid/connector.rb +168 -0
- data/lib/plaid/errors.rb +24 -14
- data/lib/plaid/income.rb +106 -0
- data/lib/plaid/info.rb +65 -0
- data/lib/plaid/institution.rb +240 -0
- data/lib/plaid/risk.rb +34 -0
- data/lib/plaid/transaction.rb +123 -0
- data/lib/plaid/user.rb +430 -0
- data/lib/plaid/version.rb +1 -1
- data/plaid.gemspec +20 -12
- metadata +58 -62
- data/.gitignore +0 -15
- data/.rspec +0 -2
- data/.travis.yml +0 -5
- data/LICENSE.txt +0 -22
- data/PUBLISHING.md +0 -21
- data/lib/plaid/config.rb +0 -19
- data/lib/plaid/connection.rb +0 -109
- data/lib/plaid/models/account.rb +0 -24
- data/lib/plaid/models/category.rb +0 -17
- data/lib/plaid/models/exchange_token_response.rb +0 -11
- data/lib/plaid/models/info.rb +0 -12
- data/lib/plaid/models/institution.rb +0 -22
- data/lib/plaid/models/transaction.rb +0 -24
- data/lib/plaid/models/user.rb +0 -189
- data/spec/plaid/config_spec.rb +0 -67
- data/spec/plaid/connection_spec.rb +0 -191
- data/spec/plaid/error_spec.rb +0 -10
- data/spec/plaid/models/account_spec.rb +0 -37
- data/spec/plaid/models/category_spec.rb +0 -16
- data/spec/plaid/models/institution_spec.rb +0 -19
- data/spec/plaid/models/transaction_spec.rb +0 -28
- data/spec/plaid/models/user_spec.rb +0 -172
- data/spec/plaid_spec.rb +0 -263
- data/spec/spec_helper.rb +0 -14
data/lib/plaid/models/account.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module Plaid
|
2
|
-
class Account
|
3
|
-
attr_accessor :available_balance, :current_balance, :institution_type, :meta, :transactions, :numbers, :name, :id, :type, :subtype
|
4
|
-
|
5
|
-
def initialize(hash)
|
6
|
-
@id = hash['_id']
|
7
|
-
@name = hash['meta']['name'] if hash['meta']
|
8
|
-
@type = hash['type']
|
9
|
-
@meta = hash['meta']
|
10
|
-
@institution_type = hash['institution_type']
|
11
|
-
|
12
|
-
if hash['balance']
|
13
|
-
@available_balance = hash['balance']['available']
|
14
|
-
@current_balance = hash['balance']['current']
|
15
|
-
end
|
16
|
-
|
17
|
-
# Depository account only, "checkings" or "savings"
|
18
|
-
# Available on live data, but not on the test data
|
19
|
-
@subtype = hash['subtype']
|
20
|
-
|
21
|
-
@numbers = hash['numbers'] ? hash['numbers'] : 'Upgrade user to access routing information for this account'
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Plaid
|
2
|
-
class Category
|
3
|
-
attr_accessor :type, :hierarchy, :id
|
4
|
-
|
5
|
-
def initialize(fields = {})
|
6
|
-
@type = fields['type']
|
7
|
-
@hierarchy = fields['hierarchy']
|
8
|
-
@id = fields['id']
|
9
|
-
end
|
10
|
-
|
11
|
-
# API: semi-private
|
12
|
-
# This method takes an array returned from the API and instantiates all of the categories
|
13
|
-
def self.all(res)
|
14
|
-
res.map { |cat| new(cat) }
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module Plaid
|
2
|
-
class ExchangeTokenResponse
|
3
|
-
attr_accessor :access_token
|
4
|
-
attr_accessor :stripe_bank_account_token
|
5
|
-
|
6
|
-
def initialize(fields = {})
|
7
|
-
@access_token = fields['access_token']
|
8
|
-
@stripe_bank_account_token = fields['stripe_bank_account_token']
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
data/lib/plaid/models/info.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
module Plaid
|
2
|
-
class Information
|
3
|
-
attr_accessor :names, :emails, :phone_numbers, :addresses
|
4
|
-
|
5
|
-
def initialize(hash)
|
6
|
-
@names = hash['names']
|
7
|
-
@emails = hash['emails']
|
8
|
-
@phone_numbers = hash['phone_numbers']
|
9
|
-
@addresses = hash['addresses']
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Plaid
|
2
|
-
class Institution
|
3
|
-
attr_accessor :id, :name, :type, :has_mfa, :mfa, :credentials, :products
|
4
|
-
|
5
|
-
def initialize(fields = {})
|
6
|
-
@id = fields['id']
|
7
|
-
@name = fields['name']
|
8
|
-
@type = fields['type']
|
9
|
-
@has_mfa = fields['has_mfa']
|
10
|
-
@mfa = fields['mfa']
|
11
|
-
@credentials = fields['credentials']
|
12
|
-
@products = fields['products']
|
13
|
-
end
|
14
|
-
|
15
|
-
# API: semi-private
|
16
|
-
# This method takes an array returned from the API and instantiates all of the institutions
|
17
|
-
def self.all(res)
|
18
|
-
res.map { |inst| new(inst) }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Plaid
|
2
|
-
class Transaction
|
3
|
-
attr_accessor :id, :account, :date, :amount, :name, :meta, :location, :pending, :score, :cat, :type, :category, :category_id, :pending_transaction
|
4
|
-
|
5
|
-
def initialize(fields = {})
|
6
|
-
@id = fields['_id']
|
7
|
-
@account = fields['_account']
|
8
|
-
@date = fields['date']
|
9
|
-
@amount = fields['amount']
|
10
|
-
@name = fields['name']
|
11
|
-
@location = fields['meta'].nil? ? {} : fields['meta']['location']
|
12
|
-
@pending = fields['pending']
|
13
|
-
@pending_transaction = fields['_pendingTransaction']
|
14
|
-
@score = fields['score']
|
15
|
-
@cat = Category.new({ 'id' => fields['category_id'], 'hierarchy' => fields['category'], 'type' => fields['type'] })
|
16
|
-
|
17
|
-
# Here for backwards compatibility only.
|
18
|
-
@type = fields['type']
|
19
|
-
@category = fields['category']
|
20
|
-
@category_id = fields['category_id']
|
21
|
-
@meta = fields['meta']
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/lib/plaid/models/user.rb
DELETED
@@ -1,189 +0,0 @@
|
|
1
|
-
require_relative 'account'
|
2
|
-
require_relative 'transaction'
|
3
|
-
require_relative 'info'
|
4
|
-
require 'json'
|
5
|
-
|
6
|
-
module Plaid
|
7
|
-
class User
|
8
|
-
attr_accessor :accounts, :transactions, :access_token, :type, :permissions, :api_res, :pending_mfa_questions, :info, :information
|
9
|
-
|
10
|
-
# API: public
|
11
|
-
# Use this method to select the MFA method
|
12
|
-
def select_mfa_method(selection, type=nil)
|
13
|
-
type = self.type if type.nil?
|
14
|
-
auth_path = self.permissions.last + '/step'
|
15
|
-
res = Connection.post(auth_path, { options: { send_method: selection }.to_json, access_token: self.access_token, type: type })
|
16
|
-
update(res, self.permissions.last)
|
17
|
-
end
|
18
|
-
|
19
|
-
# API: public
|
20
|
-
# Use this method to send back the MFA code or answer
|
21
|
-
def mfa_authentication(auth, type = nil)
|
22
|
-
type = self.type if type.nil?
|
23
|
-
auth_path = self.permissions.last + '/step'
|
24
|
-
res = Connection.post(auth_path, { mfa: auth, access_token: self.access_token, type: type })
|
25
|
-
self.accounts = []
|
26
|
-
self.transactions = []
|
27
|
-
update(res)
|
28
|
-
end
|
29
|
-
|
30
|
-
# API: public
|
31
|
-
# Use this method to find out API levels available for this user
|
32
|
-
def permit?(auth_level)
|
33
|
-
self.permissions.include? auth_level
|
34
|
-
end
|
35
|
-
|
36
|
-
# API: public
|
37
|
-
# Use this method to upgrade a user to another api level
|
38
|
-
def upgrade(api_level=nil)
|
39
|
-
if api_level.nil?
|
40
|
-
api_level = 'auth' unless self.permit? 'auth'
|
41
|
-
api_level = 'connect' unless self.permit? 'connect'
|
42
|
-
end
|
43
|
-
res = Connection.post('upgrade', { access_token: self.access_token, upgrade_to: api_level })
|
44
|
-
|
45
|
-
# Reset accounts and transaction
|
46
|
-
self.accounts = []
|
47
|
-
self.transactions = []
|
48
|
-
update(res)
|
49
|
-
end
|
50
|
-
|
51
|
-
# API: public
|
52
|
-
# Use this method to delete a user from the Plaid API
|
53
|
-
def delete_user
|
54
|
-
Connection.delete('info', { access_token: self.access_token })
|
55
|
-
end
|
56
|
-
|
57
|
-
### Internal build methods
|
58
|
-
def initialize
|
59
|
-
self.accounts = []
|
60
|
-
self.transactions = []
|
61
|
-
self.permissions = []
|
62
|
-
self.access_token = ''
|
63
|
-
self.api_res = ''
|
64
|
-
self.info = {}
|
65
|
-
end
|
66
|
-
|
67
|
-
# API: semi-private
|
68
|
-
# This class method instantiates a new Account object and updates it with the results
|
69
|
-
# from the API
|
70
|
-
def self.build(res, api_level = nil)
|
71
|
-
self.new.update(res, api_level)
|
72
|
-
end
|
73
|
-
|
74
|
-
# API: semi-private
|
75
|
-
# This method updates Account with the results returned from the API
|
76
|
-
def update(res, api_level = nil)
|
77
|
-
self.permit! api_level
|
78
|
-
|
79
|
-
if res[:msg].nil?
|
80
|
-
populate_user!(res)
|
81
|
-
clean_up_user!
|
82
|
-
else
|
83
|
-
set_mfa_request!(res)
|
84
|
-
end
|
85
|
-
|
86
|
-
self
|
87
|
-
end
|
88
|
-
|
89
|
-
# Internal helper methods
|
90
|
-
|
91
|
-
# API: semi-private
|
92
|
-
# Internal helper method to set the available API levels
|
93
|
-
def permit!(api_level)
|
94
|
-
return if api_level.nil? || self.permit?(api_level)
|
95
|
-
self.permissions << api_level
|
96
|
-
end
|
97
|
-
|
98
|
-
# API: semi-private
|
99
|
-
# Gets auth, connect, or info of the user
|
100
|
-
# TODO: (2.0) auth_level should be symbols instead of string
|
101
|
-
def get(auth_level, options = {})
|
102
|
-
return false unless self.permit? auth_level
|
103
|
-
case auth_level
|
104
|
-
when 'auth'
|
105
|
-
update(Connection.post('auth/get', access_token: self.access_token))
|
106
|
-
when 'connect'
|
107
|
-
payload = { access_token: self.access_token }.merge(options)
|
108
|
-
update(Connection.post('connect/get', payload))
|
109
|
-
when 'info'
|
110
|
-
update(Connection.secure_get('info', self.access_token))
|
111
|
-
else
|
112
|
-
raise "Invalid auth level: #{auth_level}"
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
# API: semi-private
|
117
|
-
def get_auth
|
118
|
-
get('auth')
|
119
|
-
end
|
120
|
-
|
121
|
-
# API: semi-private
|
122
|
-
def get_connect(options={})
|
123
|
-
get('connect', options)
|
124
|
-
end
|
125
|
-
|
126
|
-
# API: semi-private
|
127
|
-
def get_info
|
128
|
-
get('info')
|
129
|
-
end
|
130
|
-
|
131
|
-
# API: semi-private
|
132
|
-
# Helper method to update user information
|
133
|
-
# Requires 'info' api level
|
134
|
-
def update_info(username,pass,pin=nil)
|
135
|
-
return false unless self.permit? 'info'
|
136
|
-
|
137
|
-
payload = { username: username, password: pass, access_token: self.access_token }
|
138
|
-
payload.merge!(pin: pin) if pin
|
139
|
-
update(Plaid.patch('info', payload))
|
140
|
-
end
|
141
|
-
|
142
|
-
# API: semi-private
|
143
|
-
# Helper method to update user balance
|
144
|
-
def update_balance
|
145
|
-
update(Connection.post('balance', { access_token: self.access_token }))
|
146
|
-
end
|
147
|
-
|
148
|
-
private
|
149
|
-
|
150
|
-
def clean_up_user!
|
151
|
-
self.accounts.select! { |c| c.instance_of? Account }
|
152
|
-
end
|
153
|
-
|
154
|
-
def set_mfa_request!(res)
|
155
|
-
self.access_token = res[:body]['access_token']
|
156
|
-
self.pending_mfa_questions = res[:body]
|
157
|
-
self.api_res = res[:msg]
|
158
|
-
end
|
159
|
-
|
160
|
-
def populate_user!(res)
|
161
|
-
res['accounts'].each do |account|
|
162
|
-
if self.accounts.none? { |h| h.id == account['_id'] }
|
163
|
-
self.accounts << Account.new(account)
|
164
|
-
end
|
165
|
-
end if res['accounts']
|
166
|
-
|
167
|
-
res['transactions'].each do |transaction|
|
168
|
-
if self.transactions.any? { |t| t == transaction['_id'] }
|
169
|
-
owned_transaction = self.transactions.find { |h| h == transaction['_id'] }
|
170
|
-
owned_transaction.new(transaction)
|
171
|
-
else
|
172
|
-
self.transactions << Transaction.new(transaction)
|
173
|
-
end
|
174
|
-
end if res['transactions']
|
175
|
-
|
176
|
-
self.pending_mfa_questions = {}
|
177
|
-
self.information = Information.new(res['info']) if res['info']
|
178
|
-
self.api_res = 'success'
|
179
|
-
|
180
|
-
# TODO: Remove the following line when upgrading to V-2
|
181
|
-
self.info.merge!(res['info']) if res['info']
|
182
|
-
# End TODO
|
183
|
-
|
184
|
-
self.access_token = res['access_token'].split[0]
|
185
|
-
self.type = res['access_token'].split[1]
|
186
|
-
end
|
187
|
-
|
188
|
-
end
|
189
|
-
end
|
data/spec/plaid/config_spec.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
describe 'Plaid.config' do
|
2
|
-
around(:each) do |example|
|
3
|
-
old_customer_id = Plaid.customer_id
|
4
|
-
old_secret = Plaid.secret
|
5
|
-
old_environment_location = Plaid.environment_location
|
6
|
-
|
7
|
-
Plaid.config do |p|
|
8
|
-
p.customer_id = customer_id
|
9
|
-
p.secret = secret
|
10
|
-
p.environment_location = environment_location
|
11
|
-
end
|
12
|
-
|
13
|
-
example.run
|
14
|
-
|
15
|
-
Plaid.config do |p|
|
16
|
-
p.customer_id = old_customer_id
|
17
|
-
p.secret = old_secret
|
18
|
-
p.environment_location = old_environment_location
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
let(:customer_id) { 'test_id' }
|
23
|
-
let(:secret) { 'test_secret' }
|
24
|
-
let(:dev_url) { 'https://tartan.plaid.com/' }
|
25
|
-
let(:prod_url) { 'https://api.plaid.com/' }
|
26
|
-
|
27
|
-
|
28
|
-
let(:user) { Plaid.add_user('connect', 'plaid_test', 'plaid_good', 'wells') }
|
29
|
-
|
30
|
-
context ':environment_location' do
|
31
|
-
context 'with trailing slash' do
|
32
|
-
let(:environment_location) { 'http://example.org/' }
|
33
|
-
it 'leaves it as-is' do
|
34
|
-
expect(Plaid.environment_location).to eql(environment_location)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'without trailing slash' do
|
39
|
-
let(:environment_location) { 'http://example.org' }
|
40
|
-
it 'adds a trailing slash' do
|
41
|
-
expect(Plaid.environment_location).to eql(environment_location + '/')
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'has valid dev keys' do
|
47
|
-
let(:environment_location) { dev_url }
|
48
|
-
it { expect(user).to be_instance_of Plaid::User }
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'has valid production keys' do
|
52
|
-
let(:environment_location) { prod_url }
|
53
|
-
it { expect(user).to be_instance_of Plaid::User }
|
54
|
-
end
|
55
|
-
|
56
|
-
context 'has invalid dev keys' do
|
57
|
-
let(:secret) { 'test_bad' }
|
58
|
-
let(:environment_location) { dev_url }
|
59
|
-
it { expect { user }.to raise_error(Plaid::Unauthorized, 'secret or client_id invalid') }
|
60
|
-
end
|
61
|
-
|
62
|
-
context 'has invalid production keys' do
|
63
|
-
let(:secret) { 'test_bad' }
|
64
|
-
let(:environment_location) { prod_url }
|
65
|
-
it { expect { user }.to raise_error(Plaid::Unauthorized, 'secret or client_id invalid') }
|
66
|
-
end
|
67
|
-
end
|
@@ -1,191 +0,0 @@
|
|
1
|
-
describe Plaid::Connection do
|
2
|
-
let(:stub_url) { "https://tartan.plaid.com/testing" }
|
3
|
-
let(:bad_req_response) { {"code" => 1005, "message" => "invalid credentials", "resolve" => "The username or password provided is not correct."}.to_json }
|
4
|
-
let(:unauth_response) { {"code" => 1105, "message" => "bad access_token", "resolve" => "This access_token appears to be corrupted."}.to_json }
|
5
|
-
let(:req_fail_response) { {"code" => 1200, "message" => "invalid credentials", "resolve" => "The username or password provided is not correct."}.to_json }
|
6
|
-
let(:req_not_found) { {"code" => 1600, "message" => "product not found", "resolve" => "This product doesn't exist yet, we're actually not sure how you reached this error..."}.to_json }
|
7
|
-
|
8
|
-
describe "#post" do
|
9
|
-
it "sends a post request" do
|
10
|
-
stub = stub_request(:post, stub_url).to_return({:body => {"response" => "OK"}.to_json})
|
11
|
-
Plaid::Connection.post("testing")
|
12
|
-
expect(stub).to have_requested(:post, stub_url)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "returns response on 200 response" do
|
16
|
-
stub = stub_request(:post, stub_url).to_return({:body => {"response" => "OK"}.to_json})
|
17
|
-
response = Plaid::Connection.post("testing")
|
18
|
-
expect(response).to eq({"response" => "OK"})
|
19
|
-
end
|
20
|
-
|
21
|
-
it "returns message on 201 response" do
|
22
|
-
stub = stub_request(:post, stub_url).to_return(status: 201, body: {"response" => "OK"}.to_json)
|
23
|
-
response = Plaid::Connection.post("testing")
|
24
|
-
expect(response).to eq({:msg => "Requires further authentication", :body => {"response" => "OK"}})
|
25
|
-
end
|
26
|
-
|
27
|
-
it "throws Plaid::BadRequest on 400 response" do
|
28
|
-
stub = stub_request(:post, stub_url).to_return(status: 400, body: bad_req_response)
|
29
|
-
expect { Plaid::Connection.post("testing") }.to raise_error(Plaid::BadRequest, "invalid credentials")
|
30
|
-
end
|
31
|
-
|
32
|
-
it "throws Plaid::Unauthorized on 401 response" do
|
33
|
-
stub = stub_request(:post, stub_url).to_return(status: 401, body: unauth_response)
|
34
|
-
expect { Plaid::Connection.post("testing") }.to raise_error(Plaid::Unauthorized, "bad access_token")
|
35
|
-
end
|
36
|
-
|
37
|
-
it "throws Plaid::RequestFailed on 402 response" do
|
38
|
-
stub = stub_request(:post, stub_url).to_return(status: 402, body: req_fail_response)
|
39
|
-
expect { Plaid::Connection.post("testing") }.to raise_error(Plaid::RequestFailed, "invalid credentials")
|
40
|
-
end
|
41
|
-
|
42
|
-
it "throws a Plaid::NotFound on 404 response" do
|
43
|
-
stub = stub_request(:post, stub_url).to_return(status: 404, body: req_not_found)
|
44
|
-
expect { Plaid::Connection.post("testing") }.to raise_error(Plaid::NotFound, "product not found")
|
45
|
-
end
|
46
|
-
|
47
|
-
it "throws a Plaid::ServerError on empty response" do
|
48
|
-
stub = stub_request(:post, stub_url).to_return(status: 504, body: '')
|
49
|
-
expect { Plaid::Connection.post("testing") }.to raise_error(Plaid::ServerError, '')
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#get" do
|
54
|
-
it "sends a get request" do
|
55
|
-
stub = stub_request(:get, stub_url).to_return({:body => {"response" => "OK"}.to_json})
|
56
|
-
Plaid::Connection.get("testing")
|
57
|
-
expect(stub).to have_requested(:get, stub_url)
|
58
|
-
end
|
59
|
-
|
60
|
-
it "returns response when no code available" do
|
61
|
-
stub = stub_request(:get, stub_url).to_return({:body => {"response" => "OK"}.to_json})
|
62
|
-
response = Plaid::Connection.get("testing")
|
63
|
-
expect(response).to eq({"response" => "OK"})
|
64
|
-
end
|
65
|
-
|
66
|
-
it "returns response when code not [1301, 1401, 1501, 1601]" do
|
67
|
-
stub = stub_request(:get, stub_url).to_return({:body => {"code" => 1502, "response" => "OK"}.to_json})
|
68
|
-
response = Plaid::Connection.get("testing")
|
69
|
-
expect(response).to eq({"code" => 1502, "response" => "OK"})
|
70
|
-
end
|
71
|
-
|
72
|
-
it "throws 404 for 1301 code" do
|
73
|
-
stub = stub_request(:get, stub_url).to_return({:body => {"code" => 1301, "message" => "Doesn't matter", "resolve" => "Yep."}.to_json})
|
74
|
-
expect { Plaid::Connection.get("testing")}.to raise_error(Plaid::NotFound, "Doesn't matter")
|
75
|
-
end
|
76
|
-
|
77
|
-
it "throws 404 for 1401 code" do
|
78
|
-
stub = stub_request(:get, stub_url).to_return({:body => {"code" => 1401, "message" => "Doesn't matter", "resolve" => "Yep."}.to_json})
|
79
|
-
expect { Plaid::Connection.get("testing")}.to raise_error(Plaid::NotFound, "Doesn't matter")
|
80
|
-
end
|
81
|
-
|
82
|
-
it "throws 404 for 1501 code" do
|
83
|
-
stub = stub_request(:get, stub_url).to_return({:body => {"code" => 1501, "message" => "Doesn't matter", "resolve" => "Yep."}.to_json})
|
84
|
-
expect { Plaid::Connection.get("testing")}.to raise_error(Plaid::NotFound, "Doesn't matter")
|
85
|
-
end
|
86
|
-
|
87
|
-
it "throws 404 for 1601 code" do
|
88
|
-
stub = stub_request(:get, stub_url).to_return({:body => {"code" => 1601, "message" => "Doesn't matter", "resolve" => "Yep."}.to_json})
|
89
|
-
expect { Plaid::Connection.get("testing")}.to raise_error(Plaid::NotFound, "Doesn't matter")
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
describe "#secure_get" do
|
95
|
-
it "sends a secure get request" do
|
96
|
-
stub = stub_request(:get, stub_url).to_return({:body => {"response" => "OK"}.to_json})
|
97
|
-
Plaid::Connection.secure_get("testing", "test_wells")
|
98
|
-
expect(stub).to have_requested(:get, stub_url).with(:body => {:access_token => "test_wells"})
|
99
|
-
end
|
100
|
-
|
101
|
-
it "returns response on 200 response" do
|
102
|
-
stub = stub_request(:get, stub_url).to_return({:body => {"response" => "OK"}.to_json})
|
103
|
-
response = Plaid::Connection.secure_get("testing", "test_wells")
|
104
|
-
expect(response).to eq({"response" => "OK"})
|
105
|
-
end
|
106
|
-
|
107
|
-
it "returns message on 201 response" do
|
108
|
-
stub = stub_request(:get, stub_url).to_return(status: 201, body: {"response" => "OK"}.to_json)
|
109
|
-
response = Plaid::Connection.secure_get("testing", "test_wells")
|
110
|
-
expect(response).to eq({:msg => "Requires further authentication", :body => {"response" => "OK"}})
|
111
|
-
end
|
112
|
-
|
113
|
-
it "throws Plaid::BadRequest on 400 response" do
|
114
|
-
stub = stub_request(:get, stub_url).to_return(status: 400, body: bad_req_response)
|
115
|
-
expect { Plaid::Connection.secure_get("testing", "test_wells") }.to raise_error(Plaid::BadRequest, "invalid credentials")
|
116
|
-
end
|
117
|
-
|
118
|
-
it "throws Plaid::Unauthorized on 401 response" do
|
119
|
-
stub = stub_request(:get, stub_url).to_return(status: 401, body: unauth_response)
|
120
|
-
expect { Plaid::Connection.secure_get("testing", "test_wells") }.to raise_error(Plaid::Unauthorized, "bad access_token")
|
121
|
-
end
|
122
|
-
|
123
|
-
it "throws Plaid::RequestFailed on 402 response" do
|
124
|
-
stub = stub_request(:get, stub_url).to_return(status: 402, body: req_fail_response)
|
125
|
-
expect { Plaid::Connection.secure_get("testing", "test_wells") }.to raise_error(Plaid::RequestFailed, "invalid credentials")
|
126
|
-
end
|
127
|
-
|
128
|
-
it "throws a Plaid::NotFound on 404 response" do
|
129
|
-
stub = stub_request(:get, stub_url).to_return(status: 404, body: req_not_found)
|
130
|
-
expect { Plaid::Connection.secure_get("testing", "test_wells") }.to raise_error(Plaid::NotFound, "product not found")
|
131
|
-
end
|
132
|
-
|
133
|
-
it "throws a Plaid::ServerError on empty response" do
|
134
|
-
stub = stub_request(:get, stub_url).to_return(status: 504, body: '')
|
135
|
-
expect { Plaid::Connection.secure_get("testing", "test_wells") }.to raise_error(Plaid::ServerError, '')
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
describe "#patch" do
|
140
|
-
it "sends a patch request" do
|
141
|
-
stub = stub_request(:patch, stub_url).to_return({:body => {"response" => "OK"}.to_json})
|
142
|
-
Plaid::Connection.patch("testing")
|
143
|
-
expect(stub).to have_requested(:patch, stub_url)
|
144
|
-
end
|
145
|
-
|
146
|
-
it "returns response on 200 response" do
|
147
|
-
stub = stub_request(:patch, stub_url).to_return({:body => {"response" => "OK"}.to_json})
|
148
|
-
response = Plaid::Connection.patch("testing")
|
149
|
-
expect(response).to eq({"response" => "OK"})
|
150
|
-
end
|
151
|
-
|
152
|
-
it "returns message on 201 response" do
|
153
|
-
stub = stub_request(:patch, stub_url).to_return(status: 201, body: {"response" => "OK"}.to_json)
|
154
|
-
response = Plaid::Connection.patch("testing")
|
155
|
-
expect(response).to eq({:msg => "Requires further authentication", :body => {"response" => "OK"}})
|
156
|
-
end
|
157
|
-
|
158
|
-
it "throws Plaid::BadRequest on 400 response" do
|
159
|
-
stub = stub_request(:patch, stub_url).to_return(status: 400, body: bad_req_response)
|
160
|
-
expect { Plaid::Connection.patch("testing") }.to raise_error(Plaid::BadRequest, "invalid credentials")
|
161
|
-
end
|
162
|
-
|
163
|
-
it "throws Plaid::Unauthorized on 401 response" do
|
164
|
-
stub = stub_request(:patch, stub_url).to_return(status: 401, body: unauth_response)
|
165
|
-
expect { Plaid::Connection.patch("testing") }.to raise_error(Plaid::Unauthorized, "bad access_token")
|
166
|
-
end
|
167
|
-
|
168
|
-
it "throws Plaid::RequestFailed on 402 response" do
|
169
|
-
stub = stub_request(:patch, stub_url).to_return(status: 402, body: req_fail_response)
|
170
|
-
expect { Plaid::Connection.patch("testing") }.to raise_error(Plaid::RequestFailed, "invalid credentials")
|
171
|
-
end
|
172
|
-
|
173
|
-
it "throws a Plaid::NotFound on 404 response" do
|
174
|
-
stub = stub_request(:patch, stub_url).to_return(status: 404, body: req_not_found)
|
175
|
-
expect { Plaid::Connection.patch("testing") }.to raise_error(Plaid::NotFound, "product not found")
|
176
|
-
end
|
177
|
-
|
178
|
-
it "throws a Plaid::ServerError on empty response" do
|
179
|
-
stub = stub_request(:patch, stub_url).to_return(status: 504, body: '')
|
180
|
-
expect { Plaid::Connection.patch("testing") }.to raise_error(Plaid::ServerError, '')
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
describe "#delete" do
|
185
|
-
it "sends a delete request" do
|
186
|
-
stub = stub_request(:delete, stub_url)
|
187
|
-
Plaid::Connection.delete("testing")
|
188
|
-
expect(stub).to have_requested(:delete, stub_url)
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|