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 +4 -4
- data/README.md +1 -1
- data/lib/generators/kapellmeister/templates/lib/third_party/configuration.rb.tt +1 -1
- data/lib/generators/kapellmeister/templates/lib/third_party/responder.rb.tt +30 -0
- data/lib/generators/kapellmeister/templates/lib/third_party.rb.tt +4 -5
- data/lib/kapellmeister/dispatcher.rb +12 -13
- data/lib/kapellmeister/responder.rb +2 -2
- 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: 2c2bf7cc575b579cafe9ff8f500407e25275220340498dea77ff27d18ec73e35
         | 
| 4 | 
            +
              data.tar.gz: 36476a2563dfcac9ad129188b050b3fc212b3cd8ff9b5b5546ee10afc845ebd6
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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. | 
| 10 | 
            +
            gem 'kapellmeister', '~> 0.4.1'
         | 
| 11 11 | 
             
            ```
         | 
| 12 12 |  | 
| 13 13 | 
             
            ### Add new third party configuration:
         | 
| @@ -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 | 
            -
             | 
| 8 | 
            -
                <%= "def #{attr}" %>
         | 
| 9 | 
            -
                  <%= "@#{attr} ||= configuration.#{attr}" %>
         | 
| 10 | 
            -
                <%= "end" %>
         | 
| 7 | 
            +
                delegate <%= initialize_signatures.map { |k| ":#{k}" }.join(', ') %>, to: :configuration
         | 
| 11 8 |  | 
| 12 | 
            -
             | 
| 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 | 
            -
                 | 
| 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 | 
            -
                  ** | 
| 61 | 
            +
                  **headers
         | 
| 63 62 | 
             
                }
         | 
| 64 63 | 
             
              end
         | 
| 65 64 |  | 
| 66 65 | 
             
              def requests_generate(**requests_data)
         | 
| 67 66 | 
             
                {
         | 
| 68 67 | 
             
                  **requests_data,
         | 
| 69 | 
            -
                  ** | 
| 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:  | 
| 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. | 
| 23 | 
            +
                return body if body.empty?
         | 
| 24 24 |  | 
| 25 25 | 
             
                case body
         | 
| 26 26 | 
             
                when Hash then body
         | 
    
        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 | 
| 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- | 
| 11 | 
            +
            date: 2022-05-01 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: faraday
         |