Sha256: 6c447f763bcd4ff28ba711b4936445e6095c8fec7e2851fb5bbdd68366856373

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

require 'pact_broker/api/resources/base_resource'

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

module PactBroker::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"]
      end

      def known_methods
        super + ['PATCH']
      end

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

      def resource_exists?
        @pacticipant = pacticipant_service.find_pacticipant_by_name(identifier_from_path[:name])
        @pacticipant != nil
      end

      def to_json
        PactBroker::Api::Decorators::PacticipantRepresenter.new(@pacticipant).to_json(base_url: resource_url)
      end

    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pact_broker-1.0.0 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-1.0.0.alpha3 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-1.0.0.alpha2 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-1.0.0.alpha1 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-0.0.10 lib/pact_broker/api/resources/pacticipant.rb