Class: PactBroker::Api::Resources::PacticipantWebhooks

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

Instance Method Summary collapse

Methods included from WebhookResourceMethods

#webhook_validation_errors?

Instance Method Details

#allowed_methodsObject



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

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

#content_types_acceptedObject



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

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

#content_types_providedObject



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

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

#create_pathObject



36
37
38
# File 'lib/pact_broker/api/resources/pacticipant_webhooks.rb', line 36

def create_path
  webhook_url next_uuid, base_url
end

#from_jsonObject



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

def from_json
  saved_webhook = webhook_service.create next_uuid, webhook, consumer, provider
  response.body = decorator_class(:webhook_decorator).new(saved_webhook).to_json(decorator_options)
end

#malformed_request?Boolean

Returns:

  • (Boolean)


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

def malformed_request?
  if request.post?
    return invalid_json? || webhook_validation_errors?(webhook)
  end
  false
end

#policy_nameObject



53
54
55
# File 'lib/pact_broker/api/resources/pacticipant_webhooks.rb', line 53

def policy_name
  :'webhooks::webhooks'
end

#policy_recordObject



57
58
59
# File 'lib/pact_broker/api/resources/pacticipant_webhooks.rb', line 57

def policy_record
  request.post? ? webhook : nil
end

#post_is_create?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/pact_broker/api/resources/pacticipant_webhooks.rb', line 40

def post_is_create?
  true
end

#resource_exists?Boolean

Returns:

  • (Boolean)


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

def resource_exists?
  (!consumer_specified? || consumer) && (!provider_specified? || provider)
end

#to_jsonObject



49
50
51
# File 'lib/pact_broker/api/resources/pacticipant_webhooks.rb', line 49

def to_json
  decorator_class(:webhooks_decorator).new(webhooks).to_json(decorator_options(resource_title: "Webhooks"))
end