Class: GTM::Push
- Inherits:
-
Object
- Object
- GTM::Push
- Defined in:
- lib/gtm/push.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
-
#initialize(client) ⇒ Push
constructor
A new instance of Push.
- #run ⇒ Object
Constructor Details
#initialize(client) ⇒ Push
Returns a new instance of Push.
11 12 13 |
# File 'lib/gtm/push.rb', line 11 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
9 10 11 |
# File 'lib/gtm/push.rb', line 9 def client @client end |
Instance Method Details
#run ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gtm/push.rb', line 15 def run tag_file_origin = "#{@client.scope[:account_id]}/#{@client.scope[:container_name]}/tags/#{@client.scope[:tag_file]}" tag_file = tag_file_origin.gsub(/\.json$/, '') data = File.read("#{@client.scope[:path]}.dump/meta/#{tag_file}.dump") tag = Marshal.load(data) if tag tag_content = File.read("#{@client.scope[:path]}#{tag_file_origin}") body = tag if %w(ua html).include?(tag['type']) # dumpable types if tag['type'].eql?('ua') body['parameter'] = JSON.parse(tag_content) elsif tag['type'].eql?('html') body['parameter'].each do |parameter| parameter['value'] = tag_content if parameter['key'].eql?('html') end end @client.run do |_accounts| print "pushing tag #{"#{@client.scope[:path]}#{tag_file_origin}"} for account #{tag['accountId']} into container #{tag['containerId']} " result = @client.client.execute( api_method: @client.gtm.accounts.containers..update, parameters: { accountId: tag['accountId'], containerId: tag['containerId'], tagId: tag['tagId'] }, body_object: body ) puts '[OK]' end end end end |