kapellmeister 0.6.1 → 0.7.1
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 +29 -17
- 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: 4196ba8032b296bcb5c8c78afe748ea5029378ffa86bc33acaa1637f28205166
|
4
|
+
data.tar.gz: 674bb803ecbd64de4475ac095933872cd5708fc9165a07c3da299014e2149550
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6d9e5c707598dec39cd1dc2108d65bfa66d863dda7857f9373ae68d6e5fb8f29d4409b35c478bf00850bb1e2ac0ff4de7ba286f55abf69d620404ddd2900808
|
7
|
+
data.tar.gz: f5fb16f1d6cd0f6a369fb0c80f7fbdc015b8102d8261436c973f5cbc28b005ad1dec19089726e492fdd5ecc5214fa97a5c7f1e62e123a2feed41a38255e33873
|
@@ -1,42 +1,54 @@
|
|
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.
|
7
|
-
|
8
|
-
delegate :report, :configuration, :logger, to: base.module_parent
|
14
|
+
delegate :report, :logger, to: base.module_parent
|
9
15
|
end
|
10
16
|
|
11
17
|
FailedResponse = Struct.new(:success?, :response, :payload)
|
12
18
|
|
19
|
+
def headers
|
20
|
+
{}
|
21
|
+
end
|
22
|
+
|
23
|
+
def request_options
|
24
|
+
{}
|
25
|
+
end
|
26
|
+
|
27
|
+
def configuration
|
28
|
+
self.class.module_parent.configuration
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
13
33
|
def connection_by(method_name, path, data = {})
|
14
34
|
additional_headers = data.delete(:headers) || {}
|
15
35
|
requests_data = data.delete(:request) || {}
|
36
|
+
data_json = data.blank? ? '' : data.to_json
|
16
37
|
|
17
38
|
generated_connection = connection(additional_headers: additional_headers, requests_data: requests_data) # rubocop:disable Style/HashSyntax (for support ruby 2.4+)
|
18
39
|
|
19
|
-
process generated_connection.run_request(method_name.downcase.to_sym, path,
|
40
|
+
process generated_connection.run_request(method_name.downcase.to_sym, path, data_json, additional_headers)
|
41
|
+
|
20
42
|
rescue NameError, RuntimeError
|
21
43
|
raise "Library can't process method #{method_name} yet"
|
22
44
|
rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e
|
23
45
|
failed_response(details: e.message)
|
24
46
|
end
|
25
47
|
|
26
|
-
def headers
|
27
|
-
{}
|
28
|
-
end
|
29
|
-
|
30
|
-
def request_options
|
31
|
-
{}
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
48
|
def connection(additional_headers:, requests_data:)
|
37
|
-
::Faraday.new(url: configuration.url,
|
38
|
-
|
39
|
-
|
49
|
+
@connection ||= ::Faraday.new(url: configuration.url,
|
50
|
+
headers: headers_generate(**additional_headers),
|
51
|
+
request: requests_generate(**requests_data)) do |faraday|
|
40
52
|
faraday.request :json, content_type: 'application/json; charset=utf-8'
|
41
53
|
faraday.request :multipart
|
42
54
|
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.1
|
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-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-schema
|