kapellmeister 0.7.0 → 0.7.3
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/lib/kapellmeister/dispatcher.rb +24 -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: c63a59e324e6fd25a43b163b8db3a826b617cff0101f4cb001f1825f7fc9fc06
|
4
|
+
data.tar.gz: 38a102e6272a99813bf78181e7aa7aded4e3ab22864059c3582f0297d0263884
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d05effbadfaba1923440b05ca4875d501a5fe281899b34c0c6fea5998e260159286d72f17800cea730b36fdff72c80409f3ce6d6059a504de6fb0fa92b990ddf
|
7
|
+
data.tar.gz: 2be64d2e49d7f78b51075a6477020bad5441f8edeb20e5ecc0ccdab8bf5cc9ee8978b11cf01efb6d0945e89db40cc39f828ff678b65424e27744abf3326d0794
|
@@ -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
|
@@ -33,12 +37,15 @@ class Kapellmeister::Dispatcher
|
|
33
37
|
def connection_by(method_name, path, data = {})
|
34
38
|
additional_headers = data.delete(:headers) || {}
|
35
39
|
requests_data = data.delete(:request) || {}
|
40
|
+
data_json = data.blank? ? '' : data.to_json
|
36
41
|
|
37
42
|
generated_connection = connection(additional_headers: additional_headers, requests_data: requests_data) # rubocop:disable Style/HashSyntax (for support ruby 2.4+)
|
38
43
|
|
39
|
-
process generated_connection.run_request(method_name.downcase.to_sym,
|
40
|
-
|
41
|
-
|
44
|
+
process generated_connection.run_request(method_name.downcase.to_sym,
|
45
|
+
url_with_params(path),
|
46
|
+
data_json,
|
47
|
+
additional_headers)
|
48
|
+
|
42
49
|
rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e
|
43
50
|
failed_response(details: e.message)
|
44
51
|
end
|
@@ -51,6 +58,7 @@ class Kapellmeister::Dispatcher
|
|
51
58
|
faraday.request :multipart
|
52
59
|
faraday.response :logger, logger
|
53
60
|
faraday.response :json, content_type: 'application/json; charset=utf-8'
|
61
|
+
faraday.use FaradayMiddleware::FollowRedirects, limit: 5
|
54
62
|
faraday.adapter :typhoeus do |http|
|
55
63
|
http.timeout = 20
|
56
64
|
end
|
@@ -72,10 +80,23 @@ class Kapellmeister::Dispatcher
|
|
72
80
|
}
|
73
81
|
end
|
74
82
|
|
83
|
+
def path_generate(path)
|
84
|
+
path.query_parameters
|
85
|
+
end
|
86
|
+
|
75
87
|
def process(data)
|
76
88
|
report(data).result
|
77
89
|
end
|
78
90
|
|
91
|
+
def url_with_params(url)
|
92
|
+
return url if query_params.blank?
|
93
|
+
|
94
|
+
uri = URI(url)
|
95
|
+
params = URI.decode_www_form(uri.query || '').to_h.merge(query_params)
|
96
|
+
uri.query = URI.encode_www_form(params)
|
97
|
+
uri.to_s
|
98
|
+
end
|
99
|
+
|
79
100
|
def failed_response(**args)
|
80
101
|
FailedResponse.new(false, { message: "#{self.class} no connection" }, { status: 555, **args })
|
81
102
|
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.3
|
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-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-schema
|