Class: ShopifyApp::ScripttagsManager

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

Defined Under Namespace

Classes: CreationFailed

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shop_name, token) ⇒ ScripttagsManager

Returns a new instance of ScripttagsManager.



9
10
11
# File 'lib/shopify_app/scripttags_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/scripttags_manager.rb', line 5

def self.queue(shop_name, token)
  ShopifyApp::ScripttagsManagerJob.perform_later(shop_name: shop_name, token: token)
end

Instance Method Details

#create_scripttagsObject



18
19
20
21
22
23
24
25
26
# File 'lib/shopify_app/scripttags_manager.rb', line 18

def create_scripttags
  return unless required_scripttags.present?

  with_shopify_session do
    required_scripttags.each do |scripttag|
      create_scripttag(scripttag) unless scripttag_exists?(scripttag[:src])
    end
  end
end

#destroy_scripttagsObject



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

def destroy_scripttags
  with_shopify_session do
    ShopifyAPI::ScriptTag.all.each do |scripttag|
      ShopifyAPI::ScriptTag.delete(scripttag.id) if is_required_scripttag?(scripttag)
    end
  end
  @current_scripttags = nil
end

#recreate_scripttags!Object



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

def recreate_scripttags!
  destroy_scripttags
  create_scripttags
end