synapse_pay_rest 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 071c6f7e6a338e250519b07f2bf1f73e04899f06
4
+ data.tar.gz: 79fbf028a17974878ab53c99c856c19beb4d5c75
5
+ SHA512:
6
+ metadata.gz: 8b21462157bfb5084db7c6eada8110aea205faa64bcb65b481d5eca16709a1e3543f9e5d03214e14d1e7a9c81184a7b77b5697d9e46a942e0f03212f5856b41f
7
+ data.tar.gz: b06be2d6d1bcf1c01d10b2eda43952a0675be9c5cc6235316dfd575b66e3f46fa8f38f28b2554dd3f65958ce79e5b290a0d89571ee1dfc966522f4a0173f6abb
@@ -0,0 +1,28 @@
1
+ # Basic wrapper around the the requests library.
2
+ require_relative "synapse_pay_rest/http_client"
3
+ # Assign all the api classes
4
+ require_relative "synapse_pay_rest/api/User"
5
+ require_relative "synapse_pay_rest/api/Node"
6
+ require_relative "synapse_pay_rest/api/Trans"
7
+
8
+ class SynapsePayClient
9
+
10
+ attr_accessor :client
11
+ attr_accessor :user
12
+ attr_accessor :node
13
+ attr_accessor :trans
14
+
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'
20
+ end
21
+ end
22
+
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
27
+ end
28
+ end
@@ -0,0 +1,53 @@
1
+ class Node
2
+
3
+ attr_accessor :client
4
+
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
13
+ end
14
+ return path
15
+ end
16
+
17
+ def add(payload: )
18
+ path = create_node_path()
19
+ response = @client.post(path, payload)
20
+ return response
21
+ end
22
+
23
+ def get(node_id: nil, page: nil)
24
+ if node_id
25
+ path = create_node_path(node_id: node_id)
26
+ else
27
+ path = create_node_path()
28
+ end
29
+ if page
30
+ path += '?page=%s' %page
31
+ end
32
+ response = @client.get(path)
33
+ return response
34
+ end
35
+
36
+ def verify(node_id: nil, payload: )
37
+ if node_id
38
+ 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)
44
+ return response
45
+ end
46
+ 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
+ end
@@ -0,0 +1,49 @@
1
+ class Trans
2
+
3
+ attr_accessor :client
4
+
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
13
+ end
14
+ return path
15
+ end
16
+
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
22
+
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
28
+
29
+ def get(node_id: , trans_id: nil, page: nil)
30
+ if trans_id
31
+ path = create_transaction_path(node_id: node_id, trans_id: trans_id)
32
+ response = @client.get(path)
33
+ return response
34
+ else
35
+ path = create_transaction_path(node_id: node_id)
36
+ if page
37
+ path += '?page=%d' %page
38
+ end
39
+ response = @client.get(path)
40
+ return response
41
+ end
42
+ end
43
+
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
48
+ end
49
+ end
@@ -0,0 +1,98 @@
1
+ require 'mime-types'
2
+ require 'base64'
3
+ # require './helper'
4
+
5
+ class User
6
+
7
+ attr_accessor :client
8
+
9
+ def initialize(client)
10
+ @client = client
11
+ end
12
+
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
19
+ end
20
+
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'])
26
+ end
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()
54
+ end
55
+ response = @client.get(path)
56
+ return response
57
+ end
58
+
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
64
+
65
+ def create(payload: )
66
+ path = create_user_path()
67
+ response = @client.post(path, payload)
68
+ return response
69
+ end
70
+
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
76
+
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
82
+
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
+ }
94
+ }
95
+ response = @client.patch(path, payload)
96
+ return response
97
+ end
98
+ end
@@ -0,0 +1,98 @@
1
+ require 'rest-client'
2
+
3
+ class HTTPClient
4
+
5
+ attr_accessor :base_url
6
+ attr_accessor :options
7
+ attr_accessor :headers
8
+ attr_accessor :user_id
9
+
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
31
+ @user_id = user_id
32
+ 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
+
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
46
+
47
+ if ip_address
48
+ @headers['X-SP-USER-IP'] = ip_address
49
+ end
50
+ end
51
+
52
+
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)
61
+ end
62
+ return JSON.parse(response)
63
+ end
64
+
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)
73
+ end
74
+ return JSON.parse(response)
75
+ end
76
+
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)
84
+ end
85
+ return JSON.parse(response)
86
+ end
87
+
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)
95
+ end
96
+ return JSON.parse(response)
97
+ end
98
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: synapse_pay_rest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Hipps
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple ruby wrapper for the SynapsePay v3 Rest API
14
+ email: thomas@synapsepay.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/synapse_pay_rest.rb
20
+ - lib/synapse_pay_rest/api/Node.rb
21
+ - lib/synapse_pay_rest/api/Trans.rb
22
+ - lib/synapse_pay_rest/api/User.rb
23
+ - lib/synapse_pay_rest/http_client.rb
24
+ homepage: http://rubygems.org/gems/synapse_pay
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.4.6
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: SynapsePay v3 Rest API Wrapper
48
+ test_files: []