kapellmeister 0.6.2 → 0.7.0
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 -18
- data/lib/kapellmeister/requests_extension.rb +1 -5
- 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: 923b108fbce0c08cee2eb79bf46fb2741a61d1e833f1ffc01fcad0d18bbae972
|
4
|
+
data.tar.gz: 2dc7915c615149b8a7c5c1ff8a84960e212ffba27e65f2a29f45fd3b6ed174f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4011c6602baf6895abcb1ec4468dcdcd27ea987a56e5a4c4d6395f8ed523f020771b07e785bdfbbf2477696b31c4b5045c11042344548b3727fc1cc374918fdd
|
7
|
+
data.tar.gz: 3c4df81ba7e805659df36374c384e52f788d1d4a4309fac1b5da09eea099d5a9c6d26a3d58088e73c4ea0aa431cba8a93154aee9c65d8b7bfc091adca12ce62a
|
@@ -1,28 +1,21 @@
|
|
1
1
|
require 'faraday_middleware'
|
2
|
+
require_relative './requests_extension'
|
2
3
|
|
3
4
|
class Kapellmeister::Dispatcher
|
5
|
+
include Kapellmeister::RequestsExtension
|
6
|
+
delegate :request_processing, to: Kapellmeister::RequestsExtension
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
self.class.module_parent.requests.each(&request_processing)
|
10
|
+
end
|
11
|
+
|
4
12
|
def self.inherited(base)
|
5
13
|
super
|
6
|
-
base.extend(Kapellmeister::RequestsExtension)
|
7
|
-
|
8
14
|
delegate :report, :logger, to: base.module_parent
|
9
15
|
end
|
10
16
|
|
11
17
|
FailedResponse = Struct.new(:success?, :response, :payload)
|
12
18
|
|
13
|
-
def connection_by(method_name, path, data = {})
|
14
|
-
additional_headers = data.delete(:headers) || {}
|
15
|
-
requests_data = data.delete(:request) || {}
|
16
|
-
|
17
|
-
generated_connection = connection(additional_headers: additional_headers, requests_data: requests_data) # rubocop:disable Style/HashSyntax (for support ruby 2.4+)
|
18
|
-
|
19
|
-
process generated_connection.run_request(method_name.downcase.to_sym, path, data.to_json, additional_headers)
|
20
|
-
rescue NameError, RuntimeError
|
21
|
-
raise "Library can't process method #{method_name} yet"
|
22
|
-
rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e
|
23
|
-
failed_response(details: e.message)
|
24
|
-
end
|
25
|
-
|
26
19
|
def headers
|
27
20
|
{}
|
28
21
|
end
|
@@ -37,10 +30,23 @@ class Kapellmeister::Dispatcher
|
|
37
30
|
|
38
31
|
private
|
39
32
|
|
33
|
+
def connection_by(method_name, path, data = {})
|
34
|
+
additional_headers = data.delete(:headers) || {}
|
35
|
+
requests_data = data.delete(:request) || {}
|
36
|
+
|
37
|
+
generated_connection = connection(additional_headers: additional_headers, requests_data: requests_data) # rubocop:disable Style/HashSyntax (for support ruby 2.4+)
|
38
|
+
|
39
|
+
process generated_connection.run_request(method_name.downcase.to_sym, path, data.to_json, additional_headers)
|
40
|
+
rescue NameError, RuntimeError
|
41
|
+
raise "Library can't process method #{method_name} yet"
|
42
|
+
rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e
|
43
|
+
failed_response(details: e.message)
|
44
|
+
end
|
45
|
+
|
40
46
|
def connection(additional_headers:, requests_data:)
|
41
|
-
::Faraday.new(url: configuration.url,
|
42
|
-
|
43
|
-
|
47
|
+
@connection ||= ::Faraday.new(url: configuration.url,
|
48
|
+
headers: headers_generate(**additional_headers),
|
49
|
+
request: requests_generate(**requests_data)) do |faraday|
|
44
50
|
faraday.request :json, content_type: 'application/json; charset=utf-8'
|
45
51
|
faraday.request :multipart
|
46
52
|
faraday.response :logger, logger
|
@@ -10,17 +10,13 @@ module Kapellmeister::RequestsExtension
|
|
10
10
|
|
11
11
|
full_path = generate_full_path(path, data)
|
12
12
|
|
13
|
-
|
13
|
+
connection_by(method, full_path, data)
|
14
14
|
}.call(**request_data)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
rescue NoMethodError
|
18
18
|
raise "You need to define #{self} class with connection_by method"
|
19
19
|
end
|
20
|
-
|
21
|
-
def self.extended(base)
|
22
|
-
base.module_parent.requests.each(&request_processing)
|
23
|
-
end
|
24
20
|
end
|
25
21
|
|
26
22
|
def generate_full_path(original_path, data)
|
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.7.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-08-
|
11
|
+
date: 2022-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-schema
|