class PactBroker::Api::Resources::Pacticipant

Public Instance Methods

allowed_methods() click to toggle source
# File lib/pact_broker/api/resources/pacticipant.rb, line 20
def allowed_methods
  ["GET", "PUT", "PATCH", "DELETE", "OPTIONS"]
end
content_types_accepted() click to toggle source
# File lib/pact_broker/api/resources/pacticipant.rb, line 13
def content_types_accepted
  [
    ["application/json", :from_json],
    ["application/merge-patch+json", :from_merge_patch_json]
  ]
end
content_types_provided() click to toggle source
# File lib/pact_broker/api/resources/pacticipant.rb, line 9
def content_types_provided
  [["application/hal+json", :to_json]]
end
create_new_pacticipant() click to toggle source
# File lib/pact_broker/api/resources/pacticipant.rb, line 91
def create_new_pacticipant
  pacticipant_service.create parsed_pacticipant(OpenStruct.new).to_h.merge(:name => pacticipant_name)
end
delete_resource() click to toggle source
# File lib/pact_broker/api/resources/pacticipant.rb, line 62
def delete_resource
  pacticipant_service.delete(pacticipant_name)
  true
end
from_json() click to toggle source
# File lib/pact_broker/api/resources/pacticipant.rb, line 36
def from_json
  if pacticipant
    @pacticipant = update_existing_pacticipant
  else
    if request.patch? # for backwards compatibility, wish I hadn't done this
      @pacticipant = create_new_pacticipant
      response.headers["Location"] = pacticipant_url(base_url, pacticipant)
    else
      return 404
    end
  end
  response.body = to_json
end
from_merge_patch_json() click to toggle source
# File lib/pact_broker/api/resources/pacticipant.rb, line 50
def from_merge_patch_json
  if request.patch?
    from_json
  else
    415
  end
end
known_methods() click to toggle source
Calls superclass method
# File lib/pact_broker/api/resources/pacticipant.rb, line 24
def known_methods
  super + ["PATCH"]
end
malformed_request?() click to toggle source
# File lib/pact_broker/api/resources/pacticipant.rb, line 28
def malformed_request?
  if request.patch? || request.put?
    invalid_json? || validation_errors_for_schema?
  else
    false
  end
end
parsed_pacticipant(pacticipant) click to toggle source
# File lib/pact_broker/api/resources/pacticipant.rb, line 71
def parsed_pacticipant(pacticipant)
  decorator_class(:pacticipant_decorator).new(pacticipant).from_json(request_body)
end
policy_name() click to toggle source
# File lib/pact_broker/api/resources/pacticipant.rb, line 75
def policy_name
  :'pacticipants::pacticipant'
end
resource_exists?() click to toggle source
# File lib/pact_broker/api/resources/pacticipant.rb, line 58
def resource_exists?
  !!pacticipant
end
schema() click to toggle source
# File lib/pact_broker/api/resources/pacticipant.rb, line 79
def schema
  PactBroker::Api::Contracts::PacticipantSchema
end
to_json() click to toggle source
# File lib/pact_broker/api/resources/pacticipant.rb, line 67
def to_json
  decorator_class(:pacticipant_decorator).new(pacticipant).to_json(decorator_options)
end
update_existing_pacticipant() click to toggle source
# File lib/pact_broker/api/resources/pacticipant.rb, line 83
def update_existing_pacticipant
  if request.really_put?
    @pacticipant = pacticipant_service.replace(pacticipant_name, parsed_pacticipant(OpenStruct.new))
  else
    @pacticipant = pacticipant_service.update(pacticipant_name, parsed_pacticipant(pacticipant))
  end
end