class PactBroker::Api::Resources::AllWebhooks

Public Instance Methods

allowed_methods() click to toggle source
# File lib/pact_broker/api/resources/all_webhooks.rb, line 20
def allowed_methods
  ["GET", "POST", "OPTIONS"]
end
content_types_accepted() click to toggle source
# File lib/pact_broker/api/resources/all_webhooks.rb, line 16
def content_types_accepted
  [["application/json", :from_json]]
end
content_types_provided() click to toggle source
# File lib/pact_broker/api/resources/all_webhooks.rb, line 12
def content_types_provided
  [["application/hal+json", :to_json]]
end
create_path() click to toggle source
# File lib/pact_broker/api/resources/all_webhooks.rb, line 24
def create_path
  webhook_url next_uuid, base_url
end
from_json() click to toggle source
# File lib/pact_broker/api/resources/all_webhooks.rb, line 43
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?() click to toggle source
# File lib/pact_broker/api/resources/all_webhooks.rb, line 32
def malformed_request?
  if request.post?
    return invalid_json? || validation_errors?(webhook)
  end
  false
end
policy_name() click to toggle source
# File lib/pact_broker/api/resources/all_webhooks.rb, line 48
def policy_name
  :'webhooks::webhooks'
end
policy_record() click to toggle source
# File lib/pact_broker/api/resources/all_webhooks.rb, line 52
def policy_record
  if request.post?
    webhook
  else
    nil
  end
end
post_is_create?() click to toggle source
# File lib/pact_broker/api/resources/all_webhooks.rb, line 28
def post_is_create?
  true
end
to_json() click to toggle source
# File lib/pact_broker/api/resources/all_webhooks.rb, line 39
def to_json
  decorator_class(:webhooks_decorator).new(webhooks).to_json(decorator_options(resource_title: "Webhooks"))
end

Private Instance Methods

consumer() click to toggle source
# File lib/pact_broker/api/resources/all_webhooks.rb, line 72
def consumer
  webhook.consumer&.name ? pacticipant_service.find_pacticipant_by_name(webhook.consumer.name) : nil
end
next_uuid() click to toggle source
# File lib/pact_broker/api/resources/all_webhooks.rb, line 88
def next_uuid
  @next_uuid ||= webhook_service.next_uuid
end
provider() click to toggle source
# File lib/pact_broker/api/resources/all_webhooks.rb, line 76
def provider
  webhook.provider&.name ? pacticipant_service.find_pacticipant_by_name(webhook.provider.name) : nil
end
validation_errors?(webhook) click to toggle source
# File lib/pact_broker/api/resources/all_webhooks.rb, line 62
def validation_errors? webhook
  errors = webhook_service.errors(webhook)

  unless errors.empty?
    set_json_validation_error_messages(errors.messages)
  end

  !errors.empty?
end
webhook() click to toggle source
# File lib/pact_broker/api/resources/all_webhooks.rb, line 84
def webhook
  @webhook ||= decorator_class(:webhook_decorator).new(PactBroker::Domain::Webhook.new).from_json(request_body)
end
webhooks() click to toggle source
# File lib/pact_broker/api/resources/all_webhooks.rb, line 80
def webhooks
  webhook_service.find_all
end