kapellmeister 0.7.1 → 0.8.0
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 +22 -3
- data/lib/kapellmeister/requests_extension.rb +15 -6
- 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: 310275b6a62ec2d0e7d669d929ba840fc0fff1e33e1df7624dd50058e6bc2019
|
4
|
+
data.tar.gz: 057a8571e02b3db203e53734002f1cf4abfd8190b28e1f21df03e9c8a54374d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b42f79eaf9e15d9e6fbba01122688f8cf81b1e45708712a714cd0e6b42e4ca9cf6a09d35e96946a28ab0e6485db499cdf2d940b9865d27019124e177efa7b5f4
|
7
|
+
data.tar.gz: d5063ebf038c9effbbdd3f9cb8e134619d584712402c47e1d48efa179d086469f6ed4ef0d753b0de89758b18783cc403abed388d849827221c3a1329cf8b4ddd
|
@@ -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
|
@@ -53,6 +58,7 @@ class Kapellmeister::Dispatcher
|
|
53
58
|
faraday.request :multipart
|
54
59
|
faraday.response :logger, logger
|
55
60
|
faraday.response :json, content_type: 'application/json; charset=utf-8'
|
61
|
+
faraday.use FaradayMiddleware::FollowRedirects, limit: 5
|
56
62
|
faraday.adapter :typhoeus do |http|
|
57
63
|
http.timeout = 20
|
58
64
|
end
|
@@ -74,10 +80,23 @@ class Kapellmeister::Dispatcher
|
|
74
80
|
}
|
75
81
|
end
|
76
82
|
|
83
|
+
def path_generate(path)
|
84
|
+
path.query_parameters
|
85
|
+
end
|
86
|
+
|
77
87
|
def process(data)
|
78
88
|
report(data).result
|
79
89
|
end
|
80
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
|
+
|
81
100
|
def failed_response(**args)
|
82
101
|
FailedResponse.new(false, { message: "#{self.class} no connection" }, { status: 555, **args })
|
83
102
|
end
|
@@ -2,9 +2,12 @@ module Kapellmeister::RequestsExtension
|
|
2
2
|
def self.request_processing
|
3
3
|
proc do |name, request_data|
|
4
4
|
define_method name do |data = {}|
|
5
|
-
proc { |method:, path
|
6
|
-
|
5
|
+
proc { |method:, path: nil, body: {}, query_params: {}, mock: ''|
|
6
|
+
if (Rails.try(:env) || ENV.fetch('APP_ENV', nil)) == 'test'
|
7
|
+
return ::Kapellmeister::Base.routes_scheme_parse(mock)
|
8
|
+
end
|
7
9
|
|
10
|
+
data = query_params.compact_blank.merge(data)
|
8
11
|
valid_body?(data, body)
|
9
12
|
valid_query?(data, query_params)
|
10
13
|
|
@@ -21,10 +24,15 @@ end
|
|
21
24
|
|
22
25
|
def generate_full_path(original_path, data)
|
23
26
|
path = generate_path(original_path, data)
|
24
|
-
|
27
|
+
query = data.delete(:query_params)&.to_query
|
28
|
+
return "?#{query}" unless path
|
29
|
+
|
30
|
+
[path, query].compact_blank!.join('?')
|
25
31
|
end
|
26
32
|
|
27
33
|
def generate_path(original_path, data)
|
34
|
+
return nil unless original_path
|
35
|
+
|
28
36
|
original_path.split('/').map do |part|
|
29
37
|
next part unless part.include? '%<'
|
30
38
|
|
@@ -36,7 +44,7 @@ def valid_body?(data, body)
|
|
36
44
|
return if body.blank? || body.is_a?(Hash)
|
37
45
|
|
38
46
|
schema = Object.const_get(body).schema
|
39
|
-
result = schema.(data)
|
47
|
+
result = schema.call(data)
|
40
48
|
return data if result.success?
|
41
49
|
|
42
50
|
raise ArgumentError, result.errors.to_h
|
@@ -44,6 +52,7 @@ end
|
|
44
52
|
|
45
53
|
def valid_query?(data, query)
|
46
54
|
return if query.blank?
|
55
|
+
|
47
56
|
required_keys = query.keys
|
48
57
|
|
49
58
|
from_data = data.slice(*required_keys)
|
@@ -51,8 +60,8 @@ def valid_query?(data, query)
|
|
51
60
|
data[:query_params] ||= {}
|
52
61
|
data[:query_params] = data[:query_params].to_h.merge!(from_data)
|
53
62
|
|
54
|
-
|
55
|
-
return if required_keys.all? { |key|
|
63
|
+
different_keys = data[:query_params].transform_keys(&:to_sym)
|
64
|
+
return if required_keys.all? { |key| different_keys.key? key.to_sym }
|
56
65
|
|
57
66
|
raise ArgumentError, "Query params needs keys #{required_keys}"
|
58
67
|
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.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DarkWater
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-schema
|