soapy_cake 2.3.0 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/soapy_cake/client.rb +52 -26
- data/lib/soapy_cake/version.rb +1 -1
- data/spec/integration/soapy_cake/admin_spec.rb +10 -7
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 067f6e7655ca70f82bdb56092d19dcfbb0f41879077ede785b6490ee40ba0192
|
4
|
+
data.tar.gz: 945cce14ca15a79590bef7b1bef2a636288da4cfb0ba93b6d9f50482ecdc533b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc1c8bbba8cf6b41ca72aeebe6c516b7a915a8a3fb1bead22794e87c600aba8b4e6d8b7c590e0e6c700e3a327f8eb0264b3f0142d837c6b3e13be7dbbffce967
|
7
|
+
data.tar.gz: 9ecf1e1d0d996917d3b079b8e74f0bd3db0f5ea67d27d276c78cb8387572045893b01555877aaab17c09e20ce5e7ba0df6a0b8ebfea7152416597160f917b791
|
data/lib/soapy_cake/client.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'net/http'
|
4
|
+
require 'active_support/tagged_logging'
|
4
5
|
|
6
|
+
# rubocop:disable Metrics/ClassLength
|
5
7
|
module SoapyCake
|
6
8
|
class Client
|
7
9
|
HEADERS = { 'Content-Type' => 'application/soap+xml;charset=UTF-8' }.freeze
|
@@ -62,46 +64,58 @@ module SoapyCake
|
|
62
64
|
Retryable.retryable(opts, &block)
|
63
65
|
end
|
64
66
|
|
65
|
-
def
|
66
|
-
|
67
|
+
def response_body(request)
|
68
|
+
request.opts[:response].presence || http_response(request)
|
67
69
|
end
|
68
70
|
|
69
|
-
def
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
def http_response(request)
|
72
|
+
response = nil
|
73
|
+
logger.tagged('soapy_cake', unique_id) do
|
74
|
+
log_request(request)
|
75
|
+
response = perform_http_request(http_request(request))
|
76
|
+
log_response(response)
|
77
|
+
end
|
75
78
|
|
76
|
-
|
79
|
+
raise_if_unsuccessful(response)
|
80
|
+
response.body
|
77
81
|
end
|
78
82
|
|
79
|
-
def
|
80
|
-
|
83
|
+
def http_request(request)
|
84
|
+
http_req = Net::HTTP::Post.new(request.path, HEADERS)
|
85
|
+
http_req.body = request.xml
|
86
|
+
http_req
|
81
87
|
end
|
82
88
|
|
83
|
-
def
|
84
|
-
|
85
|
-
|
86
|
-
http_request = Net::HTTP::Post.new(request.path, HEADERS)
|
87
|
-
http_request.body = request.xml
|
88
|
-
t0 = Time.now
|
89
|
-
response = perform_http_request(http_request)
|
90
|
-
response_time = Time.now - t0
|
91
|
-
logger&.info("soapy_cake:request #{request} took: #{response_time.round(2)} s")
|
89
|
+
def unique_id
|
90
|
+
SecureRandom.hex(4)
|
91
|
+
end
|
92
92
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
93
|
+
def log_request(request)
|
94
|
+
logger.tagged('request') do
|
95
|
+
logger.info(
|
96
|
+
request
|
97
|
+
.xml
|
98
|
+
.gsub(/>[\n\s]+</, '><')
|
99
|
+
.sub(request.api_key, '[REDACTED]')
|
97
100
|
)
|
98
101
|
end
|
102
|
+
end
|
99
103
|
|
100
|
-
|
104
|
+
def log_response(response)
|
105
|
+
logger.tagged('response', response.code) do
|
106
|
+
logger.info(response.body)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def logger
|
111
|
+
@logger ||= ActiveSupport::TaggedLogging.new(
|
112
|
+
opts[:logger] || (defined?(::Rails) && ::Rails.logger) || Logger.new('/dev/null')
|
113
|
+
)
|
101
114
|
end
|
102
115
|
|
103
116
|
def perform_http_request(http_request)
|
104
|
-
|
117
|
+
t0 = Time.now
|
118
|
+
response = Net::HTTP.start(
|
105
119
|
domain,
|
106
120
|
use_ssl: true,
|
107
121
|
open_timeout: NET_TIMEOUT,
|
@@ -109,6 +123,18 @@ module SoapyCake
|
|
109
123
|
) do |http|
|
110
124
|
http.request(http_request)
|
111
125
|
end
|
126
|
+
logger.info("took: #{(Time.now - t0).round(2)} s")
|
127
|
+
response
|
128
|
+
end
|
129
|
+
|
130
|
+
def raise_if_unsuccessful(response)
|
131
|
+
return if response.is_a?(Net::HTTPSuccess)
|
132
|
+
|
133
|
+
raise RequestFailed.new(
|
134
|
+
"Request failed with HTTP #{response.code}",
|
135
|
+
response_body: response.body
|
136
|
+
)
|
112
137
|
end
|
113
138
|
end
|
114
139
|
end
|
140
|
+
# rubocop:enable Metrics/ClassLength
|
data/lib/soapy_cake/version.rb
CHANGED
@@ -3,18 +3,21 @@
|
|
3
3
|
RSpec.describe SoapyCake::Admin do
|
4
4
|
around { |example| Timecop.freeze(Time.utc(2015, 6, 15, 12), &example) }
|
5
5
|
|
6
|
-
let(:logger) {
|
6
|
+
let(:logger) { Logger.new('/dev/null') }
|
7
7
|
|
8
8
|
subject(:admin) { described_class.new(logger: logger) }
|
9
9
|
|
10
10
|
it 'returns an affiliate with correct data types', :vcr do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
a_string_matching(
|
15
|
-
/soapy_cake:request admin:export:affiliates:5 {"affiliate_id":16027} took: \d+.\d+ s/
|
16
|
-
)
|
11
|
+
# rubocop:disable RSpec/AnyInstance
|
12
|
+
expect_any_instance_of(Logger).to receive(:info).twice.with(
|
13
|
+
a_string_matching(/^<\?xml/)
|
17
14
|
)
|
15
|
+
expect_any_instance_of(Logger).to receive(:info).with(
|
16
|
+
a_string_matching(/took: \d+.\d+ s/)
|
17
|
+
)
|
18
|
+
# rubocop:enable RSpec/AnyInstance
|
19
|
+
|
20
|
+
result = admin.affiliates(affiliate_id: 16027)
|
18
21
|
|
19
22
|
expect(result.count).to eq(1)
|
20
23
|
expect(result.first).to include(
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soapy_cake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ad2games GmbH
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -272,7 +272,7 @@ homepage: http://ad2games.com
|
|
272
272
|
licenses:
|
273
273
|
- MIT
|
274
274
|
metadata: {}
|
275
|
-
post_install_message:
|
275
|
+
post_install_message:
|
276
276
|
rdoc_options: []
|
277
277
|
require_paths:
|
278
278
|
- lib
|
@@ -287,9 +287,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
287
287
|
- !ruby/object:Gem::Version
|
288
288
|
version: '0'
|
289
289
|
requirements: []
|
290
|
-
rubyforge_project:
|
290
|
+
rubyforge_project:
|
291
291
|
rubygems_version: 2.7.6
|
292
|
-
signing_key:
|
292
|
+
signing_key:
|
293
293
|
specification_version: 4
|
294
294
|
summary: Simple client for the CAKE API
|
295
295
|
test_files:
|