Class: PactBroker::Api::Resources::Webhook

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

Instance Method Summary collapse

Methods included from WebhookResourceMethods

#webhook_validation_errors?

Instance Method Details

#actionObject



60
61
62
63
64
65
66
# File 'lib/pact_broker/api/resources/webhook.rb', line 60

def action
  if request.put?
    webhook ? :update : :create
  else
    super
  end
end

#allowed_methodsObject



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

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

#content_types_acceptedObject



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

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

#content_types_providedObject



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

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

#delete_resourceObject



51
52
53
54
# File 'lib/pact_broker/api/resources/webhook.rb', line 51

def delete_resource
  webhook_service.delete_by_uuid uuid
  true
end

#from_jsonObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/pact_broker/api/resources/webhook.rb', line 36

def from_json
  if webhook
    @webhook = webhook_service.update_by_uuid(uuid, params(symbolize_names: false))
    response.body = to_json
  else
    @webhook = webhook_service.create(uuid, parsed_webhook, consumer, provider)
    response.body = to_json
    201
  end
end

#malformed_request?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/pact_broker/api/resources/webhook.rb', line 29

def malformed_request?
  if request.put?
    return invalid_json? || webhook_validation_errors?(parsed_webhook, uuid)
  end
  false
end

#policy_nameObject



56
57
58
# File 'lib/pact_broker/api/resources/webhook.rb', line 56

def policy_name
  :'webhooks::webhook'
end

#policy_recordObject



68
69
70
# File 'lib/pact_broker/api/resources/webhook.rb', line 68

def policy_record
  webhook || parsed_webhook
end

#resource_exists?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/pact_broker/api/resources/webhook.rb', line 25

def resource_exists?
  !!webhook
end

#to_jsonObject



47
48
49
# File 'lib/pact_broker/api/resources/webhook.rb', line 47

def to_json
  decorator_class(:webhook_decorator).new(webhook).to_json(decorator_options)
end