Class: ShopifyApp::WebhooksManager
- Inherits:
-
Object
- Object
- ShopifyApp::WebhooksManager
- Defined in:
- lib/shopify_app/webhooks_manager.rb
Defined Under Namespace
Classes: CreationFailed
Class Method Summary collapse
Instance Method Summary collapse
- #create_webhooks ⇒ Object
- #destroy_webhooks ⇒ Object
-
#initialize(shop_name, token) ⇒ WebhooksManager
constructor
A new instance of WebhooksManager.
- #recreate_webhooks! ⇒ Object
Constructor Details
#initialize(shop_name, token) ⇒ WebhooksManager
Returns a new instance of WebhooksManager.
9 10 11 |
# File 'lib/shopify_app/webhooks_manager.rb', line 9 def initialize(shop_name, token) @shop_name, @token = shop_name, token end |
Class Method Details
.queue(shop_name, token) ⇒ Object
5 6 7 |
# File 'lib/shopify_app/webhooks_manager.rb', line 5 def self.queue(shop_name, token) ShopifyApp::WebhooksManagerJob.perform_later(shop_name: shop_name, token: token) end |
Instance Method Details
#create_webhooks ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/shopify_app/webhooks_manager.rb', line 18 def create_webhooks return unless required_webhooks.present? with_shopify_session do required_webhooks.each do |webhook| create_webhook(webhook) unless webhook_exists?(webhook[:topic]) end end end |
#destroy_webhooks ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/shopify_app/webhooks_manager.rb', line 28 def destroy_webhooks with_shopify_session do ShopifyAPI::Webhook.all.each do |webhook| ShopifyAPI::Webhook.delete(webhook.id) if is_required_webhook?(webhook) end end @current_webhooks = nil end |
#recreate_webhooks! ⇒ Object
13 14 15 16 |
# File 'lib/shopify_app/webhooks_manager.rb', line 13 def recreate_webhooks! destroy_webhooks create_webhooks end |