synapse_pay_rest 0.0.11 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +39 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +45 -0
- data/README.md +35 -0
- data/Rakefile +10 -0
- data/lib/synapse_pay_rest.rb +20 -25
- data/lib/synapse_pay_rest/api/nodes.rb +46 -0
- data/lib/synapse_pay_rest/api/trans.rb +38 -0
- data/lib/synapse_pay_rest/api/users.rb +97 -0
- data/lib/synapse_pay_rest/error.rb +114 -0
- data/lib/synapse_pay_rest/http_client.rb +109 -98
- data/lib/synapse_pay_rest/version.rb +3 -0
- data/samples.md +276 -0
- data/synapse_pay_rest.gemspec +27 -0
- metadata +74 -8
- data/lib/synapse_pay_rest/api/Nodes.rb +0 -55
- data/lib/synapse_pay_rest/api/Trans.rb +0 -51
- data/lib/synapse_pay_rest/api/Users.rb +0 -103
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4dbdc072bf2803c60e736b7dd86c3ee77a116051
|
4
|
+
data.tar.gz: 54a9502bfcabffb266b2cb9b7a0b98f95ecd3fbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fd8d2bf9dadecaed2e2e54e97cffb8bc0a5f318638916b270987bc5ca752133a837de4d9f9c68e02bc182411973f4b6bd1f83dc0c5e23dbbea127010a0c8231
|
7
|
+
data.tar.gz: 57b16b876a60d60109a812c487609fefdd0c91ece4d86c456049f7762ad8ae9b400bc0ee43f6973b6f795f7930a652ca03f3c2fbfc144dba6721acf0e07423f8
|
data/.gitignore
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
## Specific to RubyMotion:
|
14
|
+
.dat*
|
15
|
+
.repl_history
|
16
|
+
build/
|
17
|
+
|
18
|
+
## Documentation cache and generated files:
|
19
|
+
/.yardoc/
|
20
|
+
/_yardoc/
|
21
|
+
/doc/
|
22
|
+
/rdoc/
|
23
|
+
|
24
|
+
## Environment normalisation:
|
25
|
+
/.bundle/
|
26
|
+
/vendor/bundle
|
27
|
+
/lib/bundler/man/
|
28
|
+
|
29
|
+
# for a library or gem, you might want to ignore these files since the code is
|
30
|
+
# intended to run in multiple environments; otherwise, check them in:
|
31
|
+
# Gemfile.lock
|
32
|
+
# .ruby-version
|
33
|
+
# .ruby-gemset
|
34
|
+
|
35
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
36
|
+
.rvmrc
|
37
|
+
|
38
|
+
|
39
|
+
.DS_Store
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
synapse_pay_rest (0.0.10)
|
5
|
+
rest-client
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ansi (1.5.0)
|
11
|
+
builder (3.2.2)
|
12
|
+
domain_name (0.5.25)
|
13
|
+
unf (>= 0.0.5, < 1.0.0)
|
14
|
+
http-cookie (1.0.2)
|
15
|
+
domain_name (~> 0.5)
|
16
|
+
mime-types (2.6.2)
|
17
|
+
minitest (5.8.2)
|
18
|
+
minitest-reporters (1.1.5)
|
19
|
+
ansi
|
20
|
+
builder
|
21
|
+
minitest (>= 5.0)
|
22
|
+
ruby-progressbar
|
23
|
+
netrc (0.11.0)
|
24
|
+
rake (10.4.2)
|
25
|
+
rest-client (1.8.0)
|
26
|
+
http-cookie (>= 1.0.2, < 2.0)
|
27
|
+
mime-types (>= 1.16, < 3.0)
|
28
|
+
netrc (~> 0.7)
|
29
|
+
ruby-progressbar (1.7.5)
|
30
|
+
unf (0.1.4)
|
31
|
+
unf_ext
|
32
|
+
unf_ext (0.0.7.1)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
ruby
|
36
|
+
|
37
|
+
DEPENDENCIES
|
38
|
+
bundler (~> 1.10)
|
39
|
+
minitest
|
40
|
+
minitest-reporters
|
41
|
+
rake (~> 10.0)
|
42
|
+
synapse_pay_rest!
|
43
|
+
|
44
|
+
BUNDLED WITH
|
45
|
+
1.10.6
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
## SynapsePayRest-Ruby
|
2
|
+
|
3
|
+
Simple API wrapper for SynapsePay REST V3 API. This wrapper aims to handle the headers for each API request and appropriate error handling.
|
4
|
+
|
5
|
+
|
6
|
+
## Code Example
|
7
|
+
|
8
|
+
Check out the samples.md and our API documentation(http://docs.synapsepay.com/v3.1) for examples.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
gem install synapse_pay_rest
|
13
|
+
|
14
|
+
## License
|
15
|
+
|
16
|
+
The MIT License (MIT)
|
17
|
+
|
18
|
+
Copyright (c) 2014 SynapsePay LLC
|
19
|
+
|
20
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
21
|
+
this software and associated documentation files (the "Software"), to deal in
|
22
|
+
the Software without restriction, including without limitation the rights to
|
23
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
24
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
25
|
+
subject to the following conditions:
|
26
|
+
|
27
|
+
The above copyright notice and this permission notice shall be included in all
|
28
|
+
copies or substantial portions of the Software.
|
29
|
+
|
30
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
31
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
32
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
33
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
34
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
35
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/lib/synapse_pay_rest.rb
CHANGED
@@ -1,30 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
require "synapse_pay_rest/http_client"
|
2
|
+
require "synapse_pay_rest/error"
|
3
|
+
require "synapse_pay_rest/version"
|
4
|
+
require "synapse_pay_rest/api/users"
|
5
|
+
require "synapse_pay_rest/api/nodes"
|
6
|
+
require "synapse_pay_rest/api/trans"
|
7
7
|
|
8
8
|
module SynapsePayRest
|
9
|
-
|
9
|
+
class Client
|
10
|
+
attr_accessor :client, :users, :nodes, :trans
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def initialize(options: raise("options is required"), user_id: nil)
|
13
|
+
base_url = if options['development_mode']
|
14
|
+
'https://sandbox.synapsepay.com/api/3'
|
15
|
+
else
|
16
|
+
'https://synapsepay.com/api/3'
|
17
|
+
end
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
@client = HTTPClient.new options, base_url, user_id: user_id
|
25
|
-
@users = Users.new @client
|
26
|
-
@nodes = Nodes.new @client
|
27
|
-
@trans = Trans.new @client
|
28
|
-
end
|
29
|
-
end
|
19
|
+
@client = HTTPClient.new options, base_url, user_id: user_id
|
20
|
+
@users = Users.new @client
|
21
|
+
@nodes = Nodes.new @client
|
22
|
+
@trans = Trans.new @client
|
23
|
+
end
|
24
|
+
end
|
30
25
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module SynapsePayRest
|
2
|
+
class Nodes
|
3
|
+
|
4
|
+
attr_accessor :client
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_node_path(node_id: nil)
|
11
|
+
path = ['/users', client.user_id, 'nodes' ]
|
12
|
+
path << node_id if node_id
|
13
|
+
return path.join('/')
|
14
|
+
end
|
15
|
+
|
16
|
+
def add(payload: raise("payload is required"))
|
17
|
+
path = create_node_path
|
18
|
+
client.post(path, payload)
|
19
|
+
end
|
20
|
+
|
21
|
+
def get(node_id: nil, page: nil)
|
22
|
+
# If node_id is nil then create_node_path will handle it just fine
|
23
|
+
path = create_node_path(node_id: node_id)
|
24
|
+
path += "?page=#{page}" if page
|
25
|
+
client.get(path)
|
26
|
+
end
|
27
|
+
|
28
|
+
def verify(node_id: nil, payload: raise("payload is required"))
|
29
|
+
if node_id
|
30
|
+
# verify microdeposits
|
31
|
+
path = create_node_path(node_id: node_id)
|
32
|
+
response = @client.patch(path, payload)
|
33
|
+
else
|
34
|
+
# verify MFA question(s)
|
35
|
+
path = create_node_path
|
36
|
+
response = @client.post(path, payload)
|
37
|
+
end
|
38
|
+
response
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete(node_id: raise("node_id is required"))
|
42
|
+
path = create_node_path(node_id: node_id)
|
43
|
+
client.delete(path)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module SynapsePayRest
|
2
|
+
class Trans
|
3
|
+
|
4
|
+
attr_accessor :client
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_transaction_path(node_id: raise("node_id is required"), trans_id: nil)
|
11
|
+
path = ['/users', client.user_id, 'nodes', node_id, 'trans' ]
|
12
|
+
path << trans_id if trans_id
|
13
|
+
return path.join('/')
|
14
|
+
end
|
15
|
+
|
16
|
+
def create(node_id: raise("node_id is required"), payload: raise("payload is required"))
|
17
|
+
path = create_transaction_path(node_id: node_id)
|
18
|
+
client.post(path, payload)
|
19
|
+
end
|
20
|
+
|
21
|
+
def update(node_id: raise("node_id is required"), trans_id: raise("trans_id is required"), payload: raise("payload is required"))
|
22
|
+
path = create_transaction_path(node_id: node_id, trans_id: trans_id)
|
23
|
+
client.patch(path, payload)
|
24
|
+
end
|
25
|
+
|
26
|
+
def get(node_id: raise("node_id is required"), trans_id: nil, page: nil)
|
27
|
+
path = create_transaction_path(node_id: node_id, trans_id: trans_id)
|
28
|
+
# This part really should just be a generic params generator
|
29
|
+
path += "?page=#{page}" if page
|
30
|
+
client.get(path)
|
31
|
+
end
|
32
|
+
|
33
|
+
def delete(node_id: raise("node_id is required"), trans_id: raise("trans_id is required"))
|
34
|
+
path = create_transaction_path(node_id: node_id, trans_id: trans_id)
|
35
|
+
client.delete(path)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'mime-types'
|
2
|
+
require 'base64'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
module SynapsePayRest
|
6
|
+
class Users
|
7
|
+
# Should refactor this to HTTPClient
|
8
|
+
VALID_QUERY_PARAMS = [:query, :page, :per_page].freeze
|
9
|
+
|
10
|
+
attr_accessor :client
|
11
|
+
|
12
|
+
def initialize(client)
|
13
|
+
@client = client
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_user_path(user_id: nil)
|
17
|
+
path = ['/users']
|
18
|
+
path << user_id if user_id
|
19
|
+
return path.join('/')
|
20
|
+
end
|
21
|
+
|
22
|
+
def refresh(payload: raise("payload is required"))
|
23
|
+
path = "/oauth/#{@client.user_id}"
|
24
|
+
response = @client.post(path, payload)
|
25
|
+
client.update_headers(oauth_key: response['oauth_key']) if response['oauth_key']
|
26
|
+
return response
|
27
|
+
end
|
28
|
+
|
29
|
+
def get(user_id: nil, options: {})
|
30
|
+
path = create_user_path(user_id: user_id)
|
31
|
+
|
32
|
+
if options[:user_id]
|
33
|
+
response = client.get(path)
|
34
|
+
client.update_headers(user_id: response['_id']) if response['_id']
|
35
|
+
return response
|
36
|
+
end
|
37
|
+
|
38
|
+
# Should factor this out into HTTPClient
|
39
|
+
params = VALID_QUERY_PARAMS.map do |p|
|
40
|
+
options[p] ? "#{p}=#{options[p]}" : nil
|
41
|
+
end.compact
|
42
|
+
|
43
|
+
# Probably should use CGI or RestClient's param builder instead of
|
44
|
+
# rolling our own, probably error-prone and untested version
|
45
|
+
# https://github.com/rest-client/rest-client#usage-raw-url
|
46
|
+
path += '?' + params.join('&') if params.any?
|
47
|
+
client.get(path)
|
48
|
+
end
|
49
|
+
|
50
|
+
def update(payload: raise("payload is required"))
|
51
|
+
path = create_user_path(user_id: client.user_id)
|
52
|
+
client.patch(path, payload)
|
53
|
+
end
|
54
|
+
|
55
|
+
def create(payload: raise("payload is required"))
|
56
|
+
path = create_user_path
|
57
|
+
response = client.post(path, payload)
|
58
|
+
client.update_headers(user_id: response['_id']) if response['_id']
|
59
|
+
return response
|
60
|
+
end
|
61
|
+
|
62
|
+
def add_doc(payload: raise("payload is required"))
|
63
|
+
path = create_user_path(user_id: client.user_id)
|
64
|
+
client.patch(path, payload)
|
65
|
+
end
|
66
|
+
|
67
|
+
def answer_kba(payload: raise("payload is required"))
|
68
|
+
path = create_user_path(user_id: client.user_id)
|
69
|
+
client.patch(path, payload)
|
70
|
+
end
|
71
|
+
|
72
|
+
def attach_file(file_path: raise("file_path is required"))
|
73
|
+
file_contents = open(file_path) { |f| f.read }
|
74
|
+
file_type = MIME::Types.type_for(file_path).first.try(:content_type)
|
75
|
+
if file_type.nil?
|
76
|
+
raise("File type not found. Use attach_file_with_file_type(file_path: <file_path>, file_type: <file_type>)")
|
77
|
+
else
|
78
|
+
attach_file_with_file_type(file_path: file_path, file_type: file_type)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def attach_file_with_file_type(file_path: raise("file_path is required"), file_type: raise("file_type is required"))
|
83
|
+
path = create_user_path(user_id: @client.user_id)
|
84
|
+
file_contents = open(file_path) { |f| f.read }
|
85
|
+
encoded = Base64.encode64(file_contents)
|
86
|
+
mime_padding = "data:#{file_type};base64,"
|
87
|
+
base64_attachment = mime_padding + encoded
|
88
|
+
|
89
|
+
payload = {
|
90
|
+
'doc' => {
|
91
|
+
'attachment' => base64_attachment
|
92
|
+
}
|
93
|
+
}
|
94
|
+
client.patch(path, payload)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module SynapsePayRest
|
2
|
+
class Error < StandardError
|
3
|
+
# Raised on a 4xx HTTP status code
|
4
|
+
ClientError = Class.new(self)
|
5
|
+
|
6
|
+
# Raised on the HTTP status code 400
|
7
|
+
BadRequest = Class.new(ClientError)
|
8
|
+
|
9
|
+
# Raised on the HTTP status code 401
|
10
|
+
Unauthorized = Class.new(ClientError)
|
11
|
+
|
12
|
+
# Raised on the HTTP status code 402
|
13
|
+
RequestDeclined = Class.new(ClientError)
|
14
|
+
|
15
|
+
# Raised on the HTTP status code 403
|
16
|
+
Forbidden = Class.new(ClientError)
|
17
|
+
|
18
|
+
# Raised on the HTTP status code 404
|
19
|
+
NotFound = Class.new(ClientError)
|
20
|
+
|
21
|
+
# Raised on the HTTP status code 406
|
22
|
+
NotAcceptable = Class.new(ClientError)
|
23
|
+
|
24
|
+
# Raised on the HTTP status code 409
|
25
|
+
Conflict = Class.new(ClientError)
|
26
|
+
|
27
|
+
# Raised on the HTTP status code 415
|
28
|
+
UnsupportedMediaType = Class.new(ClientError)
|
29
|
+
|
30
|
+
# Raised on the HTTP status code 422
|
31
|
+
UnprocessableEntity = Class.new(ClientError)
|
32
|
+
|
33
|
+
# Raised on the HTTP status code 429
|
34
|
+
TooManyRequests = Class.new(ClientError)
|
35
|
+
|
36
|
+
# Raised on a 5xx HTTP status code
|
37
|
+
ServerError = Class.new(self)
|
38
|
+
|
39
|
+
# Raised on the HTTP status code 500
|
40
|
+
InternalServerError = Class.new(ServerError)
|
41
|
+
|
42
|
+
# Raised on the HTTP status code 502
|
43
|
+
BadGateway = Class.new(ServerError)
|
44
|
+
|
45
|
+
# Raised on the HTTP status code 503
|
46
|
+
ServiceUnavailable = Class.new(ServerError)
|
47
|
+
|
48
|
+
# Raised on the HTTP status code 504
|
49
|
+
GatewayTimeout = Class.new(ServerError)
|
50
|
+
|
51
|
+
ERRORS = {
|
52
|
+
400 => SynapsePayRest::Error::BadRequest,
|
53
|
+
401 => SynapsePayRest::Error::Unauthorized,
|
54
|
+
402 => SynapsePayRest::Error::RequestDeclined,
|
55
|
+
403 => SynapsePayRest::Error::Forbidden,
|
56
|
+
404 => SynapsePayRest::Error::NotFound,
|
57
|
+
406 => SynapsePayRest::Error::NotAcceptable,
|
58
|
+
409 => SynapsePayRest::Error::Conflict,
|
59
|
+
415 => SynapsePayRest::Error::UnsupportedMediaType,
|
60
|
+
422 => SynapsePayRest::Error::UnprocessableEntity,
|
61
|
+
429 => SynapsePayRest::Error::TooManyRequests,
|
62
|
+
500 => SynapsePayRest::Error::InternalServerError,
|
63
|
+
502 => SynapsePayRest::Error::BadGateway,
|
64
|
+
503 => SynapsePayRest::Error::ServiceUnavailable,
|
65
|
+
504 => SynapsePayRest::Error::GatewayTimeout,
|
66
|
+
}
|
67
|
+
|
68
|
+
# The SynapsePay API Error Code
|
69
|
+
#
|
70
|
+
# @return [Integer]
|
71
|
+
attr_reader :code
|
72
|
+
|
73
|
+
# The JSON HTTP response in Hash form
|
74
|
+
#
|
75
|
+
# @return [Hash]
|
76
|
+
attr_reader :response
|
77
|
+
|
78
|
+
class << self
|
79
|
+
# Create a new error from an HTTP response
|
80
|
+
#
|
81
|
+
# @param body [String]
|
82
|
+
# @param code [Integer]
|
83
|
+
# @return [SynapsePayRest::Error]
|
84
|
+
def error_from_response(body, code)
|
85
|
+
klass = ERRORS[code] || SynapsePayRest::Error
|
86
|
+
message, error_code = parse_error(body)
|
87
|
+
klass.new(message: message, code: error_code, response: body)
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def parse_error(body)
|
93
|
+
if body.nil? || body.empty?
|
94
|
+
['', nil]
|
95
|
+
elsif body.is_a?(Hash) && body['error'].is_a?(Hash)
|
96
|
+
[body['error']['en'], body['error_code']]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
# Initializes a new Error object
|
103
|
+
#
|
104
|
+
# @param message [Exception, String]
|
105
|
+
# @param code [Integer]
|
106
|
+
# @param response [Hash]
|
107
|
+
# @return [SynapsePayRest::Error]
|
108
|
+
def initialize(message: '', code: nil, response: {})
|
109
|
+
super(message)
|
110
|
+
@code = code
|
111
|
+
@response = response
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|