sep6_client 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 585b0211026abc26214470978dd4c60d368680509f70cf6050771d78881667b7
4
+ data.tar.gz: 54f0ed9d094d44a8cc8303d4c7b45cf641caf210cea588e9883b9e38b0e17cca
5
+ SHA512:
6
+ metadata.gz: 5f48d6b6c33b0419421445cbcef951dff4c343061a8d8bc2400503608b4a360fbaaa2638d9556a0c7f4fa0980ffcafc6a25f15917f6ae044dc2049e401ca9eb7
7
+ data.tar.gz: dee4f7127e6b042b7c99a25cbd48782e1bfd249b046b71b453192998a87e2acd9c0707b8ffe23975d7c455061da69f2a1c66885235e47db0af876250cfadc41d
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify dependencies in sep6-client.gemspec
4
+ gemspec
@@ -0,0 +1,163 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require 'time'
4
+ require 'sep6_client/config'
5
+ require 'uri'
6
+ require 'openssl'
7
+
8
+ # Ruby implementation of a REST client for the COINQVEST Merchant API
9
+ # see https://www.coinqvest.com/en/api-docs
10
+ module Sep6Client
11
+
12
+ class Client
13
+
14
+ # Initializes the Sep-6 Client
15
+ # @param transfer_server; the SEP-6 transfer server
16
+ # @param log_file; optional log file path
17
+ # @constructor
18
+ def initialize(transfer_server = nil, log_file = nil)
19
+
20
+ # @string Used in the HTTP user agent (leave it as is)
21
+ @client_name = Sep6Client::CLIENT_NAME
22
+
23
+ # @string The current version of this SDK, used in the HTTP user agent (leave it as is)
24
+ @client_version = Sep6Client::CLIENT_VERSION
25
+
26
+ # @string COINQVEST connect url
27
+ @transfer_server = transfer_server ? transfer_server : Sep6Client::TRANSFER_SERVER
28
+
29
+ # @string|nil Specifies the log file to which to write, if any.
30
+ @log_file = log_file ? log_file : nil
31
+
32
+ end
33
+
34
+ # Use this method to communicate with GET endpoints
35
+ # @param endpoint (string), e.g. GET /customer
36
+ # @param params (hash), a list of GET parameters to be included in the request
37
+ # @return RestClient::Response, https://github.com/rest-client/rest-client/blob/2c72a2e77e2e87d25ff38feba0cf048d51bd5eca/lib/restclient/response.rb
38
+ def get(endpoint, params = {})
39
+
40
+ path = build_connect_url(endpoint) + '?' + URI.encode_www_form(params)
41
+ headers = build_headers(endpoint, 'GET', params)
42
+
43
+ log "GET " + path
44
+ log headers.to_s
45
+
46
+ begin
47
+ response = RestClient::Request.execute(method: :get, url: path, headers: headers, timeout: 180)
48
+ rescue RestClient::ExceptionWithResponse => e
49
+ log e.http_code.to_s + " " + e.response.to_s
50
+ return e.response
51
+ end
52
+
53
+ log response.code.to_s + " " + response.to_s
54
+
55
+ response
56
+
57
+ end
58
+
59
+ # Use this method to communicate with POST endpoints
60
+ # @param endpoint (string), e.g. POST /checkout/hosted
61
+ # @param params (hash), a list of GET parameters to be included in the request
62
+ # @return RestClient::Response, https://github.com/rest-client/rest-client/blob/2c72a2e77e2e87d25ff38feba0cf048d51bd5eca/lib/restclient/response.rb
63
+ def post(endpoint, params = {})
64
+
65
+ path = build_connect_url(endpoint)
66
+ headers = build_headers(endpoint, 'POST', params)
67
+
68
+ log "POST " + path + " " + params.to_s
69
+ log headers.to_s
70
+
71
+ begin
72
+ response = RestClient::Request.execute(method: :post, url: path, payload: params.to_json, headers: headers, timeout: 180)
73
+ rescue RestClient::ExceptionWithResponse => e
74
+ log e.http_code.to_s + " " + e.response.to_s
75
+ return e.response
76
+ end
77
+
78
+ log response.code.to_s + " " + response.to_s
79
+
80
+ response
81
+
82
+ end
83
+
84
+ # Use this method to communicate with PUT endpoints
85
+ # @param endpoint (string), e.g. PUT /customer
86
+ # @param params (hash), a list of GET parameters to be included in the request
87
+ # @return RestClient::Response, https://github.com/rest-client/rest-client/blob/2c72a2e77e2e87d25ff38feba0cf048d51bd5eca/lib/restclient/response.rb
88
+ def put(endpoint, params = {})
89
+
90
+ path = build_connect_url(endpoint)
91
+ headers = build_headers(endpoint, 'PUT', params)
92
+
93
+ log "PUT " + path + " " + params.to_s
94
+ log headers.to_s
95
+
96
+ begin
97
+ response = RestClient::Request.execute(method: :put, url: path, payload: params.to_json, headers: headers, timeout: 180)
98
+ rescue RestClient::ExceptionWithResponse => e
99
+ log e.http_code.to_s + " " + e.response.to_s
100
+ return e.response
101
+ end
102
+
103
+ log response.code.to_s + " " + response.to_s
104
+
105
+ response
106
+
107
+ end
108
+
109
+ # Use this method to communicate with PUT endpoints
110
+ # @param endpoint (string), e.g. PUT /customer
111
+ # @param params (hash), a list of GET parameters to be included in the request
112
+ # @return RestClient::Response, https://github.com/rest-client/rest-client/blob/2c72a2e77e2e87d25ff38feba0cf048d51bd5eca/lib/restclient/response.rb
113
+ def delete(endpoint, params = {})
114
+
115
+ path = build_connect_url(endpoint)
116
+ headers = build_headers(endpoint, 'DELETE', params)
117
+
118
+ log "DELETE " + path + " " + params.to_s
119
+ log headers.to_s
120
+
121
+ begin
122
+ response = RestClient::Request.execute(method: :delete, url: path, payload: params.to_json, headers: headers, timeout: 180)
123
+ rescue RestClient::ExceptionWithResponse => e
124
+ log e.http_code.to_s + " " + e.response.to_s
125
+ return e.response
126
+ end
127
+
128
+ log response.code.to_s + " " + response.to_s
129
+
130
+ response
131
+
132
+ end
133
+
134
+ # private class to generate connect url on COINQVEST servers
135
+ private
136
+ def build_connect_url(endpoint)
137
+ "https://" + @transfer_server + endpoint
138
+ end
139
+
140
+ # private class to generate authentication headers
141
+ private
142
+ def build_headers(endpoint, method, params)
143
+ {
144
+ :"User-Agent" => @client_name + " " + @client_version
145
+ }
146
+ end
147
+
148
+
149
+ private
150
+ def log(text)
151
+
152
+ if @log_file == nil
153
+ return
154
+ end
155
+
156
+ File.open(@log_file, 'a') { |f| f.write(Time.now.utc.rfc822 + " [CoinqvestMerchantSDK] " + text + "\n") }
157
+ # print Time.now.utc.rfc822 + " [CoinqvestMerchantSDK] " + text + "\n"
158
+
159
+ end
160
+
161
+ end
162
+
163
+ end
@@ -0,0 +1,9 @@
1
+ module Sep6Client
2
+
3
+ CLIENT_VERSION = '0.0.2'
4
+
5
+ CLIENT_NAME = 'sep6_client'
6
+
7
+ TRANSFER_SERVER = 'sep6.coinqvest.com'
8
+
9
+ end
@@ -0,0 +1,3 @@
1
+ module Sep6Client
2
+ # Your code goes here...
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'sep6_client/config'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'sep6_client'
7
+ s.version = Sep6Client::CLIENT_VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['COINQVEST LLC']
10
+ s.email = ['service@coinqvest.com']
11
+ s.homepage = 'https://www.coinqvest.com'
12
+ s.summary = %q{Ruby based Stellar SEP-6 Client by COINQVEST}
13
+ s.licenses = ['Apache-2.0']
14
+ s.required_ruby_version = '>= 2.0.0'
15
+
16
+ s.add_runtime_dependency 'rest-client', '~> 2.1', '>= 2.1.0'
17
+ s.add_runtime_dependency 'json', '~> 2.3', '>= 2.3.0'
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ['lib']
23
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sep6_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - COINQVEST LLC
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-10-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.1.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.1.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: json
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.3'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 2.3.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '2.3'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.3.0
53
+ description:
54
+ email:
55
+ - service@coinqvest.com
56
+ executables: []
57
+ extensions: []
58
+ extra_rdoc_files: []
59
+ files:
60
+ - ".gitignore"
61
+ - Gemfile
62
+ - lib/sep6_client.rb
63
+ - lib/sep6_client/client.rb
64
+ - lib/sep6_client/config.rb
65
+ - sep6_client.gemspec
66
+ homepage: https://www.coinqvest.com
67
+ licenses:
68
+ - Apache-2.0
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 2.0.0
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubygems_version: 3.3.11
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Ruby based Stellar SEP-6 Client by COINQVEST
89
+ test_files: []