synapse_pay_rest 0.0.4.b → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/synapse_pay_rest.rb +17 -15
- data/lib/synapse_pay_rest/api/Node.rb +41 -39
- data/lib/synapse_pay_rest/api/Trans.rb +38 -36
- data/lib/synapse_pay_rest/api/User.rb +79 -77
- data/lib/synapse_pay_rest/http_client.rb +81 -79
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3927f7461d624db66ce73adfaa792c0fade9a472
|
4
|
+
data.tar.gz: bfdfb7c62641f8482361576ad44e330677b18624
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4abcb84d3ad752fed4d6b7ed9302936ad0d0c1620df29a319523ec0830d10212bb9a0776318125f9cc5aea7cc10e4e8f874ec49eacbdb1c9b241d7d5decd9de2
|
7
|
+
data.tar.gz: d48c93f2a7cb85651f14cb8b2833b0ab62b2b0f289d9d35536396d37ffdac2caca3da2a2727625a6f67d15fcdd26b432d7fa4324c683c0392462e010bdfe4bd1
|
data/lib/synapse_pay_rest.rb
CHANGED
@@ -5,24 +5,26 @@ require_relative "synapse_pay_rest/api/User"
|
|
5
5
|
require_relative "synapse_pay_rest/api/Node"
|
6
6
|
require_relative "synapse_pay_rest/api/Trans"
|
7
7
|
|
8
|
-
|
8
|
+
module SynapsePayRest
|
9
|
+
class Client
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
attr_accessor :client
|
12
|
+
attr_accessor :user
|
13
|
+
attr_accessor :node
|
14
|
+
attr_accessor :trans
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def initialize(options: , user_id: nil)
|
17
|
+
base_url = 'https://synapsepay.com/api/3'
|
18
|
+
if options.has_key?('is_development')
|
19
|
+
if options['is_development']
|
20
|
+
base_url = 'https://sandbox.synapsepay.com/api/3'
|
21
|
+
end
|
20
22
|
end
|
21
|
-
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
@client = HTTPClient.new options, base_url, user_id: user_id
|
25
|
+
@user = User.new @client
|
26
|
+
@node = Node.new @client
|
27
|
+
@trans = Trans.new @client
|
28
|
+
end
|
27
29
|
end
|
28
30
|
end
|
@@ -1,53 +1,55 @@
|
|
1
|
-
|
1
|
+
module SynapsePayRest
|
2
|
+
class Node
|
2
3
|
|
3
|
-
|
4
|
+
attr_accessor :client
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def create_node_path(node_id: nil)
|
10
|
-
path = '/users/%s' % @client.user_id + '/nodes'
|
11
|
-
if node_id
|
12
|
-
path += '/%s' %node_id
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
13
8
|
end
|
14
|
-
return path
|
15
|
-
end
|
16
9
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
10
|
+
def create_node_path(node_id: nil)
|
11
|
+
path = '/users/%s' % @client.user_id + '/nodes'
|
12
|
+
if node_id
|
13
|
+
path += '/%s' %node_id
|
14
|
+
end
|
15
|
+
return path
|
16
|
+
end
|
22
17
|
|
23
|
-
|
24
|
-
if node_id
|
25
|
-
path = create_node_path(node_id: node_id)
|
26
|
-
else
|
18
|
+
def add(payload: )
|
27
19
|
path = create_node_path()
|
20
|
+
response = @client.post(path, payload)
|
21
|
+
return response
|
22
|
+
end
|
23
|
+
|
24
|
+
def get(node_id: nil, page: nil)
|
25
|
+
if node_id
|
26
|
+
path = create_node_path(node_id: node_id)
|
27
|
+
else
|
28
|
+
path = create_node_path()
|
29
|
+
end
|
30
|
+
if page
|
31
|
+
path += '?page=%s' %page
|
32
|
+
end
|
33
|
+
response = @client.get(path)
|
34
|
+
return response
|
28
35
|
end
|
29
|
-
|
30
|
-
|
36
|
+
|
37
|
+
def verify(node_id: nil, payload: )
|
38
|
+
if node_id
|
39
|
+
path = create_node_path(node_id: node_id)
|
40
|
+
response = @client.patch(path, payload)
|
41
|
+
return response
|
42
|
+
else
|
43
|
+
path = create_node_path()
|
44
|
+
response = @client.post(path, payload)
|
45
|
+
return response
|
46
|
+
end
|
31
47
|
end
|
32
|
-
response = @client.get(path)
|
33
|
-
return response
|
34
|
-
end
|
35
48
|
|
36
|
-
|
37
|
-
if node_id
|
49
|
+
def delete(node_id: )
|
38
50
|
path = create_node_path(node_id: node_id)
|
39
|
-
response = @client.
|
40
|
-
return response
|
41
|
-
else
|
42
|
-
path = create_node_path()
|
43
|
-
response = @client.post(path, payload)
|
51
|
+
response = @client.delete(path)
|
44
52
|
return response
|
45
53
|
end
|
46
54
|
end
|
47
|
-
|
48
|
-
def delete(node_id: )
|
49
|
-
path = create_node_path(node_id: node_id)
|
50
|
-
response = @client.delete(path)
|
51
|
-
return response
|
52
|
-
end
|
53
55
|
end
|
@@ -1,49 +1,51 @@
|
|
1
|
-
|
1
|
+
module SynapsePayRest
|
2
|
+
class Trans
|
2
3
|
|
3
|
-
|
4
|
+
attr_accessor :client
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def create_transaction_path(node_id: , trans_id: nil)
|
10
|
-
path = '/users/' + @client.user_id + '/nodes/' + node_id + '/trans'
|
11
|
-
if trans_id
|
12
|
-
path += '/%s' %trans_id
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
13
8
|
end
|
14
|
-
return path
|
15
|
-
end
|
16
9
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
10
|
+
def create_transaction_path(node_id: , trans_id: nil)
|
11
|
+
path = '/users/' + @client.user_id + '/nodes/' + node_id + '/trans'
|
12
|
+
if trans_id
|
13
|
+
path += '/%s' %trans_id
|
14
|
+
end
|
15
|
+
return path
|
16
|
+
end
|
22
17
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
def create(node_id: , payload: )
|
19
|
+
path = create_transaction_path(node_id: node_id)
|
20
|
+
response = @client.post(path, payload)
|
21
|
+
return response
|
22
|
+
end
|
28
23
|
|
29
|
-
|
30
|
-
if trans_id
|
24
|
+
def update(node_id: , trans_id: , payload: )
|
31
25
|
path = create_transaction_path(node_id: node_id, trans_id: trans_id)
|
32
|
-
response = @client.
|
26
|
+
response = @client.patch(path, payload)
|
33
27
|
return response
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
28
|
+
end
|
29
|
+
|
30
|
+
def get(node_id: , trans_id: nil, page: nil)
|
31
|
+
if trans_id
|
32
|
+
path = create_transaction_path(node_id: node_id, trans_id: trans_id)
|
33
|
+
response = @client.get(path)
|
34
|
+
return response
|
35
|
+
else
|
36
|
+
path = create_transaction_path(node_id: node_id)
|
37
|
+
if page
|
38
|
+
path += '?page=%d' %page
|
39
|
+
end
|
40
|
+
response = @client.get(path)
|
41
|
+
return response
|
38
42
|
end
|
39
|
-
response = @client.get(path)
|
40
|
-
return response
|
41
43
|
end
|
42
|
-
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
def delete(node_id: , trans_id: )
|
46
|
+
path = create_transaction_path(node_id: node_id, trans_id: trans_id)
|
47
|
+
response = @client.delete(path)
|
48
|
+
return response
|
49
|
+
end
|
48
50
|
end
|
49
51
|
end
|
@@ -1,97 +1,99 @@
|
|
1
1
|
require 'mime-types'
|
2
2
|
require 'base64'
|
3
3
|
|
4
|
-
|
4
|
+
module SynapsePayRest
|
5
|
+
class User
|
5
6
|
|
6
|
-
|
7
|
+
attr_accessor :client
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
def create_user_path(user_id: nil)
|
13
|
-
path = '/users'
|
14
|
-
if user_id
|
15
|
-
path += '/%s' %user_id
|
9
|
+
def initialize(client)
|
10
|
+
@client = client
|
16
11
|
end
|
17
|
-
return path
|
18
|
-
end
|
19
12
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
13
|
+
def create_user_path(user_id: nil)
|
14
|
+
path = '/users'
|
15
|
+
if user_id
|
16
|
+
path += '/%s' %user_id
|
17
|
+
end
|
18
|
+
return path
|
25
19
|
end
|
26
|
-
return response
|
27
|
-
end
|
28
20
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
response
|
33
|
-
|
34
|
-
@client.update_headers(user_id: response['_id'])
|
21
|
+
def refresh(payload: )
|
22
|
+
path = '/oauth/%s' % @client.user_id
|
23
|
+
response = @client.post(path, payload)
|
24
|
+
if response.has_key?('oauth_key')
|
25
|
+
@client.update_headers(oauth_key: response['oauth_key'])
|
35
26
|
end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
path += '
|
27
|
+
return response
|
28
|
+
end
|
29
|
+
|
30
|
+
def get(user_id: nil, query: nil, page: nil, per_page: nil)
|
31
|
+
if user_id
|
32
|
+
path = create_user_path(user_id: user_id)
|
33
|
+
response = @client.get(path)
|
34
|
+
if response.has_key?('_id')
|
35
|
+
@client.update_headers(user_id: response['_id'])
|
36
|
+
end
|
37
|
+
elsif query
|
38
|
+
path += '?query=%s' %query
|
39
|
+
if page
|
40
|
+
path += '&page=%s' %page
|
41
|
+
end
|
42
|
+
if per_page
|
43
|
+
path += '&per_page=%s' %per_page
|
44
|
+
end
|
45
|
+
elsif page
|
46
|
+
path += '?page=%s' %page
|
47
|
+
if per_page
|
48
|
+
path += '&per_page=%s' %per_page
|
49
|
+
end
|
50
|
+
elsif per_page
|
51
|
+
path += '?page=%s' %per_page
|
52
|
+
else
|
53
|
+
path = create_user_path()
|
48
54
|
end
|
49
|
-
|
50
|
-
|
51
|
-
else
|
52
|
-
path = create_user_path()
|
55
|
+
response = @client.get(path)
|
56
|
+
return response
|
53
57
|
end
|
54
|
-
response = @client.get(path)
|
55
|
-
return response
|
56
|
-
end
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
def update(payload: )
|
60
|
+
path = create_user_path(user_id: @client.user_id)
|
61
|
+
response = @client.patch(path, payload)
|
62
|
+
return response
|
63
|
+
end
|
63
64
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
def create(payload: )
|
66
|
+
path = create_user_path()
|
67
|
+
response = @client.post(path, payload)
|
68
|
+
return response
|
69
|
+
end
|
69
70
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
def add_doc(payload: )
|
72
|
+
path = create_user_path(user_id: @client.user_id)
|
73
|
+
response = @client.patch(path, payload)
|
74
|
+
return response
|
75
|
+
end
|
75
76
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
77
|
+
def answer_kba(payload: )
|
78
|
+
path = create_user_path(user_id: @client.user_id)
|
79
|
+
response = @client.patch(path, payload)
|
80
|
+
return response
|
81
|
+
end
|
81
82
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
83
|
+
def attach_file(file)
|
84
|
+
path = create_user_path(user_id: @client.user_id)
|
85
|
+
file_type = MIME::Types.type_for(file.path).first.content_type
|
86
|
+
mime_padding = 'data:' + file_type + ';base64,'
|
87
|
+
content = file.read
|
88
|
+
encoded = Base64.encode64(content)
|
89
|
+
base64_attachment = mime_padding + encoded
|
90
|
+
payload = {
|
91
|
+
'doc' => {
|
92
|
+
'attachment' => base64_attachment
|
93
|
+
}
|
92
94
|
}
|
93
|
-
|
94
|
-
|
95
|
-
|
95
|
+
response = @client.patch(path, payload)
|
96
|
+
return response
|
97
|
+
end
|
96
98
|
end
|
97
99
|
end
|
@@ -1,98 +1,100 @@
|
|
1
1
|
require 'rest-client'
|
2
2
|
|
3
|
-
|
3
|
+
module SynapsePayRest
|
4
|
+
class HTTPClient
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
attr_accessor :base_url
|
7
|
+
attr_accessor :options
|
8
|
+
attr_accessor :headers
|
9
|
+
attr_accessor :user_id
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
@user_id = user_id
|
27
|
-
end
|
28
|
-
|
29
|
-
def update_headers(user_id: nil, oauth_key: nil, fingerprint: nil, client_id: nil, client_secret: nil, ip_address: nil)
|
30
|
-
if user_id
|
11
|
+
def initialize(options, base_url, user_id: nil)
|
12
|
+
@options = options
|
13
|
+
user = '|%s' %options['fingerprint']
|
14
|
+
if options.has_key?('oauth_key')
|
15
|
+
user = '%s|%s' % [options['oauth_key'], options['fingerprint']]
|
16
|
+
end
|
17
|
+
gateway = '%s|%s' % [options['client_id'], options['client_secret']]
|
18
|
+
@headers = {
|
19
|
+
:content_type => :json,
|
20
|
+
:accept => :json,
|
21
|
+
'X-SP-GATEWAY' => gateway,
|
22
|
+
'X-SP-USER' => user,
|
23
|
+
'X-SP-USER-IP' => options['ip_address']
|
24
|
+
}
|
25
|
+
@base_url = base_url
|
26
|
+
# RestClient.log = 'stdout'
|
31
27
|
@user_id = user_id
|
32
28
|
end
|
33
|
-
if oauth_key and !fingerprint
|
34
|
-
@headers['X-SP-USER'] = '%s|%s' % [oauth_key, @options['fingerprint']]
|
35
|
-
elsif oauth_key and fingerprint
|
36
|
-
@headers['X-SP-USER'] = '%s|%s' % [oauth_key, fingerprint]
|
37
|
-
end
|
38
29
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
30
|
+
def update_headers(user_id: nil, oauth_key: nil, fingerprint: nil, client_id: nil, client_secret: nil, ip_address: nil)
|
31
|
+
if user_id
|
32
|
+
@user_id = user_id
|
33
|
+
end
|
34
|
+
if oauth_key and !fingerprint
|
35
|
+
@headers['X-SP-USER'] = '%s|%s' % [oauth_key, @options['fingerprint']]
|
36
|
+
elsif oauth_key and fingerprint
|
37
|
+
@headers['X-SP-USER'] = '%s|%s' % [oauth_key, fingerprint]
|
38
|
+
end
|
46
39
|
|
47
|
-
|
48
|
-
|
40
|
+
if client_id and !client_secret
|
41
|
+
@headers['X-SP-GATEWAY'] = '%s|%s' % [client_id, @options['client_secret']]
|
42
|
+
elsif client_id and client_secret
|
43
|
+
@headers['X-SP-GATEWAY'] = '%s|%s' % [client_id, client_secret]
|
44
|
+
elsif !client_id and client_secret
|
45
|
+
@headers['X-SP-GATEWAY'] = '%s|%s' % [@options['client_id'], client_secret]
|
46
|
+
end
|
47
|
+
|
48
|
+
if ip_address
|
49
|
+
@headers['X-SP-USER-IP'] = ip_address
|
50
|
+
end
|
49
51
|
end
|
50
|
-
|
51
|
-
|
52
|
+
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
54
|
+
def post(path, payload)
|
55
|
+
url = base_url + path
|
56
|
+
response = begin
|
57
|
+
RestClient.post(url,
|
58
|
+
payload.to_json,
|
59
|
+
@headers)
|
60
|
+
rescue Exception => e
|
61
|
+
return JSON.parse(e.response)
|
62
|
+
end
|
63
|
+
return JSON.parse(response)
|
61
64
|
end
|
62
|
-
return JSON.parse(response)
|
63
|
-
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
66
|
+
def patch(path, payload)
|
67
|
+
url = base_url + path
|
68
|
+
response = begin
|
69
|
+
RestClient.patch(url,
|
70
|
+
payload.to_json,
|
71
|
+
@headers)
|
72
|
+
rescue Exception => e
|
73
|
+
return JSON.parse(e.response)
|
74
|
+
end
|
75
|
+
return JSON.parse(response)
|
73
76
|
end
|
74
|
-
return JSON.parse(response)
|
75
|
-
end
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
78
|
+
def get(path)
|
79
|
+
url = base_url + path
|
80
|
+
response = begin
|
81
|
+
RestClient.get(url,
|
82
|
+
@headers)
|
83
|
+
rescue Exception => e
|
84
|
+
return JSON.parse(e.response)
|
85
|
+
end
|
86
|
+
return JSON.parse(response)
|
84
87
|
end
|
85
|
-
return JSON.parse(response)
|
86
|
-
end
|
87
88
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
89
|
+
def delete(path)
|
90
|
+
url = base_url + path
|
91
|
+
response = begin
|
92
|
+
RestClient.delete(url,
|
93
|
+
@headers)
|
94
|
+
rescue Exception => e
|
95
|
+
return JSON.parse(e.response)
|
96
|
+
end
|
97
|
+
return JSON.parse(response)
|
95
98
|
end
|
96
|
-
return JSON.parse(response)
|
97
99
|
end
|
98
100
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synapse_pay_rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Hipps
|
@@ -50,9 +50,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
50
|
version: '0'
|
51
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- - "
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
55
|
+
version: '0'
|
56
56
|
requirements: []
|
57
57
|
rubyforge_project:
|
58
58
|
rubygems_version: 2.4.6
|