Class: PagerTree::Integrations::OutgoingWebhookDelivery::HookRelay
- Inherits:
-
PagerTree::Integrations::OutgoingWebhookDelivery
- Object
- PagerTree::Integrations::OutgoingWebhookDelivery
- PagerTree::Integrations::OutgoingWebhookDelivery::HookRelay
- Extended by:
- Env
- Defined in:
- app/models/pager_tree/integrations/outgoing_webhook_delivery/hook_relay.rb
Constant Summary
Constants inherited from PagerTree::Integrations::OutgoingWebhookDelivery
Class Method Summary collapse
Instance Method Summary collapse
- #deliver ⇒ Object
- #deliver_later ⇒ Object
- #delivery ⇒ Object
- #hook_relay_delivery_url ⇒ Object
- #hook_relay_hook_url ⇒ Object
- #request ⇒ Object
- #responses ⇒ Object
Methods inherited from PagerTree::Integrations::OutgoingWebhookDelivery
Class Method Details
.hook_relay_account_id ⇒ Object
7 8 9 |
# File 'app/models/pager_tree/integrations/outgoing_webhook_delivery/hook_relay.rb', line 7 def self.hook_relay_account_id find_value_by_name(:hook_relay, :account_id) end |
.hook_relay_api_key ⇒ Object
15 16 17 |
# File 'app/models/pager_tree/integrations/outgoing_webhook_delivery/hook_relay.rb', line 15 def self.hook_relay_api_key find_value_by_name(:hook_relay, :api_key) end |
.hook_relay_hook_id ⇒ Object
11 12 13 |
# File 'app/models/pager_tree/integrations/outgoing_webhook_delivery/hook_relay.rb', line 11 def self.hook_relay_hook_id find_value_by_name(:hook_relay, :hook_id) end |
Instance Method Details
#deliver ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/models/pager_tree/integrations/outgoing_webhook_delivery/hook_relay.rb', line 31 def deliver run_callbacks :deliver do begin = { headers: { HR_TARGET_URL: url } } = { headers: { Accept: "*/*", "User-Agent": "pagertree outgoing webhook service; ref: #{resource&.id}; report: [email protected]", "Content-Type": "application/json" } } = {} if auth.is_a?(Hash) && (username = auth.dig(:username)).present? && (password = auth.dig(:password)).present? = { headers: { Authorization: Base64.strict_encode64("#{username}:#{password}") } } end = OutgoingWebhookDelivery::HTTP_OPTIONS .deep_merge() .deep_merge() .deep_merge() response = HTTParty.post(hook_relay_hook_url, body: body.to_json, **) self.thirdparty_id = response["id"] self.status = :sent rescue => exception Rails.logger.error(exception) self.status = :failure end save! end # run_callbacks end |
#deliver_later ⇒ Object
27 28 29 |
# File 'app/models/pager_tree/integrations/outgoing_webhook_delivery/hook_relay.rb', line 27 def deliver_later OutgoingWebhookJob.perform_later(id, :deliver) end |
#delivery ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/models/pager_tree/integrations/outgoing_webhook_delivery/hook_relay.rb', line 74 def delivery return @delivery if @delivery return {} unless thirdparty_id = { headers: { "Content-Type": "application/json", Authorization: "Bearer #{OutgoingWebhookDelivery::HookRelay.hook_relay_api_key}" }, timeout: 15 } response = ::HTTParty.get(hook_relay_delivery_url, **) @delivery = response.parsed_response if response.success? @delivery || {} end |
#hook_relay_delivery_url ⇒ Object
23 24 25 |
# File 'app/models/pager_tree/integrations/outgoing_webhook_delivery/hook_relay.rb', line 23 def hook_relay_delivery_url "https://app.hookrelay.dev/api/v1/accounts/#{OutgoingWebhookDelivery::HookRelay.hook_relay_account_id}/hooks/#{OutgoingWebhookDelivery::HookRelay.hook_relay_hook_id}/deliveries/#{thirdparty_id}" end |
#hook_relay_hook_url ⇒ Object
19 20 21 |
# File 'app/models/pager_tree/integrations/outgoing_webhook_delivery/hook_relay.rb', line 19 def hook_relay_hook_url "https://api.hookrelay.dev/hooks/#{OutgoingWebhookDelivery::HookRelay.hook_relay_account_id}/#{OutgoingWebhookDelivery::HookRelay.hook_relay_hook_id}" end |
#request ⇒ Object
92 93 94 |
# File 'app/models/pager_tree/integrations/outgoing_webhook_delivery/hook_relay.rb', line 92 def request delivery&.dig("request") || {} end |
#responses ⇒ Object
96 97 98 |
# File 'app/models/pager_tree/integrations/outgoing_webhook_delivery/hook_relay.rb', line 96 def responses delivery&.dig("responses") || [] end |