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
- #new_model ⇒ Object
- #policy_name ⇒ Object
- #post_is_create? ⇒ Boolean
- #to_json ⇒ Object
Instance Method Details
#allowed_methods ⇒ Object
20 21 22 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 20 def allowed_methods ["GET", "POST", "OPTIONS"] end |
#content_types_accepted ⇒ Object
16 17 18 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 16 def content_types_accepted [["application/json", :from_json]] end |
#content_types_provided ⇒ Object
12 13 14 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 12 def content_types_provided [["application/hal+json", :to_json]] end |
#create_path ⇒ Object
40 41 42 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 40 def create_path "/pacticpants/#{url_encode(params[:name])}" end |
#decorator_for(model) ⇒ Object
52 53 54 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 52 def decorator_for model PactBroker::Api::Decorators::PacticipantDecorator.new(model) end |
#from_json ⇒ Object
35 36 37 38 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 35 def from_json created_model = pacticipant_service.create(params.symbolize_keys.snakecase_keys.slice(:name, :repository_url)) response.body = decorator_for(created_model).to_json(user_options: decorator_context) end |
#generate_json(pacticipants) ⇒ Object
48 49 50 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 48 def generate_json pacticipants PactBroker::Api::Decorators::DeprecatedPacticipantCollectionDecorator.new(pacticipants).to_json() end |
#malformed_request? ⇒ Boolean
24 25 26 27 28 29 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 24 def malformed_request? if request.post? return invalid_json? || validation_errors?(new_model) end false end |
#new_model ⇒ Object
56 57 58 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 56 def new_model @new_model ||= decorator_for(PactBroker::Domain::Pacticipant.new).from_json(request.body.to_s) end |
#policy_name ⇒ Object
60 61 62 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 60 def policy_name :'pacticipants::pacticipants' end |
#post_is_create? ⇒ Boolean
31 32 33 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 31 def post_is_create? true end |
#to_json ⇒ Object
44 45 46 |
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 44 def to_json generate_json(pacticipant_service.find_all_pacticipants) end |