whalestack_sdk 1.0.0

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
+ SHA256:
3
+ metadata.gz: 39a9edcd754a06acfaa517bca1ab842f45c4de90bc3b24ffd209f1b0c290c3a3
4
+ data.tar.gz: d855b3652542a288ece87335d85b00d7b028dfac85abe7a47dfeeaf86b890339
5
+ SHA512:
6
+ metadata.gz: 05ae3d879275ebff8a772266372609bbcb320201772ca11244dc96583687e825cdcf25d9493d5c54d5655f51a39aeb3979b0d652725340fc96860d79ec530db0
7
+ data.tar.gz: 8b2eea8419491598926ebb4d3ffa9656bd500806be1845bd50783441f7454b61a5e44aade20027e1920bd366167a4e377197495edcafbaae589a8b2831d0ab80
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 whalestack_sdk.gemspec
4
+ gemspec
@@ -0,0 +1,184 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require 'time'
4
+ require 'whalestack_sdk/config'
5
+ require 'uri'
6
+ require 'openssl'
7
+
8
+ # Ruby implementation of a REST client for the Whalestack Payments API
9
+ # see https://www.whalestack.com/en/api-docs
10
+ module WhalestackSDK
11
+
12
+ class Client
13
+
14
+ # Merchant API client constructor, initialize this with the API key and secret as given by https://www.whalestack.com/en/api-settings
15
+ # @param key; as given by https://www.whalestack.com/en/api-settings
16
+ # @param secret; as given by https://www.whalestack.com/en/api-settings
17
+ # @param log_file; optional log file path
18
+ # @constructor
19
+ def initialize(key, secret, log_file = nil)
20
+
21
+ # @string The API Key as given by https://www.whalestack.com/en/api-settings
22
+ @key = key
23
+
24
+ # @string The API Secret as given by https://www.whalestack.com/en/api-settings
25
+ @secret = secret
26
+
27
+ # @string The API version to which we connect (leave it as is)
28
+ @api_version = WhalestackSDK::API_VERSION
29
+
30
+ # @string Used in the HTTP user agent (leave it as is)
31
+ @client_name = WhalestackSDK::CLIENT_NAME
32
+
33
+ # @string The current version of this SDK, used in the HTTP user agent (leave it as is)
34
+ @client_version = WhalestackSDK::CLIENT_VERSION
35
+
36
+ # @string Whalestack connect url
37
+ @connect_url = WhalestackSDK::CONNECT_URL
38
+
39
+ # @string|nil Specifies the log file to which to write, if any.
40
+ @log_file = log_file ? log_file : nil
41
+
42
+ end
43
+
44
+ # Use this method to communicate with GET endpoints
45
+ # @param endpoint (string), e.g. GET /customer
46
+ # @param params (hash), a list of GET parameters to be included in the request
47
+ # @return RestClient::Response, https://github.com/rest-client/rest-client/blob/2c72a2e77e2e87d25ff38feba0cf048d51bd5eca/lib/restclient/response.rb
48
+ def get(endpoint, params = {})
49
+
50
+ path = build_connect_url(endpoint) + '?' + URI.encode_www_form(params)
51
+ headers = build_headers(endpoint, 'GET', params)
52
+
53
+ log "GET " + path
54
+ log headers.to_s
55
+
56
+ begin
57
+ response = RestClient::Request.execute(method: :get, url: path, headers: headers, timeout: 180)
58
+ rescue RestClient::ExceptionWithResponse => e
59
+ log e.http_code.to_s + " " + e.response.to_s
60
+ return e.response
61
+ end
62
+
63
+ log response.code.to_s + " " + response.to_s
64
+
65
+ response
66
+
67
+ end
68
+
69
+ # Use this method to communicate with POST endpoints
70
+ # @param endpoint (string), e.g. POST /checkout/hosted
71
+ # @param params (hash), a list of GET parameters to be included in the request
72
+ # @return RestClient::Response, https://github.com/rest-client/rest-client/blob/2c72a2e77e2e87d25ff38feba0cf048d51bd5eca/lib/restclient/response.rb
73
+ def post(endpoint, params = {})
74
+
75
+ path = build_connect_url(endpoint)
76
+ headers = build_headers(endpoint, 'POST', params)
77
+
78
+ log "POST " + path + " " + params.to_s
79
+ log headers.to_s
80
+
81
+ begin
82
+ response = RestClient::Request.execute(method: :post, url: path, payload: params.to_json, headers: headers, timeout: 180)
83
+ rescue RestClient::ExceptionWithResponse => e
84
+ log e.http_code.to_s + " " + e.response.to_s
85
+ return e.response
86
+ end
87
+
88
+ log response.code.to_s + " " + response.to_s
89
+
90
+ response
91
+
92
+ end
93
+
94
+ # Use this method to communicate with PUT endpoints
95
+ # @param endpoint (string), e.g. PUT /customer
96
+ # @param params (hash), a list of GET parameters to be included in the request
97
+ # @return RestClient::Response, https://github.com/rest-client/rest-client/blob/2c72a2e77e2e87d25ff38feba0cf048d51bd5eca/lib/restclient/response.rb
98
+ def put(endpoint, params = {})
99
+
100
+ path = build_connect_url(endpoint)
101
+ headers = build_headers(endpoint, 'PUT', params)
102
+
103
+ log "PUT " + path + " " + params.to_s
104
+ log headers.to_s
105
+
106
+ begin
107
+ response = RestClient::Request.execute(method: :put, url: path, payload: params.to_json, headers: headers, timeout: 180)
108
+ rescue RestClient::ExceptionWithResponse => e
109
+ log e.http_code.to_s + " " + e.response.to_s
110
+ return e.response
111
+ end
112
+
113
+ log response.code.to_s + " " + response.to_s
114
+
115
+ response
116
+
117
+ end
118
+
119
+ # Use this method to communicate with PUT endpoints
120
+ # @param endpoint (string), e.g. PUT /customer
121
+ # @param params (hash), a list of GET parameters to be included in the request
122
+ # @return RestClient::Response, https://github.com/rest-client/rest-client/blob/2c72a2e77e2e87d25ff38feba0cf048d51bd5eca/lib/restclient/response.rb
123
+ def delete(endpoint, params = {})
124
+
125
+ path = build_connect_url(endpoint)
126
+ headers = build_headers(endpoint, 'DELETE', params)
127
+
128
+ log "DELETE " + path + " " + params.to_s
129
+ log headers.to_s
130
+
131
+ begin
132
+ response = RestClient::Request.execute(method: :delete, url: path, payload: params.to_json, headers: headers, timeout: 180)
133
+ rescue RestClient::ExceptionWithResponse => e
134
+ log e.http_code.to_s + " " + e.response.to_s
135
+ return e.response
136
+ end
137
+
138
+ log response.code.to_s + " " + response.to_s
139
+
140
+ response
141
+
142
+ end
143
+
144
+ # private class to generate connect url on Whalestack servers
145
+ private
146
+ def build_connect_url(endpoint)
147
+ @connect_url + @api_version + endpoint
148
+ end
149
+
150
+ # private class to generate authentication headers
151
+ private
152
+ def build_headers(endpoint, method, params)
153
+
154
+ timestamp = Time.now.to_i
155
+ body = nil
156
+ if method != 'GET'
157
+ body = params.length > 0 ? params.to_json : nil
158
+ end
159
+ data = endpoint + timestamp.to_s + method + body.to_s
160
+
161
+ {
162
+ :"X-Digest-Key" => @key,
163
+ :"X-Digest-Signature" => OpenSSL::HMAC.hexdigest('sha256', @secret, data),
164
+ :"X-Digest-Timestamp" => timestamp,
165
+ :"User-Agent" => @client_name + " " + @client_version
166
+ }
167
+
168
+ end
169
+
170
+
171
+ private
172
+ def log(text)
173
+
174
+ if @log_file == nil
175
+ return
176
+ end
177
+
178
+ File.open(@log_file, 'a') { |f| f.write(Time.now.utc.rfc822 + " [WhalestackSDK] " + text + "\n") }
179
+
180
+ end
181
+
182
+ end
183
+
184
+ end
@@ -0,0 +1,11 @@
1
+ module WhalestackSDK
2
+
3
+ CLIENT_VERSION = '1.0.0'
4
+
5
+ CLIENT_NAME = 'ruby_sdk'
6
+
7
+ API_VERSION = 'v1'
8
+
9
+ CONNECT_URL = 'https://www.whalestack.com/api/'
10
+
11
+ end
@@ -0,0 +1,3 @@
1
+ module WhalestackSDK
2
+ # Your code goes here...
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'whalestack_sdk/config'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'whalestack_sdk'
7
+ s.version = WhalestackSDK::CLIENT_VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Whalestack LLC']
10
+ s.email = ['service@whalestack.com']
11
+ s.homepage = 'https://www.whalestack.com'
12
+ s.summary = %q{Whalestack SDK. Programmatically accept and settle payments in digital currencies.}
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: whalestack_sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Whalestack LLC
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-10-05 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.0
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.1'
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.0
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.1'
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.0
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '2.3'
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.0
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '2.3'
53
+ description:
54
+ email:
55
+ - service@whalestack.com
56
+ executables: []
57
+ extensions: []
58
+ extra_rdoc_files: []
59
+ files:
60
+ - ".gitignore"
61
+ - Gemfile
62
+ - lib/whalestack_sdk.rb
63
+ - lib/whalestack_sdk/client.rb
64
+ - lib/whalestack_sdk/config.rb
65
+ - whalestack_sdk.gemspec
66
+ homepage: https://www.whalestack.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.0.3.1
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Whalestack SDK. Programmatically accept and settle payments in digital currencies.
89
+ test_files: []