Sha256: f0fa1bcc9ab0269add57d7b90c049e61ecbe1a9e8bcfc541a52e669671ec51ba

Contents?: true

Size: 1.43 KB

Versions: 74

Compression:

Stored size: 1.43 KB

Contents

require_relative 'base_decorator'
require 'json'

module PactBroker
  module Api
    module Decorators

      class WebhookExecutionResultDecorator < BaseDecorator

        class ErrorDecorator < BaseDecorator

          property :message
          property :backtrace

        end

        class HTTPResponseDecorator < BaseDecorator

          property :status, :getter => lambda { |_| code.to_i }
          property :headers, exec_context: :decorator
          property :body, exec_context: :decorator

          def headers
            headers_hash = represented.to_hash
            headers_hash.keys.each_with_object({}) do | name, new_headers_hash|
              new_headers_hash[name] = headers_hash[name].join(", ")
            end
          end

          def body
            begin
              ::JSON.parse(represented.body)
            rescue StandardError => e
              represented.body
            end
          end

        end

        property :error, :extend => ErrorDecorator
        property :response, :extend => HTTPResponseDecorator

        link :webhook do | options |
          {
            href: webhook_url(options.fetch(:webhook).uuid, options.fetch(:base_url))
          }
        end

        link :'try-again' do | options |
          {
            title: 'Execute the webhook again',
            href: webhook_execution_url(options.fetch(:webhook), options.fetch(:base_url))
          }
        end
      end
    end
  end
end

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
pact_broker-2.19.1 lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb
pact_broker-2.19.0 lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb
pact_broker-2.18.0 lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb
pact_broker-2.17.1 lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb
pact_broker-2.17.0 lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb
pact_broker-2.16.1 lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb
pact_broker-2.16.0 lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb
pact_broker-2.15.0 lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb
pact_broker-2.14.0 lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb
pact_broker-2.13.1 lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb
pact_broker-2.13.0 lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb
pact_broker-2.12.0 lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb
pact_broker-2.11.0 lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb
pact_broker-2.10.0 lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb
pact_broker-2.9.0 lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb
pact_broker-2.9.0.beta.5 lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb
pact_broker-2.8.0.beta.5 lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb
pact_broker-2.8.0.beta.4 lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb
pact_broker-2.7.0.beta.3 lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb
pact_broker-2.7.0.beta.2 lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb