Class: PactBroker::Webhooks::Webhook
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- PactBroker::Webhooks::Webhook
- Defined in:
- lib/pact_broker/webhooks/webhook.rb
Class Method Summary collapse
Instance Method Summary collapse
- #before_destroy ⇒ Object
- #parsed_body ⇒ Object
- #parsed_headers ⇒ Object
- #plain_text_password ⇒ Object
- #request_attributes ⇒ Object
- #to_domain ⇒ Object
Class Method Details
.from_domain(webhook, consumer, provider) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pact_broker/webhooks/webhook.rb', line 18 def self.from_domain webhook, consumer, provider is_json_request_body = !(String === webhook.request.body || webhook.request.body.nil?) # Can't rely on people to set content type new( uuid: webhook.uuid, method: webhook.request.method, url: webhook.request.url, username: webhook.request.username, password: not_plain_text_password(webhook.request.password), body: (is_json_request_body ? webhook.request.body.to_json : webhook.request.body), is_json_request_body: is_json_request_body ).tap do | db_webhook | db_webhook.consumer_id = consumer.id db_webhook.provider_id = provider.id end end |
.not_plain_text_password(password) ⇒ Object
34 35 36 |
# File 'lib/pact_broker/webhooks/webhook.rb', line 34 def self.not_plain_text_password password password.nil? ? nil : Base64.strict_encode64(password) end |
Instance Method Details
#before_destroy ⇒ Object
14 15 16 |
# File 'lib/pact_broker/webhooks/webhook.rb', line 14 def before_destroy WebhookHeader.where(webhook_id: id).destroy end |
#parsed_body ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/pact_broker/webhooks/webhook.rb', line 62 def parsed_body if body && is_json_request_body JSON.parse(body) else body end end |
#parsed_headers ⇒ Object
56 57 58 59 60 |
# File 'lib/pact_broker/webhooks/webhook.rb', line 56 def parsed_headers WebhookHeader.where(webhook_id: id).all.each_with_object({}) do | header, hash | hash[header[:name]] = header[:value] end end |
#plain_text_password ⇒ Object
52 53 54 |
# File 'lib/pact_broker/webhooks/webhook.rb', line 52 def plain_text_password password.nil? ? nil : Base64.strict_decode64(password) end |
#request_attributes ⇒ Object
48 49 50 |
# File 'lib/pact_broker/webhooks/webhook.rb', line 48 def request_attributes values.merge(headers: parsed_headers, body: parsed_body, password: plain_text_password, uuid: uuid) end |