Sha256: 9e44e57141c97e931d87f68f18e2d438f285618ab915e33a73e53796746fea0f

Contents?: true

Size: 1.62 KB

Versions: 28

Compression:

Stored size: 1.62 KB

Contents

require 'pact_broker/api/resources/base_resource'
require 'pact_broker/api/decorators/pact_webhooks_status_decorator'

module PactBroker

  module Api
    module Resources

      class PactWebhooksStatus < BaseResource

        def allowed_methods
          ["GET"]
        end

        def content_types_provided
          [["application/hal+json", :to_json]]
        end

        def resource_exists?
          consumer && provider
        end

        def to_json
          decorator_for(latest_triggered_webhooks).to_json(user_options: decorator_context(identifier_from_path))
        end

        private

        def latest_triggered_webhooks
          @latest_triggered_webhooks ||= webhook_service.find_latest_triggered_webhooks(consumer, provider)
        end

        def pact
          @pact ||= pact_service.find_latest_pact(pact_params)
        end

        def webhooks
          webhook_service.find_by_consumer_and_provider consumer, provider
        end

        def consumer
          @consumer ||= find_pacticipant(identifier_from_path[:consumer_name], "consumer")
        end

        def provider
          @provider ||= find_pacticipant(identifier_from_path[:provider_name], "provider")
        end

        def find_pacticipant name, role
          pacticipant_service.find_pacticipant_by_name(name).tap do | pacticipant |
            set_json_error_message("No #{role} with name '#{name}' found") if pacticipant.nil?
          end
        end

        def decorator_for latest_triggered_webhooks
          PactBroker::Api::Decorators::PactWebhooksStatusDecorator.new(latest_triggered_webhooks)
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
pact_broker-2.22.0 lib/pact_broker/api/resources/pact_webhooks_status.rb
pact_broker-2.21.0 lib/pact_broker/api/resources/pact_webhooks_status.rb
pact_broker-2.20.0 lib/pact_broker/api/resources/pact_webhooks_status.rb
pact_broker-2.19.2 lib/pact_broker/api/resources/pact_webhooks_status.rb
pact_broker-2.19.1 lib/pact_broker/api/resources/pact_webhooks_status.rb
pact_broker-2.19.0 lib/pact_broker/api/resources/pact_webhooks_status.rb
pact_broker-2.18.0 lib/pact_broker/api/resources/pact_webhooks_status.rb
pact_broker-2.17.1 lib/pact_broker/api/resources/pact_webhooks_status.rb
pact_broker-2.17.0 lib/pact_broker/api/resources/pact_webhooks_status.rb
pact_broker-2.16.1 lib/pact_broker/api/resources/pact_webhooks_status.rb
pact_broker-2.16.0 lib/pact_broker/api/resources/pact_webhooks_status.rb
pact_broker-2.15.0 lib/pact_broker/api/resources/pact_webhooks_status.rb
pact_broker-2.14.0 lib/pact_broker/api/resources/pact_webhooks_status.rb
pact_broker-2.13.1 lib/pact_broker/api/resources/pact_webhooks_status.rb
pact_broker-2.13.0 lib/pact_broker/api/resources/pact_webhooks_status.rb
pact_broker-2.12.0 lib/pact_broker/api/resources/pact_webhooks_status.rb
pact_broker-2.11.0 lib/pact_broker/api/resources/pact_webhooks_status.rb
pact_broker-2.10.0 lib/pact_broker/api/resources/pact_webhooks_status.rb
pact_broker-2.9.0 lib/pact_broker/api/resources/pact_webhooks_status.rb
pact_broker-2.9.0.beta.5 lib/pact_broker/api/resources/pact_webhooks_status.rb