class GTM::Push
Attributes
client[RW]
Public Class Methods
new(client)
click to toggle source
# File lib/gtm/push.rb, line 11 def initialize(client) @client = client end
Public Instance Methods
run()
click to toggle source
# 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.tags.update, parameters: { accountId: tag['accountId'], containerId: tag['containerId'], tagId: tag['tagId'] }, body_object: body ) puts '[OK]' end end end end