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



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

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

#content_types_acceptedObject



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

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

#content_types_providedObject



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

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

#create_pathObject



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_jsonObject



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

#malformed_request?Boolean

Returns:

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



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_nameObject



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

def policy_name
  :'pacticipants::pacticipants'
end

#post_is_create?Boolean

Returns:

  • (Boolean)


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

def post_is_create?
  true
end

#to_jsonObject



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

def to_json
  generate_json(pacticipant_service.find_all_pacticipants)
end