Class: IntercomApp::WebhooksManager

Inherits:
Object
  • Object
show all
Defined in:
lib/intercom-app/webhooks_manager.rb

Defined Under Namespace

Classes: CreationFailed

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ WebhooksManager

Returns a new instance of WebhooksManager.



4
5
6
# File 'lib/intercom-app/webhooks_manager.rb', line 4

def initialize(params)
  @intercom_token = params[:intercom_token]
end

Instance Method Details

#create_webhooks_subscriptionsObject



8
9
10
11
12
13
# File 'lib/intercom-app/webhooks_manager.rb', line 8

def create_webhooks_subscriptions
  return unless required_webhooks.present?
  required_webhooks.each do |webhook|
    create_webhook_subscription(webhook) unless webhook_subscription_exists?(webhook[:topics])
  end
end

#destroy_webhooks_subscriptionsObject



15
16
17
18
19
20
21
# File 'lib/intercom-app/webhooks_manager.rb', line 15

def destroy_webhooks_subscriptions
  intercom_client.subscriptions.all.each do |webhook|
    intercom_client.subscriptions.delete(webhook.id) if is_required_webhook?(webhook)
  end

  @current_webhooks_subscriptions = nil
end

#recreate_webhooks_subscriptions!Object



23
24
25
26
# File 'lib/intercom-app/webhooks_manager.rb', line 23

def recreate_webhooks_subscriptions!
  destroy_webhooks_subscriptions
  create_webhooks_subscriptions
end