gtm-cli 0.1.3 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff4d60b4559a4df73c96e6408cc0cdbc0a3bc068
4
- data.tar.gz: f213398cd1e329b27b3350c13f51cd8e1f074c0d
3
+ metadata.gz: 032d0ea69efdaeb3578392fa8b6c3e34d4c2ac71
4
+ data.tar.gz: 2968ef86c27f4cad8c2397000580bc21088d0b51
5
5
  SHA512:
6
- metadata.gz: b3e18ba725f8cda598cb046618dc49ef8e89dc8a1b15948900bf02f3331e83a1c6f6b92ee8b9ea1e2294aed78baed8caf86372d43696224772cbfeaf7b93f388
7
- data.tar.gz: b7b20f116d79e86f00ced1005c189e34de6fdb65363109950347e54f632bfcaee5297839819c11690a440a2b6cbe4f98dedad6e2a59ffdb4003deb8ad2c1c2ec
6
+ metadata.gz: 0aa17dc5393898986b9f6cbec04ccc13907e4566001ba0109f96080a85dfcd45918987e635e9ed5df4c482492baa4352e3583757d07e9bf8838b2af0a30d446f
7
+ data.tar.gz: 6016f017280980ce3c261f435d4457437d9021ecadcc5c3d44277a634ba7a45ac3000f32282a5a003a6fedba1164dfc4744771949ffb20b32374816b568f1bad
data/lib/gtm/pull.rb CHANGED
@@ -74,13 +74,22 @@ module GTM
74
74
  print "pulling tags from account #{container['accountId']} into #{tags_path} "
75
75
  tags.each do |tag|
76
76
  tag_name = tag['name'].parameterize.underscore
77
- html_parameter = tag.parameter.select { |p| p.key.eql? 'html' }.first
78
- if html_parameter
79
- File.open("#{tags_path}/#{tag_name}.#{html_parameter.key}", 'w') do |f|
80
- f.write html_parameter.value
77
+ if %w(ua html).include?(tag.type) # dumpable types
78
+ suffix = ''
79
+ if tag.type.eql?('ua')
80
+ value = tag.parameter.to_json
81
+ suffix = '.json'
82
+ elsif tag.type.eql?('html') and false
83
+ html_parameter = tag.parameter.select { |p| p.key.eql? 'html' }.first
84
+ value = html_parameter.value
81
85
  end
86
+ # EDITABLE CONTENT
87
+ File.open("#{tags_path}/#{tag_name}.#{tag.type}#{suffix}", 'w') do |f|
88
+ f.write value
89
+ end
90
+ # DUMP
82
91
  data = Marshal.dump(tag.to_hash)
83
- File.open("#{meta_tags_path}/#{tag_name}.#{html_parameter.key}.dump", 'w') do |f|
92
+ File.open("#{meta_tags_path}/#{tag_name}.#{tag.type}.dump", 'w') do |f|
84
93
  f.write data
85
94
  end
86
95
  print '.'
data/lib/gtm/push.rb CHANGED
@@ -13,28 +13,36 @@ module GTM
13
13
  end
14
14
 
15
15
  def run
16
- tag_file = "#{@client.scope[:account_id]}/#{@client.scope[:container_name]}/tags/#{@client.scope[:tag_file]}"
16
+ tag_file_origin = "#{@client.scope[:account_id]}/#{@client.scope[:container_name]}/tags/#{@client.scope[:tag_file]}"
17
+ tag_file = tag_file_origin.gsub(/\.json$/, '')
17
18
  data = File.read("#{@client.scope[:path]}.dump/meta/#{tag_file}.dump")
18
19
  tag = Marshal.load(data)
19
- tag_content = File.read("#{@client.scope[:path]}#{tag_file}")
20
- body = tag
21
- body['parameter'].each do |parameter|
22
- parameter['value'] = tag_content if parameter['key'].eql?('html')
23
- end
24
- @client.run do |_accounts|
25
- print "pushing tag #{"#{@client.scope[:path]}#{tag_file}"} for account #{tag['accountId']} into container #{tag['containerId']} "
26
- result = @client.client.execute(
27
- api_method: @client.gtm.accounts.containers.tags.update,
28
- parameters: {
29
- accountId: tag['accountId'],
30
- containerId: tag['containerId'],
31
- tagId: tag['tagId']
32
- },
33
- body_object: body
34
- )
35
- puts '[OK]'
20
+ if tag
21
+ tag_content = File.read("#{@client.scope[:path]}#{tag_file_origin}")
22
+ body = tag
23
+ if %w(ua html).include?(tag['type']) # dumpable types
24
+ if tag['type'].eql?('ua')
25
+ body['parameter'] = JSON.parse(tag_content)
26
+ elsif tag['type'].eql?('html') and false
27
+ body['parameter'].each do |parameter|
28
+ parameter['value'] = tag_content if parameter['key'].eql?('html')
29
+ end
30
+ end
31
+ @client.run do |_accounts|
32
+ print "pushing tag #{"#{@client.scope[:path]}#{tag_file_origin}"} for account #{tag['accountId']} into container #{tag['containerId']} "
33
+ result = @client.client.execute(
34
+ api_method: @client.gtm.accounts.containers.tags.update,
35
+ parameters: {
36
+ accountId: tag['accountId'],
37
+ containerId: tag['containerId'],
38
+ tagId: tag['tagId']
39
+ },
40
+ body_object: body
41
+ )
42
+ puts '[OK]'
43
+ end
44
+ end
36
45
  end
37
46
  end
38
47
  end
39
48
  end
40
-
data/lib/gtm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module GTM
2
- VERSION = '0.1.3'
2
+ VERSION = '0.2.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gtm-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Dudda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-26 00:00:00.000000000 Z
11
+ date: 2016-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-api-client