Class: Nylas::Tunnel
- Inherits:
-
Object
- Object
- Nylas::Tunnel
- Defined in:
- lib/nylas/services/tunnel.rb
Overview
Class containing methods to spin up a developmental websocket connection to test webhooks
Class Method Summary collapse
-
.open_webhook_tunnel(api, config = {}) ⇒ Object
Open a webhook tunnel and register it with the Nylas API 1.
-
.register_webhook_callback(api, callback_domain, tunnel_path, triggers) ⇒ Nylas::Webhook
Register callback with the Nylas forwarding service which will pass messages to the websocket.
Class Method Details
.open_webhook_tunnel(api, config = {}) ⇒ Object
Open a webhook tunnel and register it with the Nylas API
-
Creates a UUID
-
Opens a websocket connection to Nylas’ webhook forwarding service, with the UUID as a header
-
Creates a new webhook pointed at the forwarding service with the UUID as the path
When an event is received by the forwarding service, it will push directly to this websocket connection
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/nylas/services/tunnel.rb', line 19 def self.open_webhook_tunnel(api, config = {}) tunnel_id = SecureRandom.uuid triggers = config[:triggers] || WebhookTrigger.constants(false).map { |c| WebhookTrigger.const_get c } region = config[:region] || "us" websocket_domain = "tunnel.nylas.com" callback_domain = "cb.nylas.com" EM.run do setup_websocket_client(websocket_domain, api, tunnel_id, region, config) register_webhook_callback(api, callback_domain, tunnel_id, triggers) end end |
.register_webhook_callback(api, callback_domain, tunnel_path, triggers) ⇒ Nylas::Webhook
Register callback with the Nylas forwarding service which will pass messages to the websocket
38 39 40 41 42 43 44 45 46 |
# File 'lib/nylas/services/tunnel.rb', line 38 def self.register_webhook_callback(api, callback_domain, tunnel_path, triggers) callback_url = "https://#{callback_domain}/#{tunnel_path}" api.webhooks.create( callback_url: callback_url, state: WebhookState::ACTIVE, triggers: triggers ) end |