Class: DuodealerApp::WebhooksManager
- Inherits:
-
Object
- Object
- DuodealerApp::WebhooksManager
- Defined in:
- lib/duodealer_app/managers/webhooks_manager.rb
Defined Under Namespace
Classes: CreationFailed
Instance Attribute Summary collapse
-
#required_webhooks ⇒ Object
readonly
Returns the value of attribute required_webhooks.
Class Method Summary collapse
Instance Method Summary collapse
- #create_webhooks ⇒ Object
- #destroy_webhooks ⇒ Object
-
#initialize(webhooks) ⇒ WebhooksManager
constructor
A new instance of WebhooksManager.
- #recreate_webhooks! ⇒ Object
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_webhooks ⇒ Object (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(account_domain, account_token, webhooks) DuodealerApp::WebhooksManagerJob.perform_later( account_domain: account_domain, account_token: account_token, webhooks: webhooks ) end |
Instance Method Details
#create_webhooks ⇒ Object
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_webhooks ⇒ Object
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 |