comgate_ruby 0.8.3 → 0.8.3.5
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 +4 -4
- data/CHANGELOG.md +7 -1
- data/Gemfile.lock +1 -1
- data/README.md +4 -0
- data/lib/comgate/api_caller.rb +30 -2
- data/lib/comgate/gateway.rb +20 -3
- data/lib/comgate/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f974dd47d4d868539ed68baa2dd30b2d1d1539662efbc65d0cba6cac02d70763
|
4
|
+
data.tar.gz: f7f156db914822d28e05bf9805d496519782c29d3676f8c1d0cfa0d39f616f2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec831f7322aba06e135929d991a25a9d3f69a80b3f4a2fe0d00ce10baceff8036705e0597c0ffde7b6af1cc0c7ca8f0e79f501a2997274f52ccb74f816536442
|
7
|
+
data.tar.gz: 74e759684ba0bfb42281b00849facf0527c69e79dcd55fedf146f8f632f273ba552505f09fd87965eb0f1bd07c42a46050d9da2eff9423d4142f11e8ddc77f12
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
+
## [0.8.3.5] - 2023-08-10
|
2
|
+
- added `gateway.download_zipped_csvs_of_transfers(date: time_as_date, output_file_path: path_to_download)` (to get transfer fees :-) )
|
3
|
+
|
4
|
+
## [0.8.3.1] - 2023-06-28
|
5
|
+
- fixed internal passing errors
|
6
|
+
|
1
7
|
## [0.8.3] - 2023-06-27
|
2
|
-
- If response from Comgate API is error, but
|
8
|
+
- If response from Comgate API is error, but contain "transId", we do not raise exception but pass info up to stack
|
3
9
|
|
4
10
|
## [0.8.2] - 2023-06-20
|
5
11
|
- If ENV["COMGATE_MIN_LOG_LEVEL"] is set, calls and responses to Comgate are logged at that level. Otherwise `:debug` is used.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -117,6 +117,10 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
117
117
|
variable_symbol: "12345678"}
|
118
118
|
]
|
119
119
|
```
|
120
|
+
### Get zip file containing CSV files with transfers of day (much richer data then previous)
|
121
|
+
1) Call `gateway.download_zipped_csvs_of_transfers(date: time_as_date, output_file_path: path_to_download)`.
|
122
|
+
2) Unzip (at your own) file at `:path_to_download`. There can be several CSV files.
|
123
|
+
Example file can be found at `./test/fixtures/csvs.zip`.
|
120
124
|
|
121
125
|
## Parameters
|
122
126
|
Structure of parameters is unchanged across most of methods, but you can leave out unused keys. You will get error if You do not pass required key.
|
data/lib/comgate/api_caller.rb
CHANGED
@@ -37,8 +37,20 @@ module Comgate
|
|
37
37
|
|
38
38
|
attr_accessor :response
|
39
39
|
|
40
|
+
HttpResponseStubStruct = Struct.new(:code, :body, :uri, :headers, keyword_init: true) do
|
41
|
+
def [](key)
|
42
|
+
headers[key]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
40
46
|
def call_api
|
41
47
|
self.response = https_conn.request(request)
|
48
|
+
# body =""
|
49
|
+
# binding.pry
|
50
|
+
# self.response = HttpResponseStubStruct.new(code: "200",
|
51
|
+
# body: body,
|
52
|
+
# uri: URI.parse("example.com"),
|
53
|
+
# headers: { "content-type" => "application/x-www-form-urlencoded; charset=UTF-8" })
|
42
54
|
rescue *KNOWN_CONNECTION_ERRORS => e
|
43
55
|
handle_connection_error(e)
|
44
56
|
end
|
@@ -111,6 +123,8 @@ module Comgate
|
|
111
123
|
when 302
|
112
124
|
response_location
|
113
125
|
when 200
|
126
|
+
return nil if response_content_type == :zip
|
127
|
+
|
114
128
|
decoded_response_body.is_a?(Hash) ? decoded_response_body["redirect"] : nil
|
115
129
|
end
|
116
130
|
end
|
@@ -124,8 +138,10 @@ module Comgate
|
|
124
138
|
|
125
139
|
msg = [result[:response_body]["message"], result[:response_body]["extraMessage"]].compact.join(" ")
|
126
140
|
errors[:api] = ["[Error ##{result[:response_body]["error"]}] #{msg}"]
|
127
|
-
@result[:errors] = { api:
|
128
|
-
|
141
|
+
@result[:errors] = { api: [
|
142
|
+
{ code: result[:response_body]["error"].to_i,
|
143
|
+
message: msg }
|
144
|
+
] }
|
129
145
|
end
|
130
146
|
|
131
147
|
def api_error?
|
@@ -159,6 +175,8 @@ module Comgate
|
|
159
175
|
URI.decode_www_form(response.body).to_h
|
160
176
|
when :json
|
161
177
|
JSON.parse(response.body)
|
178
|
+
when :zip
|
179
|
+
{ file: store_as_tmp_file(response.body, "zipfile.zip") }
|
162
180
|
end
|
163
181
|
end
|
164
182
|
|
@@ -195,9 +213,19 @@ module Comgate
|
|
195
213
|
:json
|
196
214
|
elsif rct.include?("form-urlencoded")
|
197
215
|
:url_encoded
|
216
|
+
elsif rct.include?("zip")
|
217
|
+
:zip
|
198
218
|
else
|
199
219
|
raise "Uncaptured content type: '#{rct}'"
|
200
220
|
end
|
201
221
|
end
|
222
|
+
|
223
|
+
def store_as_tmp_file(body, filename = "comgate")
|
224
|
+
file = Tempfile.new(filename)
|
225
|
+
file.binmode
|
226
|
+
file.write(body)
|
227
|
+
file.rewind
|
228
|
+
file
|
229
|
+
end
|
202
230
|
end
|
203
231
|
end
|
data/lib/comgate/gateway.rb
CHANGED
@@ -171,6 +171,22 @@ module Comgate
|
|
171
171
|
test_call: false)
|
172
172
|
end
|
173
173
|
|
174
|
+
def download_zipped_csvs_of_transfers(date:, output_file_path:)
|
175
|
+
date_str = date.strftime("%Y-%m-%d")
|
176
|
+
|
177
|
+
resp = make_call(url: "#{BASE_URL}/csvDownload",
|
178
|
+
payload: gateway_params.merge({ date: date_str }),
|
179
|
+
test_call: false)
|
180
|
+
|
181
|
+
tmp_file = resp.hash[:file]
|
182
|
+
File.write(output_file_path, tmp_file.read)
|
183
|
+
tmp_file.close
|
184
|
+
tmp_file.unlink
|
185
|
+
|
186
|
+
resp.hash = { file_path: output_file_path }
|
187
|
+
resp
|
188
|
+
end
|
189
|
+
|
174
190
|
private
|
175
191
|
|
176
192
|
attr_reader :payment_data
|
@@ -179,10 +195,11 @@ module Comgate
|
|
179
195
|
raise "There are errors in pre-api-call phase: #{payload[:errors]}" unless payload[:errors].nil?
|
180
196
|
|
181
197
|
srv = Comgate::ApiCaller.call(url: url, payload: payload, test_call: test_call, proxy_uri: proxy_uri)
|
198
|
+
|
182
199
|
if srv.success?
|
183
200
|
Comgate::Response.new(srv.result, conversion_hash)
|
184
201
|
else
|
185
|
-
handle_failure_from(srv)
|
202
|
+
handle_failure_from(srv, conversion_hash)
|
186
203
|
end
|
187
204
|
end
|
188
205
|
|
@@ -190,8 +207,8 @@ module Comgate
|
|
190
207
|
test_from_data.nil? ? test_calls_used? : (test_from_data == true)
|
191
208
|
end
|
192
209
|
|
193
|
-
def handle_failure_from(srv)
|
194
|
-
raise srv.errors.to_s
|
210
|
+
def handle_failure_from(srv, conversion_hash)
|
211
|
+
raise srv.errors.to_s if srv.result.dig(:response_body, "transId").nil?
|
195
212
|
|
196
213
|
# pretends to be a successfull response, and keep payment check to decide what to do next
|
197
214
|
Comgate::Response.new(srv.result, conversion_hash)
|
data/lib/comgate/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: comgate_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.3
|
4
|
+
version: 0.8.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Petr Mlčoch
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Write a longer description or delete this line.
|
14
14
|
email:
|