kapellmeister 0.6.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4469ce7f200030e5215269a415737eeb448029bac1e0ea60f238ab9d68eefd6d
4
- data.tar.gz: 4a9387ea59601ed6b2413cae95b4dd4b05690492c331a4ed2d7f18f191b04a32
3
+ metadata.gz: 923b108fbce0c08cee2eb79bf46fb2741a61d1e833f1ffc01fcad0d18bbae972
4
+ data.tar.gz: 2dc7915c615149b8a7c5c1ff8a84960e212ffba27e65f2a29f45fd3b6ed174f8
5
5
  SHA512:
6
- metadata.gz: b3ed10ab1cf0c69d4e0a18aadb3f9b124d7b1f35040dfc67f89e96d931b1226f7aa2f81bd557998d3176912cd2a2a75ed0d9bd4b39cc18596c679b3bb14cc971
7
- data.tar.gz: 3c3ad070259adcb1ba6ec7ac4bcc68a1faa9266bfb5ec50919bd93266698564d04849a43b2bea8afd0ce1ce13e35b30868d2fddce512617166e538cd71dbddb9
6
+ metadata.gz: 4011c6602baf6895abcb1ec4468dcdcd27ea987a56e5a4c4d6395f8ed523f020771b07e785bdfbbf2477696b31c4b5045c11042344548b3727fc1cc374918fdd
7
+ data.tar.gz: 3c4df81ba7e805659df36374c384e52f788d1d4a4309fac1b5da09eea099d5a9c6d26a3d58088e73c4ea0aa431cba8a93154aee9c65d8b7bfc091adca12ce62a
@@ -7,7 +7,7 @@ module <%= class_name %>
7
7
  delegate <%= initialize_signatures.map { |k| ":#{k}" }.join(', ') %>, to: :configuration
8
8
 
9
9
  def ssl
10
- @ssl ||= true
10
+ @ssl ||= (Rails.try(:env) || ENV['APP_ENV']) != 'development'
11
11
  end
12
12
  end
13
13
  end
@@ -1,15 +1,35 @@
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
- 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) || {}
@@ -23,20 +43,10 @@ class Kapellmeister::Dispatcher
23
43
  failed_response(details: e.message)
24
44
  end
25
45
 
26
- def headers
27
- {}
28
- end
29
-
30
- def request_options
31
- {}
32
- end
33
-
34
- private
35
-
36
46
  def connection(additional_headers:, requests_data:)
37
- ::Faraday.new(url: configuration.url,
38
- headers: headers_generate(**additional_headers),
39
- request: requests_generate(**requests_data)) do |faraday|
47
+ @connection ||= ::Faraday.new(url: configuration.url,
48
+ headers: headers_generate(**additional_headers),
49
+ request: requests_generate(**requests_data)) do |faraday|
40
50
  faraday.request :json, content_type: 'application/json; charset=utf-8'
41
51
  faraday.request :multipart
42
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
- new.connection_by(method, full_path, data)
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)
@@ -6,15 +6,15 @@ class Kapellmeister::Responder
6
6
 
7
7
  def initialize(response, **args)
8
8
  @response = response
9
- @payload = args
9
+ @payload = args.merge(status: status) # rubocop:disable Style/HashSyntax (for support ruby 2.4+)
10
10
  end
11
11
 
12
12
  def result
13
13
  error = !/2\d{2}/.match?(status.to_s)
14
14
 
15
- Result.new(!error, parsed_body, { status: status }.merge(payload)) # rubocop:disable Style/HashSyntax (for support ruby 2.4+)
15
+ Result.new(!error, parsed_body, payload)
16
16
  rescue JSON::ParserError => e
17
- Result.new(false, e)
17
+ Result.new(false, { message: e.message }, payload)
18
18
  end
19
19
 
20
20
  private
@@ -1,3 +1,3 @@
1
1
  module Kapellmeister
2
- VERSION = '0.6.0'.freeze
2
+ VERSION = '0.7.0'.freeze
3
3
  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.6.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-05-24 00:00:00.000000000 Z
11
+ date: 2022-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-schema