apollo_commons_ruby 0.7.0

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.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/CODE_OF_CONDUCT.md +74 -0
  4. data/Gemfile +6 -0
  5. data/Gemfile.lock +19 -0
  6. data/README.md +40 -0
  7. data/Rakefile +2 -0
  8. data/apollo_commons_ruby-0.2.0.gem +0 -0
  9. data/apollo_commons_ruby-0.3.0.gem +0 -0
  10. data/apollo_commons_ruby-0.4.0.gem +0 -0
  11. data/apollo_commons_ruby-0.5.0.gem +0 -0
  12. data/apollo_commons_ruby-0.6.0.gem +0 -0
  13. data/apollo_commons_ruby.gemspec +26 -0
  14. data/bin/console +14 -0
  15. data/bin/setup +8 -0
  16. data/lib/apollo_commons_ruby.rb +34 -0
  17. data/lib/apollo_commons_ruby/DomainEvent.rb +122 -0
  18. data/lib/apollo_commons_ruby/FileUtils.rb +41 -0
  19. data/lib/apollo_commons_ruby/MarioEvent.rb +45 -0
  20. data/lib/apollo_commons_ruby/NetworkUtils.rb +67 -0
  21. data/lib/apollo_commons_ruby/Operation.rb +4 -0
  22. data/lib/apollo_commons_ruby/ResolveTemplate.rb +53 -0
  23. data/lib/apollo_commons_ruby/SecretConfig.rb +15 -0
  24. data/lib/apollo_commons_ruby/TemplateBuilder.rb +26 -0
  25. data/lib/apollo_commons_ruby/TemplatesHelper.rb +814 -0
  26. data/lib/apollo_commons_ruby/TemplatesRakefile.rb +816 -0
  27. data/lib/apollo_commons_ruby/ViewGroup.rb +62 -0
  28. data/lib/apollo_commons_ruby/ViewGroupComponent.rb +66 -0
  29. data/lib/apollo_commons_ruby/ViewGroupDefinition.rb +61 -0
  30. data/lib/tasks/add_translations.rake +9 -0
  31. data/lib/tasks/checkValidJson.rake +17 -0
  32. data/lib/tasks/delete_domain_event.rake +7 -0
  33. data/lib/tasks/delete_view_group.rake +7 -0
  34. data/lib/tasks/delete_view_group_component.rake +7 -0
  35. data/lib/tasks/delete_view_group_definition.rake +7 -0
  36. data/lib/tasks/deploy_all_templates.rake +7 -0
  37. data/lib/tasks/runTests.rake +27 -0
  38. data/lib/tasks/update_all.rake +36 -0
  39. data/lib/tasks/update_all_domain_events.rake +24 -0
  40. data/lib/tasks/update_all_view_group_components.rake +18 -0
  41. data/lib/tasks/update_domain_event.rake +11 -0
  42. data/lib/tasks/update_one_template.rake +42 -0
  43. data/lib/tasks/update_translations.rake +24 -0
  44. data/lib/tasks/update_view_group_component.rake +9 -0
  45. data/lib/tasks/update_view_group_definition.rake +7 -0
  46. data/lib/tasks/update_view_group_for_user_0.rake +36 -0
  47. data/lib/version.rb +3 -0
  48. metadata +91 -0
@@ -0,0 +1,67 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'openssl'
5
+ require 'base64'
6
+
7
+ def make_PUT_request (url, body, authtoken)
8
+ if authtoken == nil
9
+ authtoken = ""
10
+ end
11
+ uri = URI.parse(url)
12
+ http = Net::HTTP.new(uri.host, uri.port)
13
+ http.use_ssl = true
14
+ request = Net::HTTP::Put.new(uri.request_uri,
15
+ initheader = {
16
+ 'Content-Type' =>'application/json',
17
+ 'X-Zeta-AuthToken' => authtoken
18
+ })
19
+ request.body = body
20
+
21
+ puts "#{uri}\n\n"
22
+ puts "#{request.body}\n\n"
23
+ response = http.request(request)
24
+ puts "#{response.body}"
25
+ return response.body
26
+ end
27
+
28
+ def make_POST_request (url, body, authtoken)
29
+ if authtoken == nil
30
+ authtoken = ""
31
+ end
32
+ uri = URI.parse(url)
33
+ http = Net::HTTP.new(uri.host, uri.port)
34
+ http.use_ssl = true
35
+ request = Net::HTTP::Post.new(uri.request_uri,
36
+ initheader = {
37
+ 'Content-Type' =>'application/json',
38
+ 'X-Zeta-AuthToken' => authtoken
39
+ })
40
+ request.body = body
41
+
42
+ puts "#{uri}\n\n"
43
+ puts "#{request.body}\n\n"
44
+ response = http.request(request)
45
+ puts "#{response.body}"
46
+ return response.body
47
+ end
48
+
49
+ def make_DELETE_request (url, authtoken)
50
+ if authtoken == nil
51
+ authtoken = ""
52
+ end
53
+ uri = URI.parse(url)
54
+
55
+ http = Net::HTTP.new(uri.host, uri.port)
56
+ http.use_ssl = true
57
+ request = Net::HTTP::Delete.new(uri.request_uri,
58
+ initheader = {
59
+ 'Content-Type' =>'application/json',
60
+ 'X-Zeta-AuthToken' => authtoken
61
+ })
62
+
63
+ puts "#{uri}\n\n"
64
+ response = http.request(request)
65
+ puts "#{response.body}"
66
+ return response.body
67
+ end
@@ -0,0 +1,4 @@
1
+ module Operation
2
+ PUT = 1
3
+ DELETE = 2
4
+ end
@@ -0,0 +1,53 @@
1
+ require 'v8'
2
+ require 'rubygems'
3
+ require_relative 'TemplatesHelper'
4
+
5
+ class ResolveTemplate
6
+
7
+ def initialize
8
+ @context = V8::Context.new
9
+ @context.load("./scripts/underscore-min.js")
10
+ @context.eval("var generateTemplatedStringEnv = function(templateString, dataObject) { _.templateSettings = { interpolate: /\{\{(.+?)\}\}/g }; var compiledWithEnv = _.template(templateString); return compiledWithEnv(dataObject);}")
11
+ @context.eval("var generateTemplatedStringLang = function(templateString, dataObject) { _.templateSettings = { interpolate: /\<\<(.+?)\>\>/g }; var compiledWithLang = _.template(templateString); return compiledWithLang(dataObject);}")
12
+ end
13
+
14
+ def resolve(data_template, configuration)
15
+ envFilePath = configuration.env_data_file_path
16
+ envData = read_data_from_file_path(envFilePath)
17
+ envData = JSON.parse(envData)
18
+ function = @context[:generateTemplatedStringEnv];
19
+ begin
20
+ data_template = data_template.force_encoding("UTF-8")
21
+ function.call(data_template, envData)
22
+ rescue Exception => e
23
+ puts "\n", e.cause, e.javascript_backtrace;
24
+ end
25
+ end
26
+
27
+ def resolveEnv(data_template, configuration, tenant_id, project_id)
28
+ envFilePath = configuration.env_file_path(tenant_id, project_id)
29
+ envData = read_data_from_file_path(envFilePath)
30
+ envData = JSON.parse(envData)
31
+ function = @context[:generateTemplatedStringEnv];
32
+ begin
33
+ data_template = data_template.force_encoding("UTF-8")
34
+ function.call(data_template, envData)
35
+ rescue Exception => e
36
+ puts "\n", e.cause, e.javascript_backtrace;
37
+ end
38
+ end
39
+
40
+ def resolveLang(data_template, configuration, language)
41
+ langFilePath = configuration.language_file_path_for_template(language)
42
+ langData = read_res_data_from_file_path(langFilePath)
43
+ langData = JSON.parse(langData)
44
+ function = @context[:generateTemplatedStringLang];
45
+ begin
46
+ data_template = data_template.force_encoding("UTF-8")
47
+ function.call(data_template, langData)
48
+ rescue Exception => e
49
+ puts "\n", e.cause, e.javascript_backtrace;
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,15 @@
1
+ class SecretConfig
2
+
3
+ attr_reader :authToken
4
+
5
+ def initialize(environment)
6
+ conf_file = File.read(File.expand_path("/var/jenkins_home/template_config/config.json"));
7
+ conf = JSON.parse conf_file
8
+ conf = conf[environment.downcase]
9
+ if (conf["authToken"] == nil)
10
+ puts "Security configurations are missing"
11
+ return nil
12
+ end
13
+ @authToken = conf["authToken"]
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ require 'v8'
2
+
3
+ class TemplateBuilder
4
+
5
+ def initialize
6
+ @context = V8::Context.new
7
+ @context.load("scripts/underscore-min.js")
8
+ @context.eval("var generateTemplatedString = function(templateString, dataObject) { var compiled = _.template(templateString); return compiled(dataObject);}")
9
+ end
10
+
11
+ def build(data_template, data, os)
12
+ function = @context[:generateTemplatedString];
13
+ begin
14
+ data_template = data_template.force_encoding("UTF-8")
15
+ if os == "android"
16
+ @context.eval( "var compiledTemplate = _.template(' " + data_template + "');" + "compiledTemplate(" + data.to_json + ");")
17
+ else
18
+ function.call(data_template, data)
19
+ end
20
+
21
+ rescue Exception => e
22
+ puts "\n", e.causes, e.javascript_backtrace;
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,814 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'openssl'
5
+ require 'base64'
6
+ require_relative 'SecretConfig'
7
+
8
+ module HTTP
9
+ GET = 1
10
+ POST = 2
11
+ end
12
+
13
+ class String
14
+ def black; "\e[30m#{self}\e[0m" end
15
+ def red; "\e[31m#{self}\e[0m" end
16
+ def green; "\e[32m#{self}\e[0m" end
17
+ def brown; "\e[33m#{self}\e[0m" end
18
+ def blue; "\e[34m#{self}\e[0m" end
19
+ def magenta; "\e[35m#{self}\e[0m" end
20
+ def cyan; "\e[36m#{self}\e[0m" end
21
+ def gray; "\e[37m#{self}\e[0m" end
22
+
23
+ def bg_black; "\e[40m#{self}\e[0m" end
24
+ def bg_red; "\e[41m#{self}\e[0m" end
25
+ def bg_green; "\e[42m#{self}\e[0m" end
26
+ def bg_brown; "\e[43m#{self}\e[0m" end
27
+ def bg_blue; "\e[44m#{self}\e[0m" end
28
+ def bg_magenta; "\e[45m#{self}\e[0m" end
29
+ def bg_cyan; "\e[46m#{self}\e[0m" end
30
+ def bg_gray; "\e[47m#{self}\e[0m" end
31
+
32
+ def bold; "\e[1m#{self}\e[22m" end
33
+ def italic; "\e[3m#{self}\e[23m" end
34
+ def underline; "\e[4m#{self}\e[24m" end
35
+ def blink; "\e[5m#{self}\e[25m" end
36
+ def reverse_color; "\e[7m#{self}\e[27m" end
37
+ end
38
+
39
+ class LineReplacementProperties
40
+
41
+ attr_reader :file_path
42
+ attr_reader :redundant_line_prefix
43
+ attr_reader :updated_line
44
+
45
+ def initialize(file_path, redundant_line_prefix, updated_line)
46
+ @file_path = file_path
47
+ @redundant_line_prefix = redundant_line_prefix
48
+ @updated_line = updated_line
49
+ end
50
+ end
51
+
52
+ class TemplateMapping
53
+
54
+ def initialize(template_name, template_path, template_mapping)
55
+ @template_name = template_name
56
+ @template_path = template_path
57
+ @template_mapping = template_mapping
58
+ end
59
+
60
+ def create_hash
61
+ {
62
+ "template_name"=> @template_name,
63
+ "template_path"=> @template_path,
64
+ "template_mapping"=> @template_mapping
65
+ }
66
+ end
67
+
68
+ def create_mapping
69
+ {
70
+ @template_mapping => @template_name
71
+ }
72
+ end
73
+ end
74
+
75
+ class Template
76
+
77
+ attr_reader :data_template
78
+
79
+ def initialize(template_name, default_content, data_template, presentation, attrs)
80
+ @default_content = default_content
81
+ @data_template = data_template
82
+ @presentation = presentation
83
+ @template_name = template_name
84
+ @attrs = attrs
85
+ end
86
+
87
+ def create_hash
88
+ {
89
+ @template_name => {
90
+ "defaultContent"=> @default_content,
91
+ "dataTemplateBase64"=> @data_template,
92
+ "presentationBase64"=> @presentation,
93
+ "attrs"=> @attrs
94
+ }
95
+ }
96
+ end
97
+
98
+ end
99
+
100
+ class CreateTemplatePayload
101
+ def initialize(template_group, language, view, templates, version)
102
+ @template_group = template_group
103
+ @language = language
104
+ @view = view
105
+ @templates = templates
106
+ @version = version
107
+ end
108
+
109
+ def to_json
110
+ body = {
111
+ "templateGroup"=> @template_group,
112
+ "language"=> @language,
113
+ "viewType"=> @view,
114
+ "templates"=> @templates,
115
+ "version" => @version
116
+ }
117
+ body.to_json
118
+ end
119
+
120
+ end
121
+
122
+ module JSON
123
+ def self.is_valid_json?(json)
124
+ begin
125
+ JSON.parse(json)
126
+ return true
127
+ rescue JSON::ParserError => e
128
+ return false
129
+ end
130
+ end
131
+ end
132
+
133
+ class TemplateConfig
134
+ BaseAppID = "1005"
135
+ SupportedLanguages = "supportedLanguages"
136
+ BaseLanguageResource = "VI"
137
+
138
+ def self.language_resource_path(language)
139
+ return "Resources/#{language}.json"
140
+ end
141
+
142
+ def self.base_language_resource_path()
143
+ return language_resource_path("#{TemplateConfig::BaseLanguageResource}")
144
+ end
145
+
146
+ def self.template_group_contents_path_for_base_app(template_group)
147
+ return template_group_contents_path_for_appID(template_group, BaseAppID)
148
+ end
149
+
150
+ def self.template_group_contents_path_for_appID(template_group, appID)
151
+ parent_dir_path = template_group_parent_directory_path_for_appID(template_group, appID)
152
+ return "#{parent_dir_path}/#{appID}"
153
+ end
154
+
155
+ def self.template_group_parent_directory_path_for_appID(template_group, appID)
156
+ template_group_parent_path = template_group_parent_directory_path(template_group)
157
+ return "#{template_group_parent_path}/common/UIVIEW/appID_#{appID}"
158
+ end
159
+
160
+ def self.template_group_parent_directory_path(template_group)
161
+ return "Templates/#{template_group}"
162
+ end
163
+
164
+ def self.template_group_details_path_for_template_group(template_group)
165
+ template_group_parent_path = template_group_parent_directory_path(template_group)
166
+ return "#{template_group_parent_path}/templateGroupDetails.json"
167
+ end
168
+
169
+ def self.template_group_details_for_template_group(template_group)
170
+ file_path = template_group_details_path_for_template_group(template_group)
171
+ return read_raw_json_data_from_file_path(file_path)
172
+ end
173
+
174
+ def self.supported_languages_for_template_group(template_group)
175
+ return template_group_details_for_template_group(template_group)["#{TemplateConfig::SupportedLanguages}"]
176
+ end
177
+
178
+ def self.update_template_group_details_for_template_group(template_group, key, value)
179
+ template_group_details = template_group_details_for_template_group(template_group)
180
+ template_group_details[key] = value
181
+ template_group_details_file_path = template_group_details_path_for_template_group(template_group)
182
+ puts "updated template group details: #{JSON.pretty_generate template_group_details}"
183
+ write_data_to_file(template_group_details_file_path, template_group_details)
184
+ end
185
+
186
+ def self.add_language_to_supported_languages_for_template_group(template_group, language)
187
+ if language == nil
188
+ log_error("Cannot add nil lanugage to supportedLanguages")
189
+ return
190
+ end
191
+ supported_languages = supported_languages_for_template_group(template_group)
192
+ if supported_languages.include?(language)
193
+ log_info("Language #{language} already exists in supported languages. Skipping adding language")
194
+ else
195
+ puts "Adding language #{language} to supported languages"
196
+ supported_languages.push(language)
197
+ update_template_group_details_for_template_group(template_group, "#{TemplateConfig::SupportedLanguages}", supported_languages)
198
+ end
199
+ end
200
+ end
201
+
202
+ class String
203
+ def newline
204
+ self.gsub(/\n/,"")
205
+ end
206
+ def tabs
207
+ self.gsub(/\t/," ")
208
+ end
209
+ def esc
210
+ self.gsub(/\"/,"\\\"")
211
+ end
212
+ def escnewline
213
+ self.gsub(/\n/,"\\n")
214
+ end
215
+ end
216
+
217
+ class CreateCollectionItem
218
+ def initialize(item_id, data)
219
+ @itemID = item_id
220
+ @data = data
221
+ end
222
+
223
+ def to_json
224
+ body = {
225
+ "itemID"=> @itemID,
226
+ "data"=> @data,
227
+ "isBase64Encoded"=> "true"
228
+ }
229
+ body.to_json
230
+ end
231
+ end
232
+
233
+ class Configuration
234
+
235
+ attr_reader :environment
236
+ attr_reader :base_url
237
+ attr_reader :get_template_url
238
+ attr_reader :create_template_url
239
+ attr_reader :base_folder_path
240
+ attr_reader :collections_base_folder_path
241
+ attr_reader :common_data_file_path
242
+ attr_reader :templated_data_file_path
243
+ attr_reader :zebugger_templated_data_file_path
244
+ attr_reader :additional_data_file_path
245
+ attr_reader :sample_ios_uainfo_data_file_path
246
+ attr_reader :sample_android_uainfo_data_file_path
247
+ attr_reader :sample_remote_config_data_file_path
248
+ attr_reader :env_data_file_path
249
+ attr_reader :get_latest_collection_items_url
250
+ attr_reader :set_collection_item_url
251
+ attr_reader :get_collection_item_url
252
+ attr_reader :delete_collection_item_url
253
+ attr_reader :count
254
+ attr_reader :post_insert_templates_url
255
+ attr_reader :post_insert_template_group_url
256
+ attr_reader :post_upsert_template_mappings_url
257
+ attr_reader :get_template_group_details_url
258
+ attr_reader :get_templates_for_view_url
259
+ attr_reader :post_update_template_group_url
260
+ attr_reader :post_delete_template_group_url
261
+ attr_reader :post_update_templates_url
262
+ attr_reader :post_delete_templates_url
263
+ attr_reader :post_delete_template_mappings_url
264
+ attr_reader :resources_file_path
265
+ attr_reader :apollo_config_base_url
266
+ attr_reader :collection_id_for_default
267
+ attr_reader :collection_id_for_iOS_v2
268
+ attr_reader :collection_id_for_iOS_v3
269
+
270
+
271
+ def initialize(environment)
272
+ conf_file = File.read(File.expand_path("/var/jenkins_home/template_config/config.json"));
273
+ conf = JSON.parse conf_file
274
+ conf = conf[environment.downcase]
275
+ if (conf["base_url"] == nil or conf["get_template_url"] == nil or conf["create_template_url"] == nil or conf["base_folder_path"] == nil or conf["collections_base_folder_path"] == nil)
276
+ puts "Required configurations are missing"
277
+ raise "Required configurations are missing"
278
+ return nil
279
+ end
280
+ @environment = environment
281
+ @base_url = conf["base_url"]
282
+ @get_template_url = conf["base_url"] + "/" + conf["get_template_url"]
283
+ @create_template_url = conf["base_url"] + "/" + conf["create_template_url"]
284
+ @base_folder_path = conf["base_folder_path"]
285
+ @collections_base_folder_path = conf["collections_base_folder_path"]
286
+ @common_data_file_path = conf["common_data_file_path"]
287
+ @common_data_path = conf["collections_base_folder_path"]
288
+ @templated_data_file_path = conf["templated_data_file_path"]
289
+ @zebugger_templated_data_file_path = conf["zebugger_templated_data_file_path"]
290
+ @additional_data_file_path = conf["additional_data_file_path"]
291
+ @sample_ios_uainfo_data_file_path = conf["sample_ios_uainfo_data_file_path"]
292
+ @sample_android_uainfo_data_file_path = conf["sample_android_uainfo_data_file_path"]
293
+ @sample_remote_config_data_file_path = conf["sample_remote_config_data_file_path"]
294
+ @env_data_file_path = conf["env_data_file_path"]
295
+ @get_latest_collection_items_url = conf["base_url"] + "/" + conf["get_latest_collection_items_url"]
296
+ @set_collection_item_url = conf["base_url"] + "/" + conf["set_collection_item_url"]
297
+ @get_collection_item_url = conf["base_url"] + "/" + conf["get_collection_item_url"]
298
+ @delete_collection_item_url = conf["base_url"] + "/" + conf["delete_collection_item_url"]
299
+ @count = conf["count"]
300
+ @post_insert_templates_url = conf["base_url"] + "/" + conf["post_insert_templates_url"]
301
+ @post_insert_template_group_url = conf["base_url"] + "/" + conf["post_insert_template_group_url"]
302
+ @post_upsert_template_mappings_url = conf["base_url"] + "/" + conf["post_upsert_template_mappings_url"]
303
+ @get_template_group_details_url = conf["base_url"] + "/" + conf["get_template_group_details_url"]
304
+ @get_templates_for_view_url = conf["base_url"] + "/" + conf["get_templates_for_view_url"]
305
+ @post_update_template_group_url = conf["base_url"] + "/" + conf["post_update_template_group_url"]
306
+ @post_delete_template_group_url = conf["base_url"] + "/" + conf["post_delete_template_group_url"]
307
+ @post_update_templates_url = conf["base_url"] + "/" + conf["post_update_templates_url"]
308
+ @post_delete_templates_url = conf["base_url"] + "/" + conf["post_delete_templates_url"]
309
+ @post_delete_template_mappings_url = conf["base_url"] + "/" + conf["post_delete_template_mappings_url"]
310
+ @apollo_config_base_url = conf["apollo_config_base_url"]
311
+ @resources_file_path = conf["resources_file_path"]
312
+ @collection_id_for_default = conf["collection_id_for_default"]
313
+ @collection_id_for_iOS_v2 = conf["collection_id_for_iOS_v2"]
314
+ @collection_id_for_iOS_v3 = conf["collection_id_for_iOS_v3"]
315
+ end
316
+
317
+ def data_template_file_path_for_template(template_group, lang, view_type, template_name)
318
+ "#{@base_folder_path}/#{template_group}/#{lang}/#{view_type}/#{template_name}/dataTemplate.json"
319
+ end
320
+
321
+ def presentation_file_path_for_template(template_group, lang, view_type, template_name)
322
+ "#{@base_folder_path}/#{template_group}/#{lang}/#{view_type}/#{template_name}/presentation.json"
323
+ end
324
+
325
+ def default_content_file_path_for_template(template_group, lang, view_type, template_name)
326
+ "#{@base_folder_path}/#{template_group}/#{lang}/#{view_type}/#{template_name}/defaultContent.json"
327
+ end
328
+
329
+ def template_name_dir_path_for_template(template_group, language, view_type, template_name)
330
+ "#{@base_folder_path}/#{template_group}/#{language}/#{view_type}/#{template_name}"
331
+ end
332
+
333
+ def view_type_dir_path_for_template(template_group, language, view_type)
334
+ "#{@base_folder_path}/#{template_group}/#{language}/#{view_type}"
335
+ end
336
+
337
+ def view_type_dir_path_for_template_with_version(template_group, language, view_type, version)
338
+ "#{@base_folder_path}/#{template_group}/#{language}/#{view_type}/#{version}"
339
+ end
340
+
341
+ def language_dir_path_for_template(template_group, language)
342
+ "#{@base_folder_path}/#{template_group}/#{language}"
343
+ end
344
+
345
+ def transfomer_file_path_for_template(template_group)
346
+ "#{@base_folder_path}/#{template_group}/transformer.js"
347
+ end
348
+
349
+ def client_transfomer_file_path_for_template(template_group)
350
+ "#{@base_folder_path}/#{template_group}/clientTransformer.js"
351
+ end
352
+
353
+ def template_group_details_file_path_for_template(template_group)
354
+ "#{@base_folder_path}/#{template_group}/templateGroupDetails.json"
355
+ end
356
+
357
+ def template_group_dir_path_for_template(template_group)
358
+ "#{@base_folder_path}/#{template_group}"
359
+ end
360
+
361
+ def collection_dir_path_for_collection_id(collection_id)
362
+ "#{@collections_base_folder_path}/#{collection_id}/#{ENV['environment']}"
363
+ end
364
+
365
+ def collection_item_file_path_for_collection_id_and_item_id(collection_id, item_id)
366
+ "#{@collections_base_folder_path}/#{collection_id}/#{ENV['environment']}/#{item_id}.json"
367
+ end
368
+
369
+ def language_file_path_for_template(language)
370
+ "#{@resources_file_path}/#{language}.json"
371
+ end
372
+
373
+ def env_file_path(tenant_id, project_id)
374
+ if file_exists?("./environments/#{@environment}/env_#{tenant_id}_#{project_id}.json")
375
+ "./environments/#{@environment}/env_#{tenant_id}_#{project_id}.json"
376
+ else
377
+ "#{@env_data_file_path}"
378
+ end
379
+ end
380
+
381
+ end
382
+
383
+ def directory_exists?(directory)
384
+ File.directory?(directory)
385
+ end
386
+
387
+ def file_exists?(file_name)
388
+ File.file?(file_name)
389
+ end
390
+
391
+ def invoke_API(environment, url, type, query_params = nil, body = nil)
392
+ secretConfig = SecretConfig.new(environment);
393
+ puts "Invoking API: #{url}"
394
+ query_params = query_params == nil ? {} : query_params
395
+ if type == HTTP::GET
396
+ response = make_GET_request(url, secretConfig.authToken, query_params, true)
397
+ elsif type == HTTP::POST
398
+ response = make_POST_request(url, body, secretConfig.authToken, query_params, true)
399
+ elsif type == HTTP::DELETE
400
+ response = make_DELETE_request(url, body, secretConfig.authToken, query_params, true)
401
+ end
402
+ if response
403
+ JSON.parse response
404
+ end
405
+ end
406
+
407
+ def make_POST_request (url, body, authToken, query_params = nil, should_log = true)
408
+ uri = URI.parse(url)
409
+ uri.query = URI.encode_www_form(query_params) if query_params != nil
410
+
411
+ http = Net::HTTP.new(uri.host, uri.port)
412
+ http.use_ssl = true
413
+ request = Net::HTTP::Post.new(uri.request_uri,
414
+ initheader = {'Content-Type' =>'application/json', 'X-Zeta-AuthToken' => authToken})
415
+ request.body = body
416
+
417
+ puts "#{uri}\n\n" if should_log
418
+ puts "#{request.body}\n\n" if should_log
419
+ response = http.request(request)
420
+ puts "#{response.body}" if should_log
421
+ return response.body
422
+ end
423
+
424
+ def make_GET_request (url, authToken, query_params = nil, should_log = true)
425
+ uri = URI.parse(url)
426
+ uri.query = URI.encode_www_form(query_params) if query_params != nil
427
+
428
+ http = Net::HTTP.new(uri.host, uri.port)
429
+ http.use_ssl = true
430
+ request = Net::HTTP::Get.new(uri.request_uri,
431
+ initheader = {'Content-Type' =>'application/json', 'X-Zeta-AuthToken' => authToken})
432
+
433
+ puts "#{uri}\n\n" if should_log
434
+ puts "#{request.body}\n\n" if should_log
435
+ response = http.request(request)
436
+ puts "#{response.body}" if should_log
437
+ return response.body
438
+ end
439
+
440
+ def make_DELETE_request (url, body, authToken, query_params = nil, should_log = true)
441
+ uri = URI.parse(url)
442
+ uri.query = URI.encode_www_form(query_params) if query_params != nil
443
+
444
+ http = Net::HTTP.new(uri.host, uri.port)
445
+ http.use_ssl = true
446
+ request = Net::HTTP::Delete.new(uri.request_uri,
447
+ initheader = {'Content-Type' =>'application/json', 'X-Zeta-AuthToken' => authToken})
448
+ request.body = body
449
+
450
+ puts "#{uri}\n\n" if should_log
451
+ puts "#{request.body}\n\n" if should_log
452
+ response = http.request(request)
453
+ puts "#{response.body}" if should_log
454
+ return response.body
455
+ end
456
+
457
+ def make_collection_POST_request (url, body, authToken, query_params = nil)
458
+ uri = URI.parse(url)
459
+ uri.query = URI.encode_www_form(query_params) if query_params != nil
460
+
461
+ http = Net::HTTP.new(uri.host, uri.port)
462
+ http.use_ssl = true
463
+ request = Net::HTTP::Post.new(uri.request_uri,
464
+ initheader = {'Content-Type' =>'application/json', 'X-Zeta-AuthToken' => authToken})
465
+ request.body = body
466
+
467
+ puts "#{uri}\n\n"
468
+ puts "#{request.body}\n\n"
469
+ http.request(request).body
470
+ end
471
+
472
+ def make_collection_GET_request (url, query_params = nil)
473
+ uri = URI(url)
474
+ uri.query = URI.encode_www_form(query_params) if query_params != nil
475
+
476
+ response = Net::HTTP.get_response(uri)
477
+ if response.is_a?(Net::HTTPSuccess)
478
+ utf8_encoded = response.body.force_encoding("UTF-8")
479
+ JSON.parse utf8_encoded
480
+ else
481
+ puts "Error occured while loading #{url}\nquery_params: #{query_params}
482
+ Error: #{response.inspect}, #{response.body}"
483
+ end
484
+ end
485
+
486
+ def write_data_to_file(file_path, data)
487
+ out_file = File.new(file_path, "w")
488
+ out_file.puts JSON.pretty_generate data
489
+ out_file.close
490
+ end
491
+
492
+ def write_plain_text_to_file(file_path, data)
493
+ out_file = File.new(file_path, "w")
494
+ out_file.puts data
495
+ out_file.close
496
+ end
497
+
498
+ def write_common_data_to_file(configuration, collection_data)
499
+ out_file = File.new(configuration.common_data_file_path, "w")
500
+ out_file.puts JSON.pretty_generate collection_data
501
+ out_file.close
502
+ end
503
+
504
+ def write_collection_data_to_file(collection_data, file_path)
505
+ out_file = File.new(file_path, "w")
506
+ out_file.puts JSON.pretty_generate collection_data
507
+ out_file.close
508
+ end
509
+
510
+ def write_templated_data_to_file(configuration, collection_data)
511
+ out_file = File.new(configuration.templated_data_file_path, "w")
512
+ out_file.puts JSON.pretty_generate collection_data
513
+ out_file.close
514
+ end
515
+
516
+ def write_templated_data_to_file_for_zebugger(configuration, collection_data)
517
+ out_file = File.new(configuration.zebugger_templated_data_file_path, "w")
518
+ out_file.puts JSON.pretty_generate collection_data
519
+ out_file.close
520
+ end
521
+
522
+ def additional_template_data(configuration)
523
+ collection_data = {}
524
+ begin
525
+ file_path = configuration.additional_data_file_path
526
+ if (file_exists?(file_path))
527
+ in_file = File.read(file_path)
528
+ return if in_file == nil
529
+ data = JSON.parse(in_file)
530
+ data = data.to_json
531
+ collection_data = data
532
+ else
533
+ collection_data = {}
534
+ end
535
+ rescue Exception => e
536
+ puts "Additional Data loading from #{file_path} failed with error: #{e}"
537
+ collection_data = {}
538
+ end
539
+ return collection_data
540
+ end
541
+
542
+ def cached_template_data(configuration)
543
+ collection_data = {}
544
+ begin
545
+ file_path = configuration.common_data_file_path
546
+ if (file_exists?(file_path))
547
+ in_file = File.read(file_path)
548
+ return if in_file == nil
549
+ data = JSON.parse(in_file)
550
+ data = data.to_json
551
+ collection_data = data
552
+ else
553
+ collection_data = {}
554
+ end
555
+ rescue Exception => e
556
+ puts "Cached Data loading from #{file_path} failed with error: #{e}"
557
+ collection_data = {}
558
+ end
559
+ return collection_data
560
+ end
561
+
562
+ def file_of_name_in_dir_path(dir_path, file_name)
563
+ file_path = ""
564
+ begin
565
+ file_path = Dir.entries(dir_path).select {
566
+ |entry| entry.include? file_name
567
+ }.first
568
+ if !(file_path == nil)
569
+ file_path = File.join(dir_path,file_path)
570
+ end
571
+ rescue Exception => e
572
+ puts "ERROR: file_of_name_in_dir_path #{dir_path} #{file_name} #{e}"
573
+ end
574
+ return file_path
575
+ end
576
+
577
+ def read_data_from_file_of_name_in_dir_path(dir_path, file_name)
578
+ file_data = {}
579
+ begin
580
+ file_path = Dir.entries(dir_path).select {
581
+ |entry| entry.include? file_name
582
+ }.first
583
+ file_path = File.join(dir_path,file_path)
584
+ file_data = File.read(file_path)
585
+ rescue Exception => e
586
+ puts "Reading from #{file_path} failed with error: #{e}"
587
+ end
588
+ return file_data
589
+ end
590
+
591
+ def read_data_from_file_path(file_path)
592
+ file_data = {}
593
+ begin
594
+ if (file_exists?(file_path))
595
+ in_file = File.read(file_path)
596
+ return if in_file == nil
597
+ file_data = in_file
598
+ else
599
+ file_data = {}
600
+ end
601
+ rescue Exception => e
602
+ puts "Reading from #{file_path} failed with error: #{e}"
603
+ file_data = {}
604
+ end
605
+ return file_data
606
+ end
607
+
608
+ def read_plain_text_data_from_file_path(file_path)
609
+ file_data = ""
610
+ begin
611
+ if (file_exists?(file_path))
612
+ in_file = File.read(file_path)
613
+ return if in_file == nil
614
+ file_data = in_file
615
+ end
616
+ rescue Exception => e
617
+ puts "Reading from #{file_path} failed with error: #{e}"
618
+ end
619
+ return file_data
620
+ end
621
+
622
+ def read_res_data_from_file_path(file_path)
623
+ file_data = {}
624
+ if (!file_exists?(file_path))
625
+ file_path = "./Resources/EN.json"
626
+ end
627
+ file_data = read_data_from_file_path(file_path)
628
+ return file_data
629
+ end
630
+
631
+ def setup_appID_uiview_template_group_directory(template_group, appID)
632
+ base_path = TemplateConfig.template_group_parent_directory_path_for_appID(template_group, appID)
633
+ contents_path = TemplateConfig.template_group_contents_path_for_appID(template_group, appID)
634
+ if (directory_exists?(base_path))
635
+ puts "Template parent directory for appID: #{appID} already exists at path: #{base_path}"
636
+ else
637
+ Dir.mkdir base_path
638
+ end
639
+
640
+ if (directory_exists?(contents_path))
641
+ puts "Template contents directory for appID: #{appID} already exists at path: #{contents_path}"
642
+ else
643
+ Dir.mkdir contents_path
644
+ end
645
+ end
646
+
647
+ def print_separator()
648
+ puts "------------------------------------------------------------------------------------------------".green
649
+ end
650
+
651
+ def print_header(message)
652
+ print_separator()
653
+ puts message.bold.magenta
654
+ print_separator()
655
+ end
656
+
657
+ def log_error(message)
658
+ puts "ERROR: #{message}".bold.red
659
+ end
660
+
661
+ def log_info(message)
662
+ puts "INFO: #{message}".bold
663
+ end
664
+
665
+ def read_new_app_template_groups_from_config()
666
+ new_app_template_groups = Array.new
667
+ file_path = "new_app_template_groups.json"
668
+
669
+ begin
670
+ new_app_templates_config = read_raw_json_data_from_file_path(file_path)
671
+ if new_app_templates_config["templateGroups"].is_a?(Array)
672
+ new_app_template_groups = new_app_templates_config["templateGroups"]
673
+ else
674
+ throw "templateGroups inside config is not an array"
675
+ end
676
+ rescue Exception => e
677
+ log_error("Failed to read new_app_template_groups_config with error: #{e}")
678
+ end
679
+ return new_app_template_groups
680
+ end
681
+
682
+ def read_raw_json_data_from_file_path(file_path)
683
+ data = Hash.new
684
+ begin
685
+ if(file_exists?(file_path))
686
+ in_file = File.read(file_path)
687
+ if in_file != nil
688
+ data = JSON.parse(in_file)
689
+ else
690
+ throw "Contents are nil"
691
+ end
692
+ end
693
+ rescue Exception => e
694
+ log_error("Failed to read contents of file at path [#{file_path}]with error: #{e}")
695
+ end
696
+ return data
697
+ end
698
+
699
+ def read_json_data_from_file_path(file_path)
700
+ file_data = {}
701
+ begin
702
+ if (file_exists?(file_path))
703
+ in_file = File.read(file_path)
704
+ return if in_file == nil
705
+ data = JSON.parse(in_file)
706
+ data = data.to_json
707
+ file_data = data
708
+ else
709
+ file_data = {}
710
+ end
711
+ rescue Exception => e
712
+ puts "Reading from #{file_path} failed with error: #{e}"
713
+ file_data = {}
714
+ end
715
+ return file_data
716
+ end
717
+
718
+ def print_separator_line()
719
+ puts "--------------------------------------------------------------------------------------------------------------------------------------"
720
+ end
721
+
722
+ def does_templated_data_has_payment_instrument_as_states(templated_data, activePaymentInstrumentID, os)
723
+ if os == "android"
724
+ outer_states = templated_data["states"]
725
+ if outer_states
726
+ if !outer_states.empty?
727
+ inner_states = outer_states["states"]
728
+ if !inner_states.empty?
729
+ keys = inner_states.keys
730
+ return keys.include? activePaymentInstrumentID
731
+ end
732
+ end
733
+ end
734
+ end
735
+ if os == "ios"
736
+ outer_states = templated_data["states"]
737
+ keys = outer_states.keys
738
+ return keys.include? activePaymentInstrumentID
739
+ end
740
+ end
741
+
742
+ def directory_list(dir_path)
743
+ dirNames = []
744
+ Dir.entries(dir_path).select {
745
+ |entry| File.directory? File.join(dir_path,entry) and !(entry =='.' || entry == '..')
746
+ }.each do |item|
747
+ dirNames.push(item)
748
+ end
749
+ return dirNames
750
+ end
751
+
752
+ def all_directory_and_sub_directory_with_character_not_in_dir_path(dir_path, character)
753
+ dirNames = Hash.new
754
+ Dir.entries(dir_path).select {
755
+ |entry| File.directory? File.join(dir_path,entry) and !(entry =='.' || entry == '..')
756
+ }.each do |item|
757
+ indexOfCharacter = item.index(character)
758
+ indexOfTemplater = item.index("{{")
759
+ if indexOfCharacter and indexOfCharacter >= 0 and (!indexOfTemplater || indexOfCharacter < indexOfTemplater)
760
+ dirNames = dirNames.merge(all_directory_and_sub_directory_with_character_not_in_dir_path(File.join(dir_path,item), character))
761
+ else
762
+ dirNames[item] = File.join(dir_path,item)
763
+ end
764
+ end
765
+ return dirNames
766
+ end
767
+
768
+ def all_directory_and_sub_directory_in_dir_path(dir_path)
769
+ dirNames = Hash.new
770
+ Dir.entries(dir_path).select {
771
+ |entry| File.directory? File.join(dir_path,entry) and !(entry =='.' || entry == '..')
772
+ }.each do |item|
773
+ dir_path_of_item = File.join(dir_path,item)
774
+ dir_names_of_item = directory_list(dir_path_of_item)
775
+ if dir_names_of_item.count > 0
776
+ dirNames[item] = File.join(dir_path,item)
777
+ dirNames = dirNames.merge(all_directory_and_sub_directory_in_dir_path(dir_path_of_item))
778
+ else
779
+ dirNames[item] = File.join(dir_path,item)
780
+ end
781
+ end
782
+ return dirNames
783
+ end
784
+
785
+ def template_mapping_in_dir_path_file_path_with_character(dir_path, file_path, character)
786
+ dir_path += "/"
787
+ file_path.slice! dir_path
788
+ mapping_components = file_path.split('/')
789
+ template_mapping = "";
790
+ mapping_components.each do |item|
791
+ if item == "default"
792
+ template_mapping = "*"
793
+ else
794
+ length = item.length
795
+ indexOfCharacter = item.index(character)
796
+ indexOfTemplater = item.index("{{")
797
+ if indexOfCharacter and indexOfCharacter >= 0 and (!indexOfTemplater || indexOfCharacter < indexOfTemplater)
798
+ item_component = item.slice!(indexOfCharacter+1..length-1)
799
+ if template_mapping.empty?
800
+ mapping = item_component
801
+ else
802
+ mapping = "_" + item_component
803
+ end
804
+ template_mapping += mapping
805
+ end
806
+ end
807
+ end
808
+ return template_mapping
809
+ end
810
+
811
+ module ApolloCommonsRuby
812
+ class Error < StandardError; end
813
+ # Your code goes here...
814
+ end