Class: DuodealerApp::WebhooksManager

Inherits:
Object
  • Object
show all
Defined in:
lib/duodealer_app/managers/webhooks_manager.rb

Defined Under Namespace

Classes: CreationFailed

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(webhooks) ⇒ WebhooksManager

Returns a new instance of WebhooksManager.



17
18
19
# File 'lib/duodealer_app/managers/webhooks_manager.rb', line 17

def initialize(webhooks)
  @required_webhooks = webhooks
end

Instance Attribute Details

#required_webhooksObject (readonly)

Returns the value of attribute required_webhooks.



15
16
17
# File 'lib/duodealer_app/managers/webhooks_manager.rb', line 15

def required_webhooks
  @required_webhooks
end

Class Method Details

.queue(account_domain, account_token, webhooks) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/duodealer_app/managers/webhooks_manager.rb', line 7

def self.queue(, , webhooks)
  DuodealerApp::WebhooksManagerJob.perform_later(
    account_domain: ,
    account_token: ,
    webhooks: webhooks
  )
end

Instance Method Details

#create_webhooksObject



26
27
28
29
30
31
32
# File 'lib/duodealer_app/managers/webhooks_manager.rb', line 26

def create_webhooks
  return if required_webhooks.blank?

  required_webhooks.each do |webhook|
    create_webhook(webhook) unless webhook_exists?(webhook[:topic])
  end
end

#destroy_webhooksObject



34
35
36
37
38
39
40
# File 'lib/duodealer_app/managers/webhooks_manager.rb', line 34

def destroy_webhooks
  DuodealerAPI::Webhook.all.to_a.each do |webhook|
    DuodealerAPI::Webhook.delete(webhook.id) if is_required_webhook?(webhook)
  end

  @current_webhooks = nil
end

#recreate_webhooks!Object



21
22
23
24
# File 'lib/duodealer_app/managers/webhooks_manager.rb', line 21

def recreate_webhooks!
  destroy_webhooks
  create_webhooks
end