Class: PactBroker::Api::Resources::Pacticipants
- Inherits:
-
BaseResource
- Object
- BaseResource
- PactBroker::Api::Resources::Pacticipants
- Defined in:
- lib/pact_broker/api/resources/pacticipants.rb
Instance Method Summary collapse
- #allowed_methods ⇒ Object
- #content_types_accepted ⇒ Object
- #content_types_provided ⇒ Object
- #create_path ⇒ Object
- #decorator_for(model) ⇒ Object
- #from_json ⇒ Object
- #generate_json(pacticipants) ⇒ Object
- #malformed_request? ⇒ Boolean
- #parsed_pacticipant ⇒ Object
- #policy_name ⇒ Object
- #post_is_create? ⇒ Boolean
- #to_json ⇒ Object
Instance Method Details
#allowed_methods ⇒ Object
21 22 23 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 21 def allowed_methods ["GET", "POST", "OPTIONS"] end |
#content_types_accepted ⇒ Object
17 18 19 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 17 def content_types_accepted [["application/json", :from_json]] end |
#content_types_provided ⇒ Object
13 14 15 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 13 def content_types_provided [["application/hal+json", :to_json]] end |
#create_path ⇒ Object
41 42 43 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 41 def create_path "/pacticpants/#{url_encode(params[:name])}" end |
#decorator_for(model) ⇒ Object
53 54 55 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 53 def decorator_for model decorator_class(:pacticipant_decorator).new(model) end |
#from_json ⇒ Object
36 37 38 39 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 36 def from_json created_model = pacticipant_service.create(parsed_pacticipant.to_h) response.body = decorator_for(created_model).to_json() end |
#generate_json(pacticipants) ⇒ Object
49 50 51 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 49 def generate_json pacticipants decorator_class(:deprecated_pacticipant_collection_decorator).new(pacticipants).to_json() end |
#malformed_request? ⇒ Boolean
25 26 27 28 29 30 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 25 def malformed_request? if request.post? return invalid_json? || validation_errors_for_schema? end false end |
#parsed_pacticipant ⇒ Object
57 58 59 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 57 def parsed_pacticipant @new_model ||= decorator_for(OpenStruct.new).from_json(request_body) end |
#policy_name ⇒ Object
61 62 63 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 61 def policy_name :'pacticipants::pacticipants' end |
#post_is_create? ⇒ Boolean
32 33 34 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 32 def post_is_create? true end |
#to_json ⇒ Object
45 46 47 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 45 def to_json generate_json(pacticipant_service.find_all_pacticipants) end |