synapsis 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d5b2bf26eef6d006fecce9cb62a93ea6eefd89a
4
- data.tar.gz: 6b7f9dcfbc6811b14e3f0e0c4250bac5286fb136
3
+ metadata.gz: 88f25f31c347b1d5e1315a53f5f8b988bf36300d
4
+ data.tar.gz: e057d3fa66b160ec82b589cdc38375a1d5810d45
5
5
  SHA512:
6
- metadata.gz: 56699c37e591ed8a71d3f12bfb8214ee5e1d5d3310590463085aa914ceb492d4533743ea8eb3f9dafb69824c805c23b089ae31734eb3b94fcce8b5504e1a80a0
7
- data.tar.gz: 9829b32bdfa1e7f552730844e7967770bcc3ef9cccaa9452e9449192f573e561ca317a5fcfe02dc11b9abfd1974607d89eac7211fcabb693ebb97f72fb6d85ae
6
+ metadata.gz: d9236da172a713aa0c8aa9b70db0f711ef28230fa9d8ea2368010ade8239410534991af783c2dbac156db68d46b11dcee81b3ac2049e55eb1037d5012d982510
7
+ data.tar.gz: c85014c085f84d63811d1d286b9612f84077c7b92f696c11636f34b4350b435a053040bf3531eba70970b1cf093440de16a3fd4ac82f7d4c62e90646277bdda8
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .ruby-version
1
2
  /spec/config.yml
2
3
  /.bundle/
3
4
  /.yardoc
data/lib/synapsis/bank.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  class Synapsis::Bank < Synapsis::APIResource
2
- include Synapsis::Utilities
3
2
  extend Synapsis::APIOperations::Create
4
3
  extend Synapsis::APIOperations::View
5
4
 
@@ -38,7 +37,6 @@ class Synapsis::Bank < Synapsis::APIResource
38
37
  return_response(added_bank)
39
38
  end
40
39
 
41
-
42
40
  def self.link(params)
43
41
  partially_linked_bank = request(:post, bank_link_url, params)
44
42
  parsed_partially_linked_bank = parse_as_synapse_resource(partially_linked_bank)
@@ -78,6 +76,18 @@ class Synapsis::Bank < Synapsis::APIResource
78
76
  return_response(response)
79
77
  end
80
78
 
79
+ # By default, the first added bank account is the primary one. If you add another bank it will not be set as the primary one unless it was deleted.
80
+ # When a bank account is deleted, if it was the primary bank account, the next bank account chronologically added will be set as the primary one.
81
+ def self.set_as_primary(bank_id:, oauth_consumer_key:)
82
+ params = {
83
+ bank_id: bank_id,
84
+ oauth_consumer_key: oauth_consumer_key
85
+ }
86
+
87
+ response = request(:post, set_bank_as_primary_url, params)
88
+ return_response(response)
89
+ end
90
+
81
91
  private
82
92
 
83
93
  def self.bank_link_url
@@ -88,7 +98,11 @@ class Synapsis::Bank < Synapsis::APIResource
88
98
  "#{API_V2_PATH}bank/mfa/?is_dev=yes"
89
99
  end
90
100
 
101
+ def self.set_bank_as_primary_url
102
+ "#{API_V2_PATH}bank/setprimary"
103
+ end
104
+
91
105
  def self.bank_delete_url
92
- "#{API_V2_PATH}bank/delete/"
106
+ "#{API_V2_PATH}bank/delete"
93
107
  end
94
108
  end
@@ -1,10 +1,10 @@
1
1
  class Synapsis::Deposit < Synapsis::APIResource
2
- include Synapsis::Utilities
3
2
  extend Synapsis::APIOperations::Create
4
3
 
4
+ # amount, bank_id, oauth_consumer_key
5
+ # amount must be supplied using a string
5
6
  def self.create(params)
6
7
  response = create_request(params)
7
-
8
8
  return_response(response)
9
9
  end
10
10
  end
@@ -1,5 +1,4 @@
1
1
  class Synapsis::Order < Synapsis::APIResource
2
- include Synapsis::Utilities
3
2
  extend Synapsis::APIOperations::Create
4
3
 
5
4
  module Status
data/lib/synapsis/user.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  class Synapsis::User < Synapsis::APIResource
2
- include Synapsis::Utilities
3
2
  extend Synapsis::APIOperations::Create
4
3
  extend Synapsis::APIOperations::Edit
5
4
  extend Synapsis::APIOperations::View
@@ -19,6 +18,11 @@ class Synapsis::User < Synapsis::APIResource
19
18
  return_response(response)
20
19
  end
21
20
 
21
+ def self.refresh(params)
22
+ response = request(:post, refresh_url, params.merge(client_credentials))
23
+ return_response(response)
24
+ end
25
+
22
26
  def self.view_linked_banks(oauth_token)
23
27
  Synapsis::Bank.view_linked_banks(oauth_token)
24
28
  end
@@ -35,5 +39,9 @@ class Synapsis::User < Synapsis::APIResource
35
39
  def self.create_url
36
40
  "#{API_V2_PATH}user/create/"
37
41
  end
42
+
43
+ def self.refresh_url
44
+ "#{API_V2_PATH}user/refresh"
45
+ end
38
46
  end
39
47
 
@@ -1,3 +1,3 @@
1
1
  module Synapsis
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -1,5 +1,4 @@
1
1
  class Synapsis::Withdrawal < Synapsis::APIResource
2
- include Synapsis::Utilities
3
2
  extend Synapsis::APIOperations::Create
4
3
  extend Synapsis::APIOperations::View
5
4
 
data/lib/synapsis.rb CHANGED
@@ -9,12 +9,10 @@ end
9
9
 
10
10
  # Internal dependencies
11
11
  require "synapsis/version"
12
- require "synapsis/utilities"
13
12
  require "synapsis/api_resource"
14
13
  require "synapsis/api_operations/create"
15
14
  require "synapsis/api_operations/edit"
16
15
  require "synapsis/api_operations/view"
17
- require "synapsis/authentication"
18
16
  require "synapsis/user"
19
17
  require "synapsis/bank"
20
18
  require "synapsis/withdrawal"
data/spec/spec_helper.rb CHANGED
@@ -19,5 +19,4 @@ end
19
19
 
20
20
  RSpec.configure do |config|
21
21
  config.order = 'random'
22
- config.include JsonHelpers
23
22
  end
@@ -0,0 +1,7 @@
1
+ def get_random_routing_number
2
+ # Taken from: https://www.usbank.com/checking/aba-routing-number.html, we cannot just generate random numbers as the tests have a tendency to fail
3
+ sample_routing_numbers = ['122105155', '082000549', '121122676', '122235821', '102101645', '102000021', '123103729']
4
+
5
+ sample_routing_numbers.sample
6
+ end
7
+
@@ -11,7 +11,7 @@ RSpec.describe Synapsis::Bank do
11
11
  end
12
12
  end
13
13
 
14
- context '#add/ #remove' do
14
+ context '.add/#remove' do
15
15
  it 'adds and removes a bank account' do
16
16
  random_persons_access_token = 'dcd234d9d9fb55ad9711c4c41e254868ef3768d4'
17
17
 
@@ -61,4 +61,38 @@ RSpec.describe Synapsis::Bank do
61
61
  expect { Synapsis::Bank.add(bank_params) }.to raise_error(Synapsis::Error).with_message('Because of security reasons you can only add a bank account that belongs to you and is in your name.')
62
62
  end
63
63
  end
64
+
65
+ context '.set_primary' do
66
+ context 'happy path' do
67
+ it 'sets the bank as a primary bank' do
68
+ user_params = {
69
+ email: Faker::Internet.email,
70
+ fullname: Faker::Name.name,
71
+ phonenumber: Faker::PhoneNumber.phone_number,
72
+ password: '5ourcep4d',
73
+ ip_address: '8.8.8.8'
74
+ }
75
+
76
+ new_user_response = Synapsis::User.create(user_params)
77
+
78
+ bank_params = {
79
+ fullname: user_params[:fullname],
80
+ account_num: '1111111112',
81
+ routing_num: '121000358',
82
+ nickname: 'Sourcepad Bank',
83
+ oauth_consumer_key: new_user_response.access_token,
84
+ account_type: Synapsis::Bank::AccountType::CHECKING,
85
+ account_class: Synapsis::Bank::AccountClass::PERSONAL
86
+ }
87
+
88
+ first_bank_response = Synapsis::Bank.add(bank_params)
89
+ second_bank_response = Synapsis::Bank.add(bank_params)
90
+ third_bank_response = Synapsis::Bank.add(bank_params)
91
+
92
+ set_bank_primary_response = Synapsis::Bank.set_as_primary(bank_id: second_bank_response.bank.id, oauth_consumer_key: new_user_response.access_token)
93
+
94
+ expect(set_bank_primary_response.success).to be_truthy
95
+ end
96
+ end
97
+ end
64
98
  end
@@ -48,7 +48,7 @@ RSpec.describe Synapsis::Card do
48
48
  id: 483,
49
49
  legal_name: Faker::Name.name,
50
50
  account_number: "11111111#{rand(1..9)}#{rand(1..9)}",
51
- routing_number: "1210003#{rand(1..9)}#{rand(1..9)}",
51
+ routing_number: get_random_routing_number,
52
52
  account_class: rand(1..2),
53
53
  account_type: rand(1..2)
54
54
  }}
@@ -76,7 +76,10 @@ RSpec.describe Synapsis::Card do
76
76
  expect { Synapsis::Card.edit(edit_card_params.merge(id: 5)) }.to raise_error(Synapsis::Error).with_message('Card not found')
77
77
 
78
78
  # Wrong account class
79
- expect { Synapsis::Card.edit(edit_card_params.merge(account_class: 'WRONG')) }.to raise_error(Synapsis::Error).with_message('Sorry, this request could not be processed. Please try again later.')
79
+ expect { Synapsis::Card.edit(edit_card_params.merge(account_class: 'WRONG')) }.to raise_error(Synapsis::Error).with_message('account_class not supplied or incorrectly formatted')
80
+
81
+ # Wrong account type
82
+ expect { Synapsis::Card.edit(edit_card_params.merge(account_type: 'WRONG')) }.to raise_error(Synapsis::Error).with_message('account_type not supplied or incorrectly formatted')
80
83
  end
81
84
 
82
85
  xit 'doesn\'t raise errors on invalid account numbers and routing numbers' do
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  RSpec.describe Synapsis::Deposit do
4
4
  context '#add' do
5
5
  let!(:deposit_params) {{
6
- amount: 100,
6
+ amount: "100",
7
7
  oauth_consumer_key: '3bdb5790692d06983d8cb0feb40365886631e52d',
8
8
  bank_id: 2182
9
9
  }}
@@ -29,7 +29,10 @@ RSpec.describe Synapsis::Deposit do
29
29
  context 'errors' do
30
30
  it 'create a Synapsis::Error object' do
31
31
  # Missing amount
32
- expect { Synapsis::Deposit.create(deposit_params.merge(amount: 0)) }.to raise_error(Synapsis::Error).with_message('Missing amount')
32
+ expect { Synapsis::Deposit.create(deposit_params.merge(amount: 0)) }.to raise_error(Synapsis::Error).with_message('amount not supplied or incorrectly formatted')
33
+
34
+ # Missing amount
35
+ expect { Synapsis::Deposit.create(deposit_params.merge(amount: 0)) }.to raise_error(Synapsis::Error).with_message('amount not supplied or incorrectly formatted')
33
36
 
34
37
  # OAuth error
35
38
  expect { Synapsis::Deposit.create(deposit_params.merge(oauth_consumer_key: 'WRONG!!!')) }.to raise_error(Synapsis::Error).with_message('Error in OAuth Authentication.')
@@ -9,7 +9,7 @@ RSpec.describe Synapsis::MassPay do
9
9
  let!(:mass_pay_hash) {{
10
10
  legal_name: 'Test Person',
11
11
  account_number: '1111111112',
12
- routing_number: '121000358',
12
+ routing_number: get_random_routing_number,
13
13
  amount: 1,
14
14
  trans_type: 0,
15
15
  account_class: 1,
@@ -18,7 +18,7 @@ RSpec.describe Synapsis::MassPay do
18
18
  let!(:mass_pay_hash2) {{
19
19
  legal_name: 'Test Person2',
20
20
  account_number: '1111111112',
21
- routing_number: '121000359',
21
+ routing_number: get_random_routing_number,
22
22
  amount: 1,
23
23
  trans_type: 0,
24
24
  account_class: 1,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synapsis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daryll Santos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-19 00:00:00.000000000 Z
11
+ date: 2015-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -113,7 +113,6 @@ files:
113
113
  - lib/synapsis/api_operations/edit.rb
114
114
  - lib/synapsis/api_operations/view.rb
115
115
  - lib/synapsis/api_resource.rb
116
- - lib/synapsis/authentication.rb
117
116
  - lib/synapsis/bank.rb
118
117
  - lib/synapsis/bank_status.rb
119
118
  - lib/synapsis/card.rb
@@ -122,14 +121,12 @@ files:
122
121
  - lib/synapsis/mass_pay.rb
123
122
  - lib/synapsis/order.rb
124
123
  - lib/synapsis/user.rb
125
- - lib/synapsis/utilities.rb
126
124
  - lib/synapsis/version.rb
127
125
  - lib/synapsis/withdrawal.rb
128
126
  - spec/config.yml
129
127
  - spec/spec_helper.rb
130
- - spec/support/json_helpers.rb
128
+ - spec/support/routing_number_helpers.rb
131
129
  - spec/synapsis/api_resource_spec.rb
132
- - spec/synapsis/authentication_spec.rb
133
130
  - spec/synapsis/bank_link_spec.rb
134
131
  - spec/synapsis/bank_spec.rb
135
132
  - spec/synapsis/bank_status_spec.rb
@@ -160,16 +157,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
157
  version: '0'
161
158
  requirements: []
162
159
  rubyforge_project:
163
- rubygems_version: 2.2.2
160
+ rubygems_version: 2.4.7
164
161
  signing_key:
165
162
  specification_version: 4
166
163
  summary: Ruby wrapper to the SynapsePay API
167
164
  test_files:
168
165
  - spec/config.yml
169
166
  - spec/spec_helper.rb
170
- - spec/support/json_helpers.rb
167
+ - spec/support/routing_number_helpers.rb
171
168
  - spec/synapsis/api_resource_spec.rb
172
- - spec/synapsis/authentication_spec.rb
173
169
  - spec/synapsis/bank_link_spec.rb
174
170
  - spec/synapsis/bank_spec.rb
175
171
  - spec/synapsis/bank_status_spec.rb
@@ -1,25 +0,0 @@
1
- class Synapsis::Authentication
2
- include Synapsis::Utilities
3
-
4
- attr_accessor :username, :password, :grant_type, :scope
5
-
6
- def self.login(params)
7
- self.new(params).login
8
- end
9
-
10
- def initialize(params)
11
- params.each do |k, v|
12
- send("#{k}=", v)
13
- end
14
-
15
- @grant_type = 'password'
16
- @scope = 'write'
17
- end
18
-
19
- def login
20
- Synapsis.connection.post do |req|
21
- req.url 'oauth2/access_token'
22
- req.body = build_params_from_string
23
- end
24
- end
25
- end
@@ -1,30 +0,0 @@
1
- require 'json'
2
-
3
- module Synapsis::Utilities
4
- def build_json_from_params
5
- JSON.generate(to_hash.merge(client_credentials))
6
- end
7
-
8
- def build_json_from_variable_hash
9
- JSON.generate(to_hash)
10
- end
11
-
12
- def to_hash
13
- instance_variables.map do |ivar|
14
- [ivar[1..-1], instance_variable_get(ivar)]
15
- end.to_h
16
- end
17
-
18
- def build_params_from_string
19
- to_hash.merge(client_credentials).map { |k, v| "#{k}=#{v}" }.join("&")
20
- end
21
-
22
- private
23
-
24
- def client_credentials
25
- {
26
- client_id: Synapsis.client_id,
27
- client_secret: Synapsis.client_secret
28
- }
29
- end
30
- end
@@ -1,6 +0,0 @@
1
- module JsonHelpers
2
- def json_response(response)
3
- JSON.parse(response.body)
4
- end
5
- end
6
-
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Synapsis::Authentication do
4
- it 'connects' do
5
- authentication_params = {
6
- username: 'b84b8c816c0541f09ea9fbd7c5d8e4',
7
- password: '5ourcep4d'
8
- }
9
-
10
- response = Synapsis::Authentication.login(authentication_params)
11
-
12
- expect(JSON.parse(response.body)['access_token']).to be_truthy
13
- expect(JSON.parse(response.body)['token_type']).to eq 'Bearer'
14
- end
15
- end