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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fdf320f384974ae7a9bdf157425ab780cc8a99a
4
- data.tar.gz: fd3d5afd3e699687882099cd710573606beabf9f
3
+ metadata.gz: 3927f7461d624db66ce73adfaa792c0fade9a472
4
+ data.tar.gz: bfdfb7c62641f8482361576ad44e330677b18624
5
5
  SHA512:
6
- metadata.gz: 9206f6fef202d9eef072bd548e7a59fbada706aa0ad3e645d17bf6eabba46780deedc020c2458379af4fbdc8bfbf8b907048b58b7e0dffa5cd0eefcbb0b65665
7
- data.tar.gz: 7b3bdfbf9ea3bc40a7cef2030f7104071b4da2c3117ba8086212bf840e9aa16d64403a1a7b2eec506bf8cd112c65b086a914fd7cf4adcd299fec64fe0ec92f24
6
+ metadata.gz: 4abcb84d3ad752fed4d6b7ed9302936ad0d0c1620df29a319523ec0830d10212bb9a0776318125f9cc5aea7cc10e4e8f874ec49eacbdb1c9b241d7d5decd9de2
7
+ data.tar.gz: d48c93f2a7cb85651f14cb8b2833b0ab62b2b0f289d9d35536396d37ffdac2caca3da2a2727625a6f67d15fcdd26b432d7fa4324c683c0392462e010bdfe4bd1
@@ -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
- class SynapsePayClient
8
+ module SynapsePayRest
9
+ class Client
9
10
 
10
- attr_accessor :client
11
- attr_accessor :user
12
- attr_accessor :node
13
- attr_accessor :trans
11
+ attr_accessor :client
12
+ attr_accessor :user
13
+ attr_accessor :node
14
+ attr_accessor :trans
14
15
 
15
- def initialize(options: , user_id: nil)
16
- base_url = 'https://synapsepay.com/api/3'
17
- if options.has_key?('is_development')
18
- if options['is_development']
19
- base_url = 'https://sandbox.synapsepay.com/api/3'
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
- @client = HTTPClient.new options, base_url, user_id: user_id
24
- @user = User.new @client
25
- @node = Node.new @client
26
- @trans = Trans.new @client
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
- class Node
1
+ module SynapsePayRest
2
+ class Node
2
3
 
3
- attr_accessor :client
4
+ attr_accessor :client
4
5
 
5
- def initialize(client)
6
- @client = client
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
- def add(payload: )
18
- path = create_node_path()
19
- response = @client.post(path, payload)
20
- return response
21
- end
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
- def get(node_id: nil, page: nil)
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
- if page
30
- path += '?page=%s' %page
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
- def verify(node_id: nil, payload: )
37
- if node_id
49
+ def delete(node_id: )
38
50
  path = create_node_path(node_id: node_id)
39
- response = @client.patch(path, payload)
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
- class Trans
1
+ module SynapsePayRest
2
+ class Trans
2
3
 
3
- attr_accessor :client
4
+ attr_accessor :client
4
5
 
5
- def initialize(client)
6
- @client = client
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
- def create(node_id: , payload: )
18
- path = create_transaction_path(node_id: node_id)
19
- response = @client.post(path, payload)
20
- return response
21
- end
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
- def update(node_id: , trans_id: , payload: )
24
- path = create_transaction_path(node_id: node_id, trans_id: trans_id)
25
- response = @client.patch(path, payload)
26
- return response
27
- end
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
- def get(node_id: , trans_id: nil, page: nil)
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.get(path)
26
+ response = @client.patch(path, payload)
33
27
  return response
34
- else
35
- path = create_transaction_path(node_id: node_id)
36
- if page
37
- path += '?page=%d' %page
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
- def delete(node_id: , trans_id: )
45
- path = create_transaction_path(node_id: node_id, trans_id: trans_id)
46
- response = @client.delete(path)
47
- return response
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
- class User
4
+ module SynapsePayRest
5
+ class User
5
6
 
6
- attr_accessor :client
7
+ attr_accessor :client
7
8
 
8
- def initialize(client)
9
- @client = client
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
- def refresh(payload: )
21
- path = '/oauth/%s' % @client.user_id
22
- response = @client.post(path, payload)
23
- if response.has_key?('oauth_key')
24
- @client.update_headers(oauth_key: response['oauth_key'])
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
- def get(user_id: nil, query: nil, page: nil, per_page: nil)
30
- if user_id
31
- path = create_user_path(user_id: user_id)
32
- response = @client.get(path)
33
- if response.has_key?('_id')
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
- elsif query
37
- path += '?query=%s' %query
38
- if page
39
- path += '&page=%s' %page
40
- end
41
- if per_page
42
- path += '&per_page=%s' %per_page
43
- end
44
- elsif page
45
- path += '?page=%s' %page
46
- if per_page
47
- path += '&per_page=%s' %per_page
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
- elsif per_page
50
- path += '?page=%s' %per_page
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
- def update(payload: )
59
- path = create_user_path(user_id: @client.user_id)
60
- response = @client.patch(path, payload)
61
- return response
62
- end
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
- def create(payload: )
65
- path = create_user_path()
66
- response = @client.post(path, payload)
67
- return response
68
- end
65
+ def create(payload: )
66
+ path = create_user_path()
67
+ response = @client.post(path, payload)
68
+ return response
69
+ end
69
70
 
70
- def add_doc(payload: )
71
- path = create_user_path(user_id: @client.user_id)
72
- response = @client.patch(path, payload)
73
- return response
74
- end
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
- def answer_kba(payload: )
77
- path = create_user_path(user_id: @client.user_id)
78
- response = @client.patch(path, payload)
79
- return response
80
- end
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
- def attach_file(file)
83
- path = create_user_path(user_id: @client.user_id)
84
- file_type = MIME::Types.type_for(file.path).first.content_type
85
- mime_padding = 'data:' + file_type + ';base64,'
86
- content = file.read
87
- encoded = Base64.encode64(content)
88
- base64_attachment = mime_padding + encoded
89
- payload = {
90
- 'doc' => {
91
- 'attachment' => base64_attachment
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
- response = @client.patch(path, payload)
95
- return response
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
- class HTTPClient
3
+ module SynapsePayRest
4
+ class HTTPClient
4
5
 
5
- attr_accessor :base_url
6
- attr_accessor :options
7
- attr_accessor :headers
8
- attr_accessor :user_id
6
+ attr_accessor :base_url
7
+ attr_accessor :options
8
+ attr_accessor :headers
9
+ attr_accessor :user_id
9
10
 
10
- def initialize(options, base_url, user_id: nil)
11
- @options = options
12
- user = '|%s' %options['fingerprint']
13
- if options.has_key?('oauth_key')
14
- user = '%s|%s' % [options['oauth_key'], options['fingerprint']]
15
- end
16
- gateway = '%s|%s' % [options['client_id'], options['client_secret']]
17
- @headers = {
18
- :content_type => :json,
19
- :accept => :json,
20
- 'X-SP-GATEWAY' => gateway,
21
- 'X-SP-USER' => user,
22
- 'X-SP-USER-IP' => options['ip_address']
23
- }
24
- @base_url = base_url
25
- # RestClient.log = 'stdout'
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
- if client_id and !client_secret
40
- @headers['X-SP-GATEWAY'] = '%s|%s' % [client_id, @options['client_secret']]
41
- elsif client_id and client_secret
42
- @headers['X-SP-GATEWAY'] = '%s|%s' % [client_id, client_secret]
43
- elsif !client_id and client_secret
44
- @headers['X-SP-GATEWAY'] = '%s|%s' % [@options['client_id'], client_secret]
45
- end
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
- if ip_address
48
- @headers['X-SP-USER-IP'] = ip_address
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
- end
51
-
52
+
52
53
 
53
- def post(path, payload)
54
- url = base_url + path
55
- response = begin
56
- RestClient.post(url,
57
- payload.to_json,
58
- @headers)
59
- rescue Exception => e
60
- return JSON.parse(e.response)
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
- def patch(path, payload)
66
- url = base_url + path
67
- response = begin
68
- RestClient.patch(url,
69
- payload.to_json,
70
- @headers)
71
- rescue Exception => e
72
- return JSON.parse(e.response)
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
- def get(path)
78
- url = base_url + path
79
- response = begin
80
- RestClient.get(url,
81
- @headers)
82
- rescue Exception => e
83
- return JSON.parse(e.response)
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
- def delete(path)
89
- url = base_url + path
90
- response = begin
91
- RestClient.delete(url,
92
- @headers)
93
- rescue Exception => e
94
- return JSON.parse(e.response)
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.b
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: 1.3.1
55
+ version: '0'
56
56
  requirements: []
57
57
  rubyforge_project:
58
58
  rubygems_version: 2.4.6