Sha256: c43003bb9bcef7b99e390e56158216534814bc39efe47465e8b85c0a7b4e3413

Contents?: true

Size: 1.52 KB

Versions: 33

Compression:

Stored size: 1.52 KB

Contents

require 'pact_broker/api/resources/base_resource'

module Webmachine
  class Request
    def put?
      method == "PUT" || method == "PATCH"
    end
  end
end

module PactBroker
  module Api
    module Resources

      class Pacticipant < BaseResource

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

        def content_types_accepted
          [["application/json", :from_json]]
        end

        def allowed_methods
          ["GET", "PATCH", "DELETE"]
        end

        def known_methods
          super + ['PATCH']
        end

        def from_json
          if pacticipant
            @pacticipant = pacticipant_service.update params.merge(name: pacticipant_name)
          else
            @pacticipant = pacticipant_service.create params.merge(name: pacticipant_name)
            response.headers["Location"] = pacticipant_url(base_url, pacticipant)
          end
          response.body = to_json
        end

        def resource_exists?
          pacticipant
        end

        def delete_resource
          pacticipant_service.delete pacticipant_name
          true
        end

        def to_json
          PactBroker::Api::Decorators::PacticipantDecorator.new(pacticipant).to_json(user_options: { base_url: base_url })
        end

        private

        def pacticipant
          @pacticipant ||= pacticipant_service.find_pacticipant_by_name(pacticipant_name)
        end

        def pacticipant_name
          identifier_from_path[:name]
        end

      end
    end

  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
pact_broker-2.7.0.beta.2 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-2.7.0.beta.1 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-2.6.0 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-2.5.1 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-2.5.0 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-2.4.2 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-2.4.1 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-2.4.0 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-2.3.0 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-2.2.0 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-2.1.1 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-2.1.0 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-2.0.5 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-2.0.4 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-2.0.3 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-2.0.2 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-2.0.1 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-2.0.0 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-2.0.0.beta.8 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-2.0.0.beta.7 lib/pact_broker/api/resources/pacticipant.rb