Class: ShopifyApp::WebhooksManager

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

Defined Under Namespace

Classes: CreationFailed

Class Method Summary collapse

Class Method Details

.add_registrationsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/shopify_app/managers/webhooks_manager.rb', line 35

def add_registrations
  return unless ShopifyApp.configuration.has_webhooks?

  ShopifyApp.configuration.webhooks.each do |attributes|
    ShopifyAPI::Webhooks::Registry.add_registration(
      topic: attributes[:topic],
      delivery_method: attributes[:delivery_method] || :http,
      path: attributes[:address],
      handler: webhook_job_klass(attributes[:topic]),
      fields: attributes[:fields]
    )
  end
end

.create_webhooks(session:) ⇒ Object



15
16
17
18
# 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



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

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



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

def recreate_webhooks!(session:)
  destroy_webhooks
  return unless ShopifyApp.configuration.has_webhooks?
  add_registrations
  ShopifyAPI::Webhooks::Registry.register_all(session: session)
end