synapse_pay 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.travis.yml +16 -0
- data/Gemfile +8 -0
- data/LICENSE +21 -0
- data/README.md +54 -0
- data/Rakefile +8 -0
- data/VERSION +1 -0
- data/bin/synapse_pay-console +7 -0
- data/gemfiles/default-with-activesupport.gemfile +10 -0
- data/gemfiles/json.gemfile +12 -0
- data/gemfiles/yajl.gemfile +12 -0
- data/lib/synapse_pay.rb +78 -0
- data/lib/synapse_pay/apibits/api_client.rb +29 -0
- data/lib/synapse_pay/apibits/api_endpoint.rb +9 -0
- data/lib/synapse_pay/apibits/api_list.rb +88 -0
- data/lib/synapse_pay/apibits/api_method.rb +97 -0
- data/lib/synapse_pay/apibits/api_object.rb +52 -0
- data/lib/synapse_pay/apibits/api_resource.rb +127 -0
- data/lib/synapse_pay/apibits/headers_builder.rb +47 -0
- data/lib/synapse_pay/apibits/params_builder.rb +30 -0
- data/lib/synapse_pay/apibits/path_builder.rb +38 -0
- data/lib/synapse_pay/apibits/requester.rb +104 -0
- data/lib/synapse_pay/apibits/util.rb +51 -0
- data/lib/synapse_pay/client.rb +89 -0
- data/lib/synapse_pay/endpoints/bank_endpoint.rb +47 -0
- data/lib/synapse_pay/endpoints/bank_mfa_device_endpoint.rb +5 -0
- data/lib/synapse_pay/endpoints/bank_mfa_questions_endpoint.rb +5 -0
- data/lib/synapse_pay/endpoints/bank_status_endpoint.rb +11 -0
- data/lib/synapse_pay/endpoints/card_endpoint.rb +26 -0
- data/lib/synapse_pay/endpoints/deposit_endpoint.rb +23 -0
- data/lib/synapse_pay/endpoints/mass_pay_endpoint.rb +26 -0
- data/lib/synapse_pay/endpoints/order_endpoint.rb +44 -0
- data/lib/synapse_pay/endpoints/user_endpoint.rb +26 -0
- data/lib/synapse_pay/endpoints/wire_endpoint.rb +29 -0
- data/lib/synapse_pay/endpoints/withdrawal_endpoint.rb +17 -0
- data/lib/synapse_pay/errors/api_connection_error.rb +4 -0
- data/lib/synapse_pay/errors/api_error.rb +32 -0
- data/lib/synapse_pay/errors/authentication_error.rb +4 -0
- data/lib/synapse_pay/errors/synapse_pay_error.rb +13 -0
- data/lib/synapse_pay/nested_list.rb +32 -0
- data/lib/synapse_pay/resources/bank.rb +46 -0
- data/lib/synapse_pay/resources/bank_mfa_device.rb +32 -0
- data/lib/synapse_pay/resources/bank_mfa_questions.rb +28 -0
- data/lib/synapse_pay/resources/bank_status.rb +21 -0
- data/lib/synapse_pay/resources/card.rb +32 -0
- data/lib/synapse_pay/resources/deposit.rb +25 -0
- data/lib/synapse_pay/resources/mass_pay.rb +38 -0
- data/lib/synapse_pay/resources/order.rb +63 -0
- data/lib/synapse_pay/resources/user.rb +80 -0
- data/lib/synapse_pay/resources/wire.rb +31 -0
- data/lib/synapse_pay/resources/withdrawal.rb +29 -0
- data/lib/synapse_pay/version.rb +3 -0
- data/synapse_pay.gemspec +29 -0
- data/test/synapse_pay/api_list_test.rb +23 -0
- data/test/synapse_pay/api_method_test.rb +89 -0
- data/test/synapse_pay/headers_builder_test.rb +39 -0
- data/test/synapse_pay/params_builder_test.rb +57 -0
- data/test/synapse_pay/path_builder_test.rb +50 -0
- data/test/synapse_pay/requester_test.rb +86 -0
- data/test/synapse_pay/util_test.rb +51 -0
- data/test/test_data.rb +72 -0
- data/test/test_helper.rb +41 -0
- metadata +220 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3812258b427d907502b4a954d75fc130272a8797
|
4
|
+
data.tar.gz: c051b7c387ec68046eb67f061122ee91e19c1a7a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c0c701d80d45d27d479e260286c57c3eb2c561d105ffe7ca6b9aa539607c4fb5483430bd08b92932f15b4377185080f307c8ed380db5014a9ef66ef28ef04887
|
7
|
+
data.tar.gz: 04431e4e07ede206e4cab686118ee4a1a6bba4ad45f4b6e10dad3eac41883bcca6d6a41d25524139b01c07a588274a5f6fc716265eb416623883d8efacfd6745
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015- Apibits (http://apibits.com)
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, 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,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# SynapsePay Ruby Bindings  [](https://codeclimate.com/github/synapse_pay/synapse_pay-ruby)
|
2
|
+
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
You don't need this source code unless you want to modify the gem. If
|
7
|
+
you just want to use the SynapsePay Ruby bindings, you should run:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
gem install synapse_pay
|
11
|
+
```
|
12
|
+
|
13
|
+
If you want to build & install the gem from source:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
gem build synapse_pay.gemspec
|
17
|
+
gem install synapse_pay-0.0.1.gem
|
18
|
+
```
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
## Requirements
|
25
|
+
|
26
|
+
* Ruby 1.8.7 or above. (Ruby 1.8.6 may work if you load
|
27
|
+
ActiveSupport.) For Ruby versions before 1.9.2, you'll need to add this to your Gemfile:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.9.2')
|
31
|
+
gem 'rest-client', '~> 1.6.8'
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
* rest-client, json
|
36
|
+
|
37
|
+
|
38
|
+
## Bundler
|
39
|
+
|
40
|
+
If you are installing via bundler, you should be sure to use the https
|
41
|
+
rubygems source in your Gemfile, as any gems fetched over http could potentially be compromised.
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
source 'https://rubygems.org'
|
45
|
+
|
46
|
+
gem 'rails'
|
47
|
+
gem 'synapse_pay'
|
48
|
+
```
|
49
|
+
|
50
|
+
|
51
|
+
## Development
|
52
|
+
|
53
|
+
Test cases can be run with: `bundle exec rake test`
|
54
|
+
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,10 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
gemspec :path => File.join(File.dirname(__FILE__), "..")
|
3
|
+
|
4
|
+
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.9.3')
|
5
|
+
gem 'i18n', '< 0.7'
|
6
|
+
gem 'rest-client', '~> 1.6.8'
|
7
|
+
gem 'activesupport', '~> 3.2'
|
8
|
+
else
|
9
|
+
gem 'activesupport'
|
10
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
gemspec :path => File.join(File.dirname(__FILE__), "..")
|
3
|
+
|
4
|
+
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.9.3')
|
5
|
+
gem 'i18n', '< 0.7'
|
6
|
+
gem 'rest-client', '~> 1.6.8'
|
7
|
+
gem 'activesupport', '~> 3.2'
|
8
|
+
else
|
9
|
+
gem 'activesupport'
|
10
|
+
end
|
11
|
+
|
12
|
+
gem 'json'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
gemspec :path => File.join(File.dirname(__FILE__), "..")
|
3
|
+
|
4
|
+
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.9.3')
|
5
|
+
gem 'i18n', '< 0.7'
|
6
|
+
gem 'rest-client', '~> 1.6.8'
|
7
|
+
gem 'activesupport', '~> 3.2'
|
8
|
+
else
|
9
|
+
gem 'activesupport'
|
10
|
+
end
|
11
|
+
|
12
|
+
gem 'yajl-ruby'
|
data/lib/synapse_pay.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# SynapsePay Ruby bindings
|
2
|
+
# API Docs are located at http://synapsepay.readme.io/v1.0/docs
|
3
|
+
require 'cgi'
|
4
|
+
require 'set'
|
5
|
+
require 'openssl'
|
6
|
+
require 'rest_client'
|
7
|
+
require 'json'
|
8
|
+
require 'base64'
|
9
|
+
|
10
|
+
# Version
|
11
|
+
require 'synapse_pay/version'
|
12
|
+
|
13
|
+
# Errors
|
14
|
+
require 'synapse_pay/errors/synapse_pay_error'
|
15
|
+
require 'synapse_pay/errors/api_error'
|
16
|
+
require 'synapse_pay/errors/api_connection_error'
|
17
|
+
require 'synapse_pay/errors/authentication_error'
|
18
|
+
|
19
|
+
# Wrapper around RestClient
|
20
|
+
require 'synapse_pay/apibits/requester'
|
21
|
+
|
22
|
+
# Builders for creating API methods.
|
23
|
+
require 'synapse_pay/apibits/path_builder'
|
24
|
+
require 'synapse_pay/apibits/headers_builder'
|
25
|
+
require 'synapse_pay/apibits/params_builder'
|
26
|
+
require 'synapse_pay/apibits/api_method'
|
27
|
+
|
28
|
+
# Generic resources
|
29
|
+
require 'synapse_pay/apibits/api_endpoint'
|
30
|
+
require 'synapse_pay/apibits/api_client'
|
31
|
+
require 'synapse_pay/apibits/api_object'
|
32
|
+
require 'synapse_pay/apibits/api_resource'
|
33
|
+
require 'synapse_pay/apibits/api_list'
|
34
|
+
require 'synapse_pay/apibits/util'
|
35
|
+
|
36
|
+
# API specific resources
|
37
|
+
require 'synapse_pay/resources/bank'
|
38
|
+
require 'synapse_pay/resources/bank_mfa_device'
|
39
|
+
require 'synapse_pay/resources/bank_mfa_questions'
|
40
|
+
require 'synapse_pay/resources/bank_status'
|
41
|
+
require 'synapse_pay/resources/card'
|
42
|
+
require 'synapse_pay/resources/deposit'
|
43
|
+
require 'synapse_pay/resources/mass_pay'
|
44
|
+
require 'synapse_pay/resources/order'
|
45
|
+
require 'synapse_pay/resources/user'
|
46
|
+
require 'synapse_pay/resources/wire'
|
47
|
+
require 'synapse_pay/resources/withdrawal'
|
48
|
+
|
49
|
+
# API specific endpoints
|
50
|
+
require 'synapse_pay/endpoints/bank_endpoint'
|
51
|
+
require 'synapse_pay/endpoints/bank_mfa_device_endpoint'
|
52
|
+
require 'synapse_pay/endpoints/bank_mfa_questions_endpoint'
|
53
|
+
require 'synapse_pay/endpoints/bank_status_endpoint'
|
54
|
+
require 'synapse_pay/endpoints/card_endpoint'
|
55
|
+
require 'synapse_pay/endpoints/deposit_endpoint'
|
56
|
+
require 'synapse_pay/endpoints/mass_pay_endpoint'
|
57
|
+
require 'synapse_pay/endpoints/order_endpoint'
|
58
|
+
require 'synapse_pay/endpoints/user_endpoint'
|
59
|
+
require 'synapse_pay/endpoints/wire_endpoint'
|
60
|
+
require 'synapse_pay/endpoints/withdrawal_endpoint'
|
61
|
+
|
62
|
+
# OAuth Client
|
63
|
+
require 'synapse_pay/client'
|
64
|
+
|
65
|
+
module SynapsePay
|
66
|
+
@api_base = "https://synapsepay.com/api/v2/"
|
67
|
+
@api_staging = "https://sandbox.synapsepay.com/api/v2"
|
68
|
+
@api_version = "v2"
|
69
|
+
@support_email = "hello@synapsepay.com"
|
70
|
+
@docs_url = "http://synapsepay.readme.io/v1.0/docs"
|
71
|
+
@api_sandbox = "https://sandbox.synapsepay.com/api/v2"
|
72
|
+
|
73
|
+
class << self
|
74
|
+
attr_accessor :api_base, :api_version
|
75
|
+
attr_reader :api_staging, :support_email, :docs_url
|
76
|
+
attr_accessor :client_id, :client_secret, :api_sandbox
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module SynapsePay
|
2
|
+
class APIClient
|
3
|
+
attr_accessor :headers, :params
|
4
|
+
|
5
|
+
def initialize(headers, params)
|
6
|
+
self.refresh_from(headers, params)
|
7
|
+
end
|
8
|
+
|
9
|
+
def refresh_from(headers, params)
|
10
|
+
@headers = headers
|
11
|
+
@params = params
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute(api_method)
|
16
|
+
api_method.headers = ParamsBuilder.merge(api_method.headers, @headers)
|
17
|
+
api_method.params = ParamsBuilder.merge(api_method.params, @params)
|
18
|
+
api_method.execute
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def inspect
|
23
|
+
"#<#{self.class}:0x#{self.object_id.to_s(16)}> Headers: " +
|
24
|
+
JSON.pretty_generate(@headers) + ", Params: " +
|
25
|
+
JSON.pretty_generate(@params)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module SynapsePay
|
2
|
+
class APIList < APIResource
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
attr_reader :data
|
6
|
+
attr_reader :klass
|
7
|
+
attr_reader :client
|
8
|
+
|
9
|
+
def initialize(klass, json={}, api_method=nil, client=nil)
|
10
|
+
if klass.is_a?(Class)
|
11
|
+
@klass = klass
|
12
|
+
else
|
13
|
+
@klass = Util.constantize(klass)
|
14
|
+
end
|
15
|
+
|
16
|
+
refresh_from(json, api_method, client)
|
17
|
+
end
|
18
|
+
|
19
|
+
def refresh_from(json, api_method=nil, client=nil)
|
20
|
+
unless json.is_a?(Hash)
|
21
|
+
json = {
|
22
|
+
:data => json
|
23
|
+
}
|
24
|
+
end
|
25
|
+
json = Util.symbolize_keys(json)
|
26
|
+
|
27
|
+
clear_api_attributes
|
28
|
+
@api_method = api_method
|
29
|
+
@client = client
|
30
|
+
@data = []
|
31
|
+
@json = Util.sorta_deep_clone(json)
|
32
|
+
|
33
|
+
json.each do |k, v|
|
34
|
+
if k.to_sym == :data
|
35
|
+
if v.respond_to?(:map)
|
36
|
+
instance_variable_set("@#{k}", v.map{ |i| @klass.new(i, @api_method, @client) })
|
37
|
+
else
|
38
|
+
instance_variable_set("@#{k}", v || [])
|
39
|
+
end
|
40
|
+
elsif self.class.api_attribute_names.include?(k)
|
41
|
+
instance_variable_set("@#{k}", determine_api_attribute_value(k, v))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
47
|
+
def [](k)
|
48
|
+
data[k]
|
49
|
+
end
|
50
|
+
|
51
|
+
def []=(k, v)
|
52
|
+
data[k]=v
|
53
|
+
end
|
54
|
+
|
55
|
+
def last
|
56
|
+
data.last
|
57
|
+
end
|
58
|
+
|
59
|
+
def length
|
60
|
+
data.length
|
61
|
+
end
|
62
|
+
|
63
|
+
def each(&blk)
|
64
|
+
data.each(&blk)
|
65
|
+
end
|
66
|
+
|
67
|
+
def inspect
|
68
|
+
"#<#{self.class}[#{@klass}]:0x#{self.object_id.to_s(16)}> Data: " + JSON.pretty_generate(inspect_data)
|
69
|
+
end
|
70
|
+
|
71
|
+
def inspect_data
|
72
|
+
ret = []
|
73
|
+
data.each do |d|
|
74
|
+
if d.respond_to?(:inspect_nested)
|
75
|
+
ret << d.inspect_nested
|
76
|
+
else
|
77
|
+
ret << d
|
78
|
+
end
|
79
|
+
end
|
80
|
+
ret
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
@api_attributes = {
|
85
|
+
:data => { :readonly => true }
|
86
|
+
}
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module SynapsePay
|
2
|
+
class APIMethod
|
3
|
+
|
4
|
+
attr_accessor :path
|
5
|
+
attr_accessor :method
|
6
|
+
attr_accessor :params
|
7
|
+
attr_accessor :headers
|
8
|
+
|
9
|
+
attr_accessor :response_body
|
10
|
+
attr_accessor :response_code
|
11
|
+
attr_accessor :error
|
12
|
+
|
13
|
+
attr_accessor :api_base
|
14
|
+
|
15
|
+
def initialize(method, path, params, headers, object)
|
16
|
+
@api_base = api_base || SynapsePay.api_base
|
17
|
+
|
18
|
+
@method = method.to_sym
|
19
|
+
@path = PathBuilder.build(path, object, params)
|
20
|
+
@params = ParamsBuilder.build(params)
|
21
|
+
@headers = HeadersBuilder.build(headers)
|
22
|
+
end
|
23
|
+
|
24
|
+
def execute
|
25
|
+
begin
|
26
|
+
response = Requester.request(method, url, params, headers)
|
27
|
+
@response_body = response.body
|
28
|
+
@response_code = response.code
|
29
|
+
rescue Exception => e
|
30
|
+
@response_body = e.http_body if e.respond_to?(:http_body)
|
31
|
+
@response_code = e.http_code if e.respond_to?(:http_code)
|
32
|
+
@error = compose_error(e)
|
33
|
+
raise @error
|
34
|
+
end
|
35
|
+
|
36
|
+
response_json
|
37
|
+
end
|
38
|
+
|
39
|
+
def url
|
40
|
+
"#{api_base}#{@path}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def response_json
|
44
|
+
begin
|
45
|
+
json = Util.symbolize_keys(JSON.parse(@response_body))
|
46
|
+
rescue JSON::ParserError
|
47
|
+
@error = APIError.new("Unable to parse the server response as JSON.", self)
|
48
|
+
raise @error
|
49
|
+
end
|
50
|
+
if(!json[:success])
|
51
|
+
@error = APIError.new(json, self)
|
52
|
+
raise @error
|
53
|
+
end
|
54
|
+
json
|
55
|
+
end
|
56
|
+
|
57
|
+
def compose_error(error)
|
58
|
+
msg = "An error occured while making the API call."
|
59
|
+
|
60
|
+
case error
|
61
|
+
when RestClient::ExceptionWithResponse
|
62
|
+
return error_with_response(error)
|
63
|
+
|
64
|
+
when RestClient::RequestTimeout
|
65
|
+
msg = "The request timed out while making the API call."
|
66
|
+
|
67
|
+
when RestClient::ServerBrokeConnection
|
68
|
+
msg = "The connection to the server broke before the request completed."
|
69
|
+
|
70
|
+
when SocketError
|
71
|
+
msg = "An unexpected error occured while trying to connect to " \
|
72
|
+
"the API. You may be seeing this message because your DNS is " \
|
73
|
+
"not working. To check, try running 'host #{SynapsePay.api_base}' "\
|
74
|
+
"from the command line."
|
75
|
+
|
76
|
+
else
|
77
|
+
msg = "An unexpected error occured. If this problem persists let us " \
|
78
|
+
"know at #{SynapsePay.support_email}."
|
79
|
+
end
|
80
|
+
|
81
|
+
return APIConnectionError.new(msg, self)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Handle a few common cases.
|
85
|
+
def error_with_response(error)
|
86
|
+
case @response_code
|
87
|
+
when 400, 404
|
88
|
+
return APIError.new("Invalid request. Please check the URL and parameters.", self)
|
89
|
+
when 401
|
90
|
+
return AuthenticationError.new("Authentication failed. Please check your API key and verify that it is correct.", self)
|
91
|
+
else
|
92
|
+
return APIError.new("An error occured while making the API call.", self)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|