Class: ShopifyApp::WebhooksManager
- Inherits:
-
Object
- Object
- ShopifyApp::WebhooksManager
- Defined in:
- lib/ruby_shopify_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.
16 17 18 |
# File 'lib/ruby_shopify_app/managers/webhooks_manager.rb', line 16 def initialize(webhooks) @required_webhooks = webhooks end |
Instance Attribute Details
#required_webhooks ⇒ Object (readonly)
Returns the value of attribute required_webhooks.
14 15 16 |
# File 'lib/ruby_shopify_app/managers/webhooks_manager.rb', line 14 def required_webhooks @required_webhooks end |
Class Method Details
.queue(shop_domain, shop_token, webhooks) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/ruby_shopify_app/managers/webhooks_manager.rb', line 6 def self.queue(shop_domain, shop_token, webhooks) ShopifyApp::WebhooksManagerJob.perform_later( shop_domain: shop_domain, shop_token: shop_token, webhooks: webhooks ) end |
Instance Method Details
#create_webhooks ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/ruby_shopify_app/managers/webhooks_manager.rb', line 25 def create_webhooks return unless required_webhooks.present? required_webhooks.each do |webhook| create_webhook(webhook) unless webhook_exists?(webhook[:topic]) end end |
#destroy_webhooks ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/ruby_shopify_app/managers/webhooks_manager.rb', line 33 def destroy_webhooks ShopifyAPI::Webhook.all.to_a.each do |webhook| ShopifyAPI::Webhook.delete(webhook.id) if required_webhook?(webhook) end @current_webhooks = nil end |
#recreate_webhooks! ⇒ Object
20 21 22 23 |
# File 'lib/ruby_shopify_app/managers/webhooks_manager.rb', line 20 def recreate_webhooks! destroy_webhooks create_webhooks end |