kapellmeister 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kapellmeister/dispatcher.rb +21 -3
- data/lib/kapellmeister/requests_extension.rb +7 -4
- data/lib/kapellmeister/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: 03e830a5335e55d2acd0db7d93e54bf12e657fc0cf21cc9c5676cf90a0cddc80
|
4
|
+
data.tar.gz: db3fc0c80480c15e84e6a40e019b569d7a7dc1645d1eaed8a28b73ccaf8b87a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c79f2c5b731932fa74af03a1ddf08f89ed089d09104cac257d6720c9cdcccb0689ead099cf4a9a32b83b7c323434387a463b9cd9ea7a26615f7812d6bb8c6281
|
7
|
+
data.tar.gz: 69b47a4b15b8075a772273dc99a2a41e710859db437714b3a4e8e5963b79dacd6a7b69f59ee676e78e55c4e9e8267a774ec76093c0c593c0ce5bcc084e2697b8
|
@@ -24,6 +24,10 @@ class Kapellmeister::Dispatcher
|
|
24
24
|
{}
|
25
25
|
end
|
26
26
|
|
27
|
+
def query_params
|
28
|
+
{}
|
29
|
+
end
|
30
|
+
|
27
31
|
def configuration
|
28
32
|
self.class.module_parent.configuration
|
29
33
|
end
|
@@ -37,10 +41,11 @@ class Kapellmeister::Dispatcher
|
|
37
41
|
|
38
42
|
generated_connection = connection(additional_headers: additional_headers, requests_data: requests_data) # rubocop:disable Style/HashSyntax (for support ruby 2.4+)
|
39
43
|
|
40
|
-
process generated_connection.run_request(method_name.downcase.to_sym,
|
44
|
+
process generated_connection.run_request(method_name.downcase.to_sym,
|
45
|
+
url_with_params(path),
|
46
|
+
data_json,
|
47
|
+
additional_headers)
|
41
48
|
|
42
|
-
rescue NameError, RuntimeError
|
43
|
-
raise "Library can't process method #{method_name} yet"
|
44
49
|
rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e
|
45
50
|
failed_response(details: e.message)
|
46
51
|
end
|
@@ -74,10 +79,23 @@ class Kapellmeister::Dispatcher
|
|
74
79
|
}
|
75
80
|
end
|
76
81
|
|
82
|
+
def path_generate(path)
|
83
|
+
path.query_parameters
|
84
|
+
end
|
85
|
+
|
77
86
|
def process(data)
|
78
87
|
report(data).result
|
79
88
|
end
|
80
89
|
|
90
|
+
def url_with_params(url)
|
91
|
+
return url if query_params.blank?
|
92
|
+
|
93
|
+
uri = URI(url)
|
94
|
+
params = URI.decode_www_form(uri.query || '').to_h.merge(query_params)
|
95
|
+
uri.query = URI.encode_www_form(params)
|
96
|
+
uri.to_s
|
97
|
+
end
|
98
|
+
|
81
99
|
def failed_response(**args)
|
82
100
|
FailedResponse.new(false, { message: "#{self.class} no connection" }, { status: 555, **args })
|
83
101
|
end
|
@@ -3,7 +3,9 @@ module Kapellmeister::RequestsExtension
|
|
3
3
|
proc do |name, request_data|
|
4
4
|
define_method name do |data = {}|
|
5
5
|
proc { |method:, path:, body: {}, query_params: {}, mock: ''|
|
6
|
-
|
6
|
+
if (Rails.try(:env) || ENV.fetch('APP_ENV', nil)) == 'test'
|
7
|
+
return ::Kapellmeister::Base.routes_scheme_parse(mock)
|
8
|
+
end
|
7
9
|
|
8
10
|
valid_body?(data, body)
|
9
11
|
valid_query?(data, query_params)
|
@@ -36,7 +38,7 @@ def valid_body?(data, body)
|
|
36
38
|
return if body.blank? || body.is_a?(Hash)
|
37
39
|
|
38
40
|
schema = Object.const_get(body).schema
|
39
|
-
result = schema.(data)
|
41
|
+
result = schema.call(data)
|
40
42
|
return data if result.success?
|
41
43
|
|
42
44
|
raise ArgumentError, result.errors.to_h
|
@@ -44,6 +46,7 @@ end
|
|
44
46
|
|
45
47
|
def valid_query?(data, query)
|
46
48
|
return if query.blank?
|
49
|
+
|
47
50
|
required_keys = query.keys
|
48
51
|
|
49
52
|
from_data = data.slice(*required_keys)
|
@@ -51,8 +54,8 @@ def valid_query?(data, query)
|
|
51
54
|
data[:query_params] ||= {}
|
52
55
|
data[:query_params] = data[:query_params].to_h.merge!(from_data)
|
53
56
|
|
54
|
-
|
55
|
-
return if required_keys.all? { |key|
|
57
|
+
different_keys = data[:query_params].transform_keys(&:to_sym)
|
58
|
+
return if required_keys.all? { |key| different_keys.key? key.to_sym }
|
56
59
|
|
57
60
|
raise ArgumentError, "Query params needs keys #{required_keys}"
|
58
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kapellmeister
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DarkWater
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-schema
|