Class: ShopifyApp::WebhooksManager

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

Defined Under Namespace

Classes: CreationFailed

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(webhooks) ⇒ WebhooksManager

Returns a new instance of WebhooksManager.



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

def initialize(webhooks)
  @required_webhooks = webhooks
end

Instance Attribute Details

#required_webhooksObject (readonly)

Returns the value of attribute required_webhooks.



13
14
15
# File 'lib/shopify_app/webhooks_manager.rb', line 13

def required_webhooks
  @required_webhooks
end

Class Method Details

.queue(shop_domain, shop_token, webhooks) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/shopify_app/webhooks_manager.rb', line 5

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_webhooksObject



24
25
26
27
28
29
30
# File 'lib/shopify_app/webhooks_manager.rb', line 24

def create_webhooks
  return unless required_webhooks.present?

  required_webhooks.each do |webhook|
    create_webhook(webhook) unless webhook_exists?(webhook[:topic])
  end
end

#destroy_webhooksObject



32
33
34
35
36
37
38
# File 'lib/shopify_app/webhooks_manager.rb', line 32

def destroy_webhooks
  ShopifyAPI::Webhook.all.each do |webhook|
    ShopifyAPI::Webhook.delete(webhook.id) if is_required_webhook?(webhook)
  end

  @current_webhooks = nil
end

#recreate_webhooks!Object



19
20
21
22
# File 'lib/shopify_app/webhooks_manager.rb', line 19

def recreate_webhooks!
  destroy_webhooks
  create_webhooks
end