Sha256: 37f29fd10bc05c2ad9b2735de2bff3b0397f1de8efebc91ad6231fb56e8512eb

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

require 'pact_broker/api/resources/base_resource'
require 'pact_broker/services'
require 'pact_broker/api/decorators/webhook_execution_result_decorator'
require 'pact_broker/constants'

module PactBroker
  module Api
    module Resources

      class WebhookExecution < BaseResource

        def allowed_methods
          ["POST"]
        end

        def process_post
          webhook_execution_result = webhook_service.test_execution(webhook)
          response.headers['Content-Type'] = 'application/hal+json;charset=utf-8'
          response.body = post_response_body webhook_execution_result
          if webhook_execution_result.success?
            true
          else
            response.headers[PactBroker::DO_NOT_ROLLBACK] = 'true'
            500
          end
        end

        def resource_exists?
          webhook
        end

        private

        def post_response_body webhook_execution_result
          Decorators::WebhookExecutionResultDecorator.new(webhook_execution_result).to_json(user_options: user_options)
        end

        def webhook
          @webhook ||= webhook_service.find_by_uuid uuid
        end

        def uuid
          identifier_from_path[:uuid]
        end

        def user_options
          { base_url: base_url, webhook: webhook, show_response: PactBroker.configuration.show_webhook_response? }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pact_broker-2.23.0 lib/pact_broker/api/resources/webhook_execution.rb