Class: PactBroker::Webhooks::Webhook

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/pact_broker/webhooks/webhook.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_domain(webhook, consumer, provider) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/pact_broker/webhooks/webhook.rb', line 29

def self.from_domain webhook, consumer, provider
  new(
    properties_hash_from_domain(webhook).merge(uuid: webhook.uuid)
  ).tap do | db_webhook |
    db_webhook.consumer_id = consumer.id if consumer
    db_webhook.provider_id = provider.id if provider
  end
end

.not_plain_text_password(password) ⇒ Object



38
39
40
# File 'lib/pact_broker/webhooks/webhook.rb', line 38

def self.not_plain_text_password password
  password.nil? ? nil : Base64.strict_encode64(password)
end

Instance Method Details

#is_for?(relationship) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/pact_broker/webhooks/webhook.rb', line 71

def is_for? relationship
  (consumer_id == relationship.consumer_id || !consumer_id) && (provider_id == relationship.provider_id || !provider_id)
end

#parsed_bodyObject



63
64
65
66
67
68
69
# File 'lib/pact_broker/webhooks/webhook.rb', line 63

def parsed_body
  if body && is_json_request_body
     JSON.parse(body)
  else
    body
  end
end

#plain_text_passwordObject



59
60
61
# File 'lib/pact_broker/webhooks/webhook.rb', line 59

def plain_text_password
  password.nil? ? nil : Base64.strict_decode64(password)
end

#request_attributesObject



55
56
57
# File 'lib/pact_broker/webhooks/webhook.rb', line 55

def request_attributes
  values.merge(headers: headers, body: parsed_body, password: plain_text_password, uuid: uuid)
end

#to_domainObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pact_broker/webhooks/webhook.rb', line 42

def to_domain
  Domain::Webhook.new(
    uuid: uuid,
    description: description,
    consumer: consumer,
    provider: provider,
    events: events,
    request: Webhooks::WebhookRequestTemplate.new(request_attributes),
    enabled: enabled,
    created_at: created_at,
    updated_at: updated_at)
end

#update_from_domain(webhook) ⇒ Object



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

def update_from_domain webhook
  set(self.class.properties_hash_from_domain(webhook))
end