Class: PactBroker::Api::Resources::Pacticipants

Inherits:
BaseResource
  • Object
show all
Defined in:
lib/pact_broker/api/resources/pacticipants.rb

Instance Method Summary collapse

Instance Method Details

#allowed_methodsObject



20
21
22
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 20

def allowed_methods
  ["GET", "POST", "OPTIONS"]
end

#content_types_acceptedObject



16
17
18
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 16

def content_types_accepted
  [["application/json", :from_json]]
end

#content_types_providedObject



12
13
14
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 12

def content_types_provided
  [["application/hal+json", :to_json]]
end

#create_pathObject



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_jsonObject



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(decorator_options)
end

#malformed_request?Boolean

Returns:

  • (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_modelObject



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_nameObject



60
61
62
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 60

def policy_name
  :'pacticipants::pacticipants'
end

#post_is_create?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 31

def post_is_create?
  true
end

#to_jsonObject



44
45
46
# File 'lib/pact_broker/api/resources/pacticipants.rb', line 44

def to_json
  generate_json(pacticipant_service.find_all_pacticipants)
end