Class: ShopifyApp::WebhooksManager

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

Class Method Summary collapse

Class Method Details

.add_registrationsObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/shopify_app/managers/webhooks_manager.rb', line 37

def add_registrations
  return unless ShopifyApp.configuration.has_webhooks?

  ShopifyApp.configuration.webhooks.each do |attributes|
    webhook_path = path(attributes)

    ShopifyAPI::Webhooks::Registry.add_registration(
      topic: attributes[:topic],
      delivery_method: attributes[:delivery_method] || :http,
      path: webhook_path,
      handler: webhook_job_klass(webhook_path),
      fields: attributes[:fields],
    )
  end
end

.create_webhooks(session:) ⇒ Object



15
16
17
18
19
# File 'lib/shopify_app/managers/webhooks_manager.rb', line 15

def create_webhooks(session:)
  return unless ShopifyApp.configuration.has_webhooks?

  ShopifyAPI::Webhooks::Registry.register_all(session: session)
end

.destroy_webhooksObject



29
30
31
32
33
34
35
# File 'lib/shopify_app/managers/webhooks_manager.rb', line 29

def destroy_webhooks
  return unless ShopifyApp.configuration.has_webhooks?

  ShopifyApp.configuration.webhooks.each do |attributes|
    ShopifyAPI::Webhooks::Registry.unregister(topic: attributes[:topic])
  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



21
22
23
24
25
26
27
# File 'lib/shopify_app/managers/webhooks_manager.rb', line 21

def recreate_webhooks!(session:)
  destroy_webhooks
  return unless ShopifyApp.configuration.has_webhooks?

  add_registrations
  ShopifyAPI::Webhooks::Registry.register_all(session: session)
end