Class: PactBroker::Api::Resources::Pacticipant

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

Instance Method Summary collapse

Instance Method Details

#allowed_methodsObject



24
25
26
# File 'lib/pact_broker/api/resources/pacticipant.rb', line 24

def allowed_methods
  ["GET", "PATCH", "DELETE", "OPTIONS"]
end

#content_types_acceptedObject



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

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

#content_types_providedObject



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

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

#delete_resourceObject



54
55
56
57
# File 'lib/pact_broker/api/resources/pacticipant.rb', line 54

def delete_resource
  pacticipant_service.delete(pacticipant_name)
  true
end

#from_jsonObject



32
33
34
35
36
37
38
39
40
# File 'lib/pact_broker/api/resources/pacticipant.rb', line 32

def from_json
  if pacticipant
    @pacticipant = pacticipant_service.update params(symbolize_names: false).merge('name' => pacticipant_name)
  else
    @pacticipant = pacticipant_service.create params.merge(:name => pacticipant_name)
    response.headers["Location"] = pacticipant_url(base_url, pacticipant)
  end
  response.body = to_json
end

#known_methodsObject



28
29
30
# File 'lib/pact_broker/api/resources/pacticipant.rb', line 28

def known_methods
  super + ['PATCH']
end

#policy_resourceObject



50
51
52
# File 'lib/pact_broker/api/resources/pacticipant.rb', line 50

def policy_resource
  pacticipant
end

#resource_exists?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/pact_broker/api/resources/pacticipant.rb', line 42

def resource_exists?
  !!resource_object
end

#resource_objectObject



46
47
48
# File 'lib/pact_broker/api/resources/pacticipant.rb', line 46

def resource_object
  pacticipant
end

#to_jsonObject



59
60
61
# File 'lib/pact_broker/api/resources/pacticipant.rb', line 59

def to_json
  PactBroker::Api::Decorators::PacticipantDecorator.new(pacticipant).to_json(decorator_options)
end