Class: PactBroker::Api::Resources::PactWebhooks
- Inherits:
-
BaseResource
- Object
- PactBroker::Api::Resources::PactWebhooks
- Defined in:
- lib/pact_broker/api/resources/pact_webhooks.rb
Instance Method Summary collapse
- #allowed_methods ⇒ Object
- #content_types_accepted ⇒ Object
- #content_types_provided ⇒ Object
- #create_path ⇒ Object
- #from_json ⇒ Object
- #malformed_request? ⇒ Boolean
- #policy_name ⇒ Object
- #post_is_create? ⇒ Boolean
- #resource_exists? ⇒ Boolean
- #to_json ⇒ Object
- #validation_errors?(webhook) ⇒ Boolean
Instance Method Details
#allowed_methods ⇒ Object
11 12 13 |
# File 'lib/pact_broker/api/resources/pact_webhooks.rb', line 11 def allowed_methods ["POST", "GET", "OPTIONS"] end |
#content_types_accepted ⇒ Object
19 20 21 |
# File 'lib/pact_broker/api/resources/pact_webhooks.rb', line 19 def content_types_accepted [["application/json", :from_json]] end |
#content_types_provided ⇒ Object
15 16 17 |
# File 'lib/pact_broker/api/resources/pact_webhooks.rb', line 15 def content_types_provided [["application/hal+json", :to_json]] end |
#create_path ⇒ Object
45 46 47 |
# File 'lib/pact_broker/api/resources/pact_webhooks.rb', line 45 def create_path webhook_url next_uuid, base_url end |
#from_json ⇒ Object
53 54 55 56 |
# File 'lib/pact_broker/api/resources/pact_webhooks.rb', line 53 def from_json saved_webhook = webhook_service.create next_uuid, webhook, consumer, provider response.body = decorator_class(:webhook_decorator).new(saved_webhook).to_json() end |
#malformed_request? ⇒ Boolean
27 28 29 30 31 32 |
# File 'lib/pact_broker/api/resources/pact_webhooks.rb', line 27 def malformed_request? if request.post? return invalid_json? || validation_errors?(webhook) end false end |
#policy_name ⇒ Object
62 63 64 |
# File 'lib/pact_broker/api/resources/pact_webhooks.rb', line 62 def policy_name :"integrations::integration" end |
#post_is_create? ⇒ Boolean
49 50 51 |
# File 'lib/pact_broker/api/resources/pact_webhooks.rb', line 49 def post_is_create? true end |
#resource_exists? ⇒ Boolean
23 24 25 |
# File 'lib/pact_broker/api/resources/pact_webhooks.rb', line 23 def resource_exists? (!consumer_specified? || consumer) && (!provider_specified? || provider) end |
#to_json ⇒ Object
58 59 60 |
# File 'lib/pact_broker/api/resources/pact_webhooks.rb', line 58 def to_json decorator_class(:webhooks_decorator).new(webhooks).to_json((resource_title: "Pact webhooks")) end |
#validation_errors?(webhook) ⇒ Boolean
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pact_broker/api/resources/pact_webhooks.rb', line 34 def validation_errors? webhook errors = webhook_service.errors(webhook) unless errors.empty? response.headers["Content-Type"] = "application/hal+json;charset=utf-8" response.body = { errors: errors. }.to_json end !errors.empty? end |