Sha256: dfe6b8d619a03c14941a80afc6d911f4cd7759e9cbda65f5c7e69a78478c7683

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 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", "OPTIONS"]
        end

        def known_methods
          super + ['PATCH']
        end

        def from_json
          if pacticipant
            @pacticipant = pacticipant_service.update params(symbolize_names: false).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?
          !!resource_object
        end

        def resource_object
          pacticipant
        end

        def delete_resource
          pacticipant_service.delete(pacticipant_name)
          true
        end

        def to_json
          PactBroker::Api::Decorators::PacticipantDecorator.new(pacticipant).to_json(decorator_options)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pact_broker-2.58.3 lib/pact_broker/api/resources/pacticipant.rb
pact_broker-2.58.2 lib/pact_broker/api/resources/pacticipant.rb