synapse_client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,55 @@
1
+
2
+ module SynapseClient
3
+ module Util
4
+
5
+ def self.url_encode(key)
6
+ URI.escape(key.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
7
+ end
8
+
9
+ def self.flatten_params(params, parent_key=nil)
10
+ result = []
11
+ params.each do |key, value|
12
+ calculated_key = parent_key ? "#{parent_key}[#{url_encode(key)}]" : url_encode(key)
13
+ if value.is_a?(Hash)
14
+ result += flatten_params(value, calculated_key)
15
+ elsif value.is_a?(Array)
16
+ result += flatten_params_array(value, calculated_key)
17
+ else
18
+ result << [calculated_key, value]
19
+ end
20
+ end
21
+ result
22
+ end
23
+
24
+ def self.flatten_params_array(value, calculated_key)
25
+ result = []
26
+ value.each do |elem|
27
+ if elem.is_a?(Hash)
28
+ result += flatten_params(elem, calculated_key)
29
+ elsif elem.is_a?(Array)
30
+ result += flatten_params_array(elem, calculated_key)
31
+ else
32
+ result << ["#{calculated_key}[]", elem]
33
+ end
34
+ end
35
+ result
36
+ end
37
+
38
+ def self.symbolize_names(object)
39
+ case object
40
+ when Hash
41
+ new_hash = Map.new
42
+ object.each do |key, value|
43
+ key = (key.to_sym rescue key) || key
44
+ new_hash[key] = symbolize_names(value)
45
+ end
46
+ new_hash
47
+ when Array
48
+ object.map { |value| symbolize_names(value) }
49
+ else
50
+ object
51
+ end
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module SynapseClient
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,78 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'pry'
5
+ require 'synapse_client'
6
+
7
+
8
+ #
9
+ def test_credentials
10
+ Map.new({
11
+ :client_id => "e06fa0f143a267c2ed8e",
12
+ :client_secret => "f578105bf9ae03d9310e0af6f4637c1bf363998b",
13
+ :merchant_synapse_id => 536,
14
+ :merchant_oauth_token => "16688788f22d8b46a83711b42ad9b0dec39b09ce",
15
+ :merchant_refresh_token => "37e6f092e3c9a5ad0c1a2f2c62fec6ab8cb44808",
16
+ :merchant_username => "0537fa5d0cb94aaea9e79900bc0cab",
17
+ :dev => true
18
+ })
19
+ end
20
+ SynapseClient.client_id = test_credentials.client_id
21
+ SynapseClient.client_secret = test_credentials.client_secret
22
+ SynapseClient.merchant_synapse_id = test_credentials.merchant_synapse_id
23
+ SynapseClient.dev = test_credentials.dev
24
+
25
+
26
+ #
27
+ # Most of this dummy data is taken from the examples at dev.synapsepay.com.
28
+
29
+ #
30
+ def dummy_customer_data
31
+ hex = SecureRandom.hex(4)
32
+ hex[0] = hex[0].upcase
33
+
34
+ Map.new({
35
+ :email => "foo+" + hex.downcase + "@example.com",
36
+ :fullname => "Foo Bar " + hex,
37
+ :phonenumber => sprintf('%010d', rand(10**10)),
38
+ :ip_address => Array.new(4){rand(256)}.join('.')
39
+ })
40
+ end
41
+
42
+ def get_dummy_customer
43
+ SynapseClient::Customer.create(dummy_customer_data)
44
+ end
45
+
46
+ #
47
+ def dummy_add_bank_account_info
48
+ Map.new({
49
+ :account_num => "1111111111",
50
+ :routing_num => "084000026",
51
+ :nickname => "Example bank account",
52
+ :account_type => "1",
53
+ :account_class => "1"
54
+ })
55
+ end
56
+
57
+ def dummy_link_bank_account_info
58
+ Map.new({
59
+ :username => "synapse_good",
60
+ :password => "test1234",
61
+ :pin => "1234",
62
+ :bank => "Bank of America"
63
+ })
64
+ end
65
+
66
+ def dummy_finish_linking_bank_account_info
67
+ Map.new({
68
+ :mfa => "test_answer",
69
+ :bank => "Bank of America"
70
+ })
71
+ end
72
+
73
+ def get_dummy_bank
74
+
75
+ SynapseClient::Customer.create(dummy_customer_data)
76
+ end
77
+
78
+
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe SynapseClient::BankAccount do
4
+
5
+ before(:each) do
6
+ @customer = get_dummy_customer
7
+ end
8
+
9
+ describe "listing bank accounts" do
10
+ it "should return an empty array when a customer has 0 bank accounts" do
11
+ bank_accounts = @customer.bank_accounts
12
+
13
+ expect(bank_accounts).to be_an(Array)
14
+ expect(bank_accounts.count).to eq(0)
15
+ end
16
+ end
17
+
18
+ describe "adding a bank account" do
19
+ it "should successfully return the bank account." do
20
+ bank_account = @customer.add_bank_account(dummy_add_bank_account_info)
21
+
22
+ expect(bank_account).to be_a SynapseClient::BankAccount
23
+
24
+ expect(bank_account.id).to be_a Fixnum
25
+ expect(bank_account.account_number_string).to be_a String
26
+ expect(bank_account.routing_number_string).to be_a String
27
+ expect(bank_account.nickname).to be_a String
28
+ expect(bank_account.account_type).to be_a Fixnum
29
+ expect(bank_account.account_class).to be_a Fixnum
30
+ end
31
+ end
32
+
33
+ describe "linking a bank account" do
34
+ it "should successfully return an mfa." do
35
+ mfa = @customer.link_bank_account(dummy_link_bank_account_info)
36
+
37
+ expect(mfa).to be_a SynapseClient::MFA
38
+
39
+ expect(mfa.type).to be_a String
40
+ expect(mfa.bank_access_token).to be_a String
41
+ expect(mfa.questions).to be_an Array
42
+ end
43
+
44
+ it "should successfully finish linking with an mfa." do
45
+ mfa = @customer.link_bank_account(dummy_link_bank_account_info)
46
+ bank_accounts = @customer.finish_linking_bank_account(dummy_finish_linking_bank_account_info.merge({
47
+ :bank_account_token => mfa.bank_access_token
48
+ }))
49
+
50
+ expect(bank_accounts).to be_a Array
51
+ expect(bank_accounts.count).to be > 0
52
+
53
+ bank_accounts.each do |ba|
54
+ expect(ba.account_number_string).to be_a String
55
+ expect(ba.routing_number_string).to be_a String
56
+ expect(ba.bank_name).to be_a String
57
+ expect(ba.nickname).to be_a String
58
+ expect(ba.name_on_account).to be_a String
59
+ expect(ba.account_type).to be_a Fixnum
60
+ expect(ba.account_class).to be_a Fixnum
61
+ end
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe SynapseClient::Customer do
4
+
5
+ before(:each) do
6
+ @dummy_customer_data = dummy_customer_data
7
+ @customer = SynapseClient::Customer.create(@dummy_customer_data)
8
+ end
9
+
10
+
11
+ describe "creating a customer" do
12
+ it "should successfully return a customer object with tokens and other info." do
13
+ expect(@customer).to be_a SynapseClient::Customer
14
+
15
+ expect(@customer.email).to be @dummy_customer_data.email
16
+ expect(@customer.fullname).to be @dummy_customer_data.fullname
17
+ expect(@customer.phonenumber).to be @dummy_customer_data.phonenumber
18
+ expect(@customer.ip_address).to be @dummy_customer_data.ip_address
19
+
20
+ expect(@customer.access_token).to be_a String
21
+ expect(@customer.refresh_token).to be_a String
22
+ expect(@customer.expires_in).to be_a Fixnum
23
+ expect(@customer.username).to be_a String
24
+ end
25
+ end
26
+
27
+ describe "retrieving a customer" do
28
+ it "should successfully return a customer object with tokens and other info." do
29
+ customer = SynapseClient::Customer.retrieve(@customer.access_token)
30
+
31
+ expect(customer).to be_a SynapseClient::Customer
32
+
33
+ expect(customer.id).to be_a Fixnum
34
+ expect(customer.email).to eq @dummy_customer_data.email
35
+ expect(customer.fullname).to eq @dummy_customer_data.fullname
36
+ expect(customer.phonenumber).to eq @dummy_customer_data.phonenumber
37
+ expect(customer.username).to be_a String
38
+ end
39
+ end
40
+
41
+ end
42
+
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe SynapseClient::Order do
4
+
5
+ before(:each) do
6
+ @customer = get_dummy_customer
7
+ @bank = @customer.add_bank_account(dummy_add_bank_account_info)
8
+ @amount_to_charge = rand(1..1000)
9
+ end
10
+
11
+ describe "getting orders for a customer" do
12
+ it "should return an empty array" do
13
+ orders = @customer.orders
14
+
15
+ expect(orders).to be_an(Array)
16
+ expect(orders.count).to eq(0)
17
+ end
18
+ end
19
+
20
+ describe "adding an order" do
21
+ it "should successfully return an order." do
22
+ order = @customer.add_order({
23
+ :amount => @amount_to_charge,
24
+ :bank_id => @bank.id
25
+ })
26
+ expect(order).to be_a SynapseClient::Order
27
+
28
+ expect(order.amount).to eq(@amount_to_charge)
29
+ expect(order.id).to be_a Fixnum
30
+ expect(order.status).to be_a Fixnum
31
+ end
32
+ end
33
+
34
+ describe "retrieving an order" do
35
+ it "should successfully return an order." do
36
+ new_order = @customer.add_order({
37
+ :amount => @amount_to_charge,
38
+ :bank_id => @bank.id
39
+ })
40
+ order = SynapseClient::Order.retrieve(new_order.id)
41
+
42
+ expect(order).to be_a SynapseClient::Order
43
+
44
+ #expect(order.amount).to eq(@amount_to_charge)
45
+ #expect(order.id).to be_a Fixnum
46
+ expect(order.status).to be_a Fixnum
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+
53
+
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe SynapseClient do
4
+
5
+ before(:each) do
6
+ SynapseClient.client_id = test_credentials.client_id
7
+ SynapseClient.client_secret = test_credentials.client_secret
8
+ SynapseClient.merchant_synapse_id = test_credentials.merchant_synapse_id
9
+ SynapseClient.dev = test_credentials.dev
10
+ end
11
+
12
+ describe "api keys should be stored" do
13
+ it 'stores the client_id on the top level module' do
14
+ expect(SynapseClient.client_id).to eq(test_credentials.client_id)
15
+ end
16
+
17
+ it 'stores the client_secret on the top level module' do
18
+ expect(SynapseClient.client_secret).to eq(test_credentials.client_secret)
19
+ end
20
+
21
+ it 'stores the merchant_synapse_id on the top level module' do
22
+ expect(SynapseClient.merchant_synapse_id).to eq(test_credentials.merchant_synapse_id)
23
+ end
24
+
25
+ it 'stores that dev is true' do
26
+ expect(SynapseClient.dev).to eq(test_credentials.dev)
27
+ expect(SynapseClient.dev?).to eq(test_credentials.dev)
28
+ end
29
+ end
30
+
31
+
32
+ describe "url generation is correct" do
33
+ it "should have the is_dev query param" do
34
+ expect(SynapseClient.api_url).to eq("https://sandbox.synapsepay.com?is_dev=true")
35
+ end
36
+
37
+ it "should have the sandbox domain" do
38
+ expect(SynapseClient.api_url).to match("https://sandbox.synapsepay.com")
39
+ end
40
+
41
+ it "should append a path to the url with a trailing slash" do
42
+ expect(SynapseClient.api_url("/foo")).to match("https://sandbox.synapsepay.com/foo/")
43
+ end
44
+ end
45
+
46
+
47
+ describe "base request method" do
48
+ it "should raise an error when api keys are absent" do
49
+ SynapseClient.client_id = nil
50
+ expect { SynapseClient.request("get", "users") }.to raise_error
51
+ end
52
+
53
+ it "should raise an error when api keys contain whitespace" do
54
+ SynapseClient.client_id = " foo bar "
55
+ expect { SynapseClient.request("get", "users") }.to raise_error
56
+ end
57
+
58
+ it "should be able to do a basic get of bank statuses" do
59
+ response = SynapseClient.request("get", "/api/v2/bankstatus/show/")
60
+
61
+ expect(response).to be_an(SynapseClient::APIOperations::Response)
62
+ expect(response.successful?).to be true
63
+
64
+ expect(response.data.banks).to be_an(Array)
65
+ expect(response.data.banks.count).to be > 0
66
+ end
67
+ end
68
+
69
+ end
70
+
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'synapse_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "synapse_client"
8
+ spec.version = SynapseClient::VERSION
9
+ spec.authors = ["Miles Matthias"]
10
+ spec.email = ["miles.matthias@gmail.com"]
11
+ spec.summary = %q{A ruby client for the SynapsePay.com API.}
12
+ spec.description = %q{A ruby client for the SynapsePay.com API. Read SynapsePay API documentation at dev.synapsepay.com.}
13
+ spec.homepage = "https://github.com/milesmatthias/synapse_client"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'rest-client', '~> 1.7', '>= 1.7.2'
22
+ spec.add_runtime_dependency 'map'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "rspec-nc"
28
+ spec.add_development_dependency "guard"
29
+ spec.add_development_dependency "guard-rspec"
30
+ spec.add_development_dependency "pry", "~> 0.9.0"
31
+ spec.add_development_dependency "pry-remote"
32
+ spec.add_development_dependency "pry-nav"
33
+ spec.add_development_dependency "coveralls"
34
+ end
metadata ADDED
@@ -0,0 +1,253 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: synapse_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Miles Matthias
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.7.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.7'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.7.2
33
+ - !ruby/object:Gem::Dependency
34
+ name: map
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.7'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.7'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rspec-nc
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: guard
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: guard-rspec
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: pry
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: 0.9.0
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: 0.9.0
145
+ - !ruby/object:Gem::Dependency
146
+ name: pry-remote
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ - !ruby/object:Gem::Dependency
160
+ name: pry-nav
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ - !ruby/object:Gem::Dependency
174
+ name: coveralls
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ description: A ruby client for the SynapsePay.com API. Read SynapsePay API documentation
188
+ at dev.synapsepay.com.
189
+ email:
190
+ - miles.matthias@gmail.com
191
+ executables: []
192
+ extensions: []
193
+ extra_rdoc_files: []
194
+ files:
195
+ - ".coveralls.yml"
196
+ - ".gitignore"
197
+ - ".travis.yml"
198
+ - Gemfile
199
+ - Guardfile
200
+ - LICENSE
201
+ - README.md
202
+ - Rakefile
203
+ - lib/synapse_client.rb
204
+ - lib/synapse_client/api_operations/create.rb
205
+ - lib/synapse_client/api_operations/list.rb
206
+ - lib/synapse_client/api_operations/response.rb
207
+ - lib/synapse_client/api_resource.rb
208
+ - lib/synapse_client/bank_account.rb
209
+ - lib/synapse_client/customer.rb
210
+ - lib/synapse_client/error.rb
211
+ - lib/synapse_client/merchant.rb
212
+ - lib/synapse_client/mfa.rb
213
+ - lib/synapse_client/order.rb
214
+ - lib/synapse_client/refreshed_tokens.rb
215
+ - lib/synapse_client/security_question.rb
216
+ - lib/synapse_client/util.rb
217
+ - lib/synapse_client/version.rb
218
+ - spec/spec_helper.rb
219
+ - spec/synapse_client_bank_account_spec.rb
220
+ - spec/synapse_client_customer_spec.rb
221
+ - spec/synapse_client_order_spec.rb
222
+ - spec/synapse_client_spec.rb
223
+ - synapse_client.gemspec
224
+ homepage: https://github.com/milesmatthias/synapse_client
225
+ licenses:
226
+ - MIT
227
+ metadata: {}
228
+ post_install_message:
229
+ rdoc_options: []
230
+ require_paths:
231
+ - lib
232
+ required_ruby_version: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ required_rubygems_version: !ruby/object:Gem::Requirement
238
+ requirements:
239
+ - - ">="
240
+ - !ruby/object:Gem::Version
241
+ version: '0'
242
+ requirements: []
243
+ rubyforge_project:
244
+ rubygems_version: 2.2.2
245
+ signing_key:
246
+ specification_version: 4
247
+ summary: A ruby client for the SynapsePay.com API.
248
+ test_files:
249
+ - spec/spec_helper.rb
250
+ - spec/synapse_client_bank_account_spec.rb
251
+ - spec/synapse_client_customer_spec.rb
252
+ - spec/synapse_client_order_spec.rb
253
+ - spec/synapse_client_spec.rb