Class: ShopifyApp::WebhooksManager
- Inherits:
-
Object
- Object
- ShopifyApp::WebhooksManager
- Defined in:
- lib/shopify_app/managers/webhooks_manager.rb
Class Method Summary collapse
- .add_registrations ⇒ Object
- .create_webhooks(session:) ⇒ Object
- .destroy_webhooks(session:) ⇒ Object
- .queue(shop_domain, shop_token) ⇒ Object
- .recreate_webhooks!(session:) ⇒ Object
Class Method Details
.add_registrations ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/shopify_app/managers/webhooks_manager.rb', line 41 def add_registrations return unless ShopifyApp.configuration.has_webhooks? ShopifyApp::Logger.debug("Adding registrations to webhooks") ShopifyApp.configuration.webhooks.each do |attributes| webhook_path = path(attributes) delivery_method = attributes[:delivery_method] || :http ShopifyAPI::Webhooks::Registry.add_registration( topic: attributes[:topic], delivery_method: delivery_method, path: webhook_path, handler: delivery_method == :http ? webhook_job_klass(webhook_path) : nil, fields: attributes[:fields], metafield_namespaces: attributes[:metafield_namespaces], ) end end |
.create_webhooks(session:) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/shopify_app/managers/webhooks_manager.rb', line 15 def create_webhooks(session:) return unless ShopifyApp.configuration.has_webhooks? ShopifyApp::Logger.debug("Creating webhooks #{ShopifyApp.configuration.webhooks}") ShopifyAPI::Webhooks::Registry.register_all(session: session) end |
.destroy_webhooks(session:) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/shopify_app/managers/webhooks_manager.rb', line 32 def destroy_webhooks(session:) return unless ShopifyApp.configuration.has_webhooks? ShopifyApp::Logger.debug("Destroying webhooks") ShopifyApp.configuration.webhooks.each do |attributes| ShopifyAPI::Webhooks::Registry.unregister(topic: attributes[:topic], session: session) end end |
.queue(shop_domain, shop_token) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/shopify_app/managers/webhooks_manager.rb', line 8 def queue(shop_domain, shop_token) ShopifyApp::WebhooksManagerJob.perform_later( shop_domain: shop_domain, shop_token: shop_token, ) end |
.recreate_webhooks!(session:) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/shopify_app/managers/webhooks_manager.rb', line 23 def recreate_webhooks!(session:) destroy_webhooks(session: session) return unless ShopifyApp.configuration.has_webhooks? ShopifyApp::Logger.debug("Recreating webhooks") add_registrations create_webhooks(session: session) end |