Class: PactBroker::Api::Resources::Pacticipant
- Inherits:
-
BaseResource
- Object
- BaseResource
- PactBroker::Api::Resources::Pacticipant
- Defined in:
- lib/pact_broker/api/resources/pacticipant.rb
Instance Method Summary collapse
- #allowed_methods ⇒ Object
- #content_types_accepted ⇒ Object
- #content_types_provided ⇒ Object
- #create_new_pacticipant ⇒ Object
- #delete_resource ⇒ Object
- #from_json ⇒ Object
- #from_merge_patch_json ⇒ Object
- #known_methods ⇒ Object
- #malformed_request? ⇒ Boolean
- #parsed_pacticipant(pacticipant) ⇒ Object
- #policy_name ⇒ Object
- #resource_exists? ⇒ Boolean
- #schema ⇒ Object
- #to_json ⇒ Object
- #update_existing_pacticipant ⇒ Object
Instance Method Details
#allowed_methods ⇒ Object
20 21 22 |
# File 'lib/pact_broker/api/resources/pacticipant.rb', line 20 def allowed_methods ["GET", "PUT", "PATCH", "DELETE", "OPTIONS"] end |
#content_types_accepted ⇒ Object
13 14 15 16 17 18 |
# 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 ⇒ Object
9 10 11 |
# File 'lib/pact_broker/api/resources/pacticipant.rb', line 9 def content_types_provided [["application/hal+json", :to_json]] end |
#create_new_pacticipant ⇒ Object
91 92 93 |
# 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 ⇒ Object
62 63 64 65 |
# File 'lib/pact_broker/api/resources/pacticipant.rb', line 62 def delete_resource pacticipant_service.delete(pacticipant_name) true end |
#from_json ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# 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 ⇒ Object
50 51 52 53 54 55 56 |
# 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 ⇒ Object
24 25 26 |
# File 'lib/pact_broker/api/resources/pacticipant.rb', line 24 def known_methods super + ["PATCH"] end |
#malformed_request? ⇒ Boolean
28 29 30 31 32 33 34 |
# 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) ⇒ Object
71 72 73 |
# 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 ⇒ Object
75 76 77 |
# File 'lib/pact_broker/api/resources/pacticipant.rb', line 75 def policy_name :'pacticipants::pacticipant' end |
#resource_exists? ⇒ Boolean
58 59 60 |
# File 'lib/pact_broker/api/resources/pacticipant.rb', line 58 def resource_exists? !!pacticipant end |
#schema ⇒ Object
79 80 81 |
# File 'lib/pact_broker/api/resources/pacticipant.rb', line 79 def schema PactBroker::Api::Contracts::PacticipantSchema end |
#to_json ⇒ Object
67 68 69 |
# File 'lib/pact_broker/api/resources/pacticipant.rb', line 67 def to_json decorator_class(:pacticipant_decorator).new(pacticipant).to_json() end |
#update_existing_pacticipant ⇒ Object
83 84 85 86 87 88 89 |
# 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 |