kapellmeister 0.2.0 → 0.4.2

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: d2b84c0c37d94a680d0c405370bd1c4cd4f47dc1c9e1b175782cbf5169c4f047
4
- data.tar.gz: c9a1827474e3b1249b122fcf7ea7a6ff6540fcb011bfcf5a77883e21458e044b
3
+ metadata.gz: 2c2bf7cc575b579cafe9ff8f500407e25275220340498dea77ff27d18ec73e35
4
+ data.tar.gz: 36476a2563dfcac9ad129188b050b3fc212b3cd8ff9b5b5546ee10afc845ebd6
5
5
  SHA512:
6
- metadata.gz: d442dd5e3efd05daddd385204f0ee3264456b0bbdde008bcbcb55965678251e251016788ab7c70d656c4e156355dd4efcdd19310add797268d0cf98530f8a6a5
7
- data.tar.gz: 9ac48ff4d3f602ee60573d4237034914e547d333de760375773a774e4b0b9c85857f82dfb946e1bacd1163addb238d9d45912d7ba29ae3e53ee5ee06f9a8c514
6
+ metadata.gz: b62e680f94423d0822ff0a784702b023712ebf313bb40b38634808a4eb2e2d03affb5027e3d064942ba5fa475068ec42d746a9ac053d14d975923a3f85960fba
7
+ data.tar.gz: bca17d751f762904131e458423e342eea9e56b521ef6ab869d45d5ff8746aa0519c8dc501d9cf76e4372df8be6205f8559f119c6de8c4ab07ba7b0745f36126c
data/README.md CHANGED
@@ -7,7 +7,7 @@ This template-service allows you to define http requests to a third party throug
7
7
  Add kapellmeister to your Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'kapellmeister', '~> 0.0.1', require: false
10
+ gem 'kapellmeister', '~> 0.4.1'
11
11
  ```
12
12
 
13
13
  ### Add new third party configuration:
@@ -1,5 +1,5 @@
1
1
  class <%= class_name %>::Configuration
2
- attr_accessor <%= [*initialize_signatures, :path, :logger].map { |k| ":#{k}" }.join(', ') %>
2
+ attr_accessor <%= [*initialize_signatures, :ssl, :path, :logger].map { |k| ":#{k}" }.join(', ') %>
3
3
 
4
4
  def initialize
5
5
  @path = ''
@@ -0,0 +1,30 @@
1
+ class <%= class_name %>::Responder
2
+ Result = Struct.new(:success?, :response, :payload)
3
+ attr_reader :response, :payload
4
+
5
+ delegate :body, :status, to: :response
6
+
7
+ def initialize(response, **args)
8
+ @response = response
9
+ @payload = args
10
+ end
11
+
12
+ def result
13
+ error = !/2\d{2}/.match?(status.to_s)
14
+
15
+ Result.new(!error, parsed_body, { status: }.merge(payload))
16
+ rescue JSON::ParserError => e
17
+ Result.new(false, e)
18
+ end
19
+
20
+ private
21
+
22
+ def parsed_body
23
+ return body if body.length.zero?
24
+
25
+ case body
26
+ when Hash then body
27
+ else JSON.parse(body, symbolize_names: true, quirks_mode: true)
28
+ end
29
+ end
30
+ end
@@ -4,11 +4,10 @@ module <%= class_name %>
4
4
  class << self
5
5
  include ::Kapellmeister::Base
6
6
 
7
- <%- initialize_signatures.each do |attr| -%>
8
- <%= "def #{attr}" %>
9
- <%= "@#{attr} ||= configuration.#{attr}" %>
10
- <%= "end" %>
7
+ delegate <%= initialize_signatures.map { |k| ":#{k}" }.join(', ') %>, to: :configuration
11
8
 
12
- <%- end -%>
9
+ def ssl
10
+ @ssl ||= true
11
+ end
13
12
  end
14
13
  end
@@ -2,17 +2,10 @@ require 'faraday_middleware'
2
2
 
3
3
  class Kapellmeister::Dispatcher
4
4
  def self.inherited(base)
5
- base.extend(RequestsExtension)
5
+ super
6
+ base.extend(Kapellmeister::RequestsExtension)
6
7
 
7
8
  delegate :report, :configuration, :logger, to: base.module_parent
8
-
9
- def custom_headers
10
- @custom_headers ||= try(:headers) || {}
11
- end
12
-
13
- def custom_request_options
14
- @custom_request_options ||= try(:request_options) || {}
15
- end
16
9
  end
17
10
 
18
11
  FailedResponse = Struct.new(:success?, :response, :payload)
@@ -37,13 +30,20 @@ class Kapellmeister::Dispatcher
37
30
  failed_response(details: e.message)
38
31
  end
39
32
 
33
+ def headers
34
+ {}
35
+ end
36
+
37
+ def request_options
38
+ {}
39
+ end
40
+
40
41
  private
41
42
 
42
43
  def connection(additional_headers:, requests_data:)
43
44
  ::Faraday.new(url: configuration.url,
44
45
  headers: headers_generate(**additional_headers),
45
46
  request: requests_generate(**requests_data)) do |faraday|
46
- faraday.request :authorization, *authorization
47
47
  faraday.request :json, content_type: 'application/json'
48
48
  faraday.request :multipart
49
49
  faraday.response :logger, logger
@@ -56,17 +56,16 @@ class Kapellmeister::Dispatcher
56
56
 
57
57
  def headers_generate(**additional)
58
58
  {
59
- authority: Credentials.send_it.host,
60
59
  accept: 'application/json, text/plain, */*',
61
60
  **additional,
62
- **custom_headers
61
+ **headers
63
62
  }
64
63
  end
65
64
 
66
65
  def requests_generate(**requests_data)
67
66
  {
68
67
  **requests_data,
69
- **custom_request_options
68
+ **request_options
70
69
  }
71
70
  end
72
71
 
@@ -12,7 +12,7 @@ class Kapellmeister::Responder
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))
15
+ Result.new(!error, parsed_body, { status: }.merge(payload))
16
16
  rescue JSON::ParserError => e
17
17
  Result.new(false, e)
18
18
  end
@@ -20,7 +20,7 @@ class Kapellmeister::Responder
20
20
  private
21
21
 
22
22
  def parsed_body
23
- return body if body.length == 0
23
+ return body if body.empty?
24
24
 
25
25
  case body
26
26
  when Hash then body
@@ -1,3 +1,3 @@
1
1
  module Kapellmeister
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.4.2'.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.2.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - DarkWater
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-29 00:00:00.000000000 Z
11
+ date: 2022-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday