singleton-ruby 0.1.3 → 0.1.7

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
  SHA256:
3
- metadata.gz: c2e092b1d69a9639d976877f5ad64486ebe37a6d64bdaef84f1aa10a1424ae6e
4
- data.tar.gz: 42f5c443bf2e9a20004ba147586de5088d9fdb1a7cd56b422f0b8fff85ea82ec
3
+ metadata.gz: ce278f87ad2d126f157bd01f73dfde7261d130151ca8b434880b81fd963059e5
4
+ data.tar.gz: 42ebbf6d9e61acce392a64a7be42d423e2608ec5068ce5960bec9c58077aa7ae
5
5
  SHA512:
6
- metadata.gz: 4e269b9d4dc398a51491bcaa8c71304c360cc082cce8bc6f49ca07ddd7d72849f26341d65d1700e452eb5976197eb5a95542f09e9bf1aa595e2448becd894353
7
- data.tar.gz: d8230f6464e7c1c4f940665f55bfb0fdb577553c980b844ecd45803e77ee3ca4ffdf346c67deec784daf17d94fc2bd2cbbdf2ed8e4b9eb565f24a12d3191f788
6
+ metadata.gz: 2c1470e61f1f06b84057b72003a285fdfed9daefefe39adf2e0f9d0f090a210531223d47e83ee081e903f7f1c545082683f306172fc5ccec03500796abbf9cf5
7
+ data.tar.gz: b7b17bcee21fbce9b639cf94ef4491ad6e9cc9a85ce9884ea9cc5cbefd51ae7b437c8bb3a7f83b6f20371c973e56283ef6653ec85259aa3ac289e14a336981c2
data/README.md CHANGED
@@ -23,13 +23,30 @@ SgtnClient::Source.loadBundles(locale)
23
23
  @Result = SgtnClient::Translation.getString(component, key, locale)
24
24
 
25
25
  ```
26
- ## API
26
+ ## API Usage
27
27
 
28
28
  ### Get a string's translation
29
29
  SgtnClient::Translation.getString(component, key, locale)
30
30
 
31
31
  ### Get a string's translation and format it with placeholders
32
- SgtnClient::Translation.getString_F(component, key, args, locale)
32
+ SgtnClient::Translation.getString_f(component, key, args, locale)
33
+
34
+ ### Get a component's translations
35
+ SgtnClient::Translation.getStrings(component, locale)
36
+
37
+
38
+ ## API Usage(with request_store)
39
+
40
+ Before call below APIs(without locale and component arguments), it requires to set the locale and component in the initial codes.
41
+
42
+ ### Get a string's translation
43
+ SgtnClient::T.s(key)
44
+
45
+ ### Get a string's translation and format it with placeholders
46
+ SgtnClient::T.s_f(key, args)
47
+
48
+ ### Get a component's translations
49
+ SgtnClient::T.c()
33
50
 
34
51
 
35
52
 
@@ -2,7 +2,7 @@ require 'erb'
2
2
  require 'yaml'
3
3
 
4
4
  module SgtnClient
5
-
5
+
6
6
  autoload :CacheUtil, "sgtn-client/util/cache-util"
7
7
 
8
8
  class Source
@@ -41,18 +41,16 @@ module SgtnClient
41
41
  env = SgtnClient::Config.default_environment
42
42
  SgtnClient::Config.configurations.default = locale
43
43
  source_bundle = SgtnClient::Config.configurations[env]["source_bundle"]
44
- SgtnClient.logger.debug "Loading [" + locale + "] bundles from path: " + source_bundle
44
+ SgtnClient.logger.debug "Loading [" + locale + "] source bundles from path: " + source_bundle
45
45
  Dir.children(source_bundle).each do |component|
46
46
  yamlfile = File.join(source_bundle, component + "/" + locale + ".yml")
47
47
  bundle = read_yml(yamlfile)
48
48
  cachekey = SgtnClient::CacheUtil.get_cachekey(component, locale)
49
49
  SgtnClient::CacheUtil.write_cache(cachekey,bundle)
50
50
  end
51
-
52
51
  end
53
52
 
54
53
  private
55
-
56
54
  def self.getBundle(component, locale)
57
55
  env = SgtnClient::Config.default_environment
58
56
  source_bundle = SgtnClient::Config.configurations[env]["source_bundle"]
@@ -71,7 +69,6 @@ module SgtnClient
71
69
  erb.filename = file_name
72
70
  YAML.load(erb.result)
73
71
  end
74
-
75
72
  end
76
73
 
77
74
  end
@@ -0,0 +1,22 @@
1
+ module SgtnClient
2
+ class T < Translation
3
+
4
+ def self.s(key)
5
+ locale = RequestStore.store[:locale]
6
+ component = RequestStore.store[:component]
7
+ return getString(component, key, locale)
8
+ end
9
+
10
+ def self.s_f(key, args)
11
+ locale = RequestStore.store[:locale]
12
+ component = RequestStore.store[:component]
13
+ return getString_f(component, key, args, locale)
14
+ end
15
+
16
+ def self.c()
17
+ locale = RequestStore.store[:locale]
18
+ component = RequestStore.store[:component]
19
+ return getStrings(component, locale)
20
+ end
21
+ end
22
+ end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'multi_json'
2
2
 
3
3
  module SgtnClient
4
4
 
@@ -36,10 +36,15 @@ module SgtnClient
36
36
 
37
37
  def self.getString_f(component, key, args, locale)
38
38
  s = getString(component, key, locale)
39
- puts 1111
40
- puts SgtnClient::Config.configurations.default
41
- puts s
42
- return s % args
39
+ if is_json?(args)
40
+ jsonstr = MultiJson.load(args)
41
+ jsonstr.each do |source, arg|
42
+ s.gsub! "{#{source}}", arg
43
+ end
44
+ elsif args.is_a?(Array)
45
+ s = sprintf s % args
46
+ end
47
+ return s
43
48
  end
44
49
 
45
50
  def self.getStrings(component, locale)
@@ -55,7 +60,12 @@ module SgtnClient
55
60
 
56
61
  default = SgtnClient::Config.configurations.default
57
62
  if items.nil? || items["messages"] == nil
58
- items = SgtnClient::Source.getSources(component, default)
63
+ items = {}
64
+ s = SgtnClient::Source.getSources(component, default)
65
+ key, value = s.first
66
+ items["component"] = key
67
+ items["messages"] = value
68
+ items["locale"] = 'source'
59
69
  end
60
70
  return items
61
71
  end
@@ -82,7 +92,7 @@ module SgtnClient
82
92
  SgtnClient.logger.debug "Getting translations from offline bundle: " + bundlepath
83
93
  begin
84
94
  file = File.read(bundlepath)
85
- data_hash = JSON.parse(file)
95
+ data_hash = MultiJson.load(file)
86
96
  rescue => exception
87
97
  SgtnClient.logger.error exception.message
88
98
  end
@@ -108,6 +118,13 @@ module SgtnClient
108
118
  return obj
109
119
  end
110
120
 
121
+ def self.is_json?(value)
122
+ result = MultiJson.load(value)
123
+ result.is_a?(Hash) || result.is_a?(Array)
124
+ rescue => exception
125
+ false
126
+ end
127
+
111
128
  end
112
129
 
113
130
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'multi_json'
2
2
  require 'pp'
3
3
 
4
4
  module SgtnClient
@@ -13,7 +13,7 @@ module SgtnClient
13
13
 
14
14
  def to_s
15
15
  begin
16
- response_body = JSON.parse(response.body)
16
+ response_body = MultiJson.load(response.body)
17
17
  debug_id = response["sgtn-debug-id"]
18
18
  debug_id = response["correlation-id"] if debug_id.to_s == ''
19
19
  debug_id = response_body["debug_id"] if debug_id.to_s == ''
@@ -4,6 +4,7 @@ module SgtnClient
4
4
  end
5
5
 
6
6
  autoload :Translation, "sgtn-client/api/translation"
7
+ autoload :T, "sgtn-client/api/t"
7
8
  autoload :Source, "sgtn-client/api/source"
8
9
  autoload :Config, "sgtn-client/core/config"
9
10
  autoload :Logging, "sgtn-client/core/logging"
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
 
2
- VERSION_INFO = [0, 1, 3].freeze
2
+ VERSION_INFO = [0, 1, 7].freeze
3
3
  VERSION = VERSION_INFO.map(&:to_s).join('.').freeze
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: singleton-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - VMware G11n Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-25 00:00:00.000000000 Z
11
+ date: 2021-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: request_store
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.1'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: webmock
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -216,20 +230,6 @@ dependencies:
216
230
  - - "~>"
217
231
  - !ruby/object:Gem::Version
218
232
  version: '1.0'
219
- - !ruby/object:Gem::Dependency
220
- name: twitter_cldr
221
- requirement: !ruby/object:Gem::Requirement
222
- requirements:
223
- - - "~>"
224
- - !ruby/object:Gem::Version
225
- version: '6.6'
226
- type: :runtime
227
- prerelease: false
228
- version_requirements: !ruby/object:Gem::Requirement
229
- requirements:
230
- - - "~>"
231
- - !ruby/object:Gem::Version
232
- version: '6.6'
233
233
  description: Singleton Ruby client
234
234
  email: g11n-vip-project@vmware.com
235
235
  executables: []
@@ -237,10 +237,9 @@ extensions: []
237
237
  extra_rdoc_files:
238
238
  - README.md
239
239
  files:
240
- - Gemfile
241
240
  - README.md
242
- - Rakefile
243
241
  - lib/sgtn-client/api/source.rb
242
+ - lib/sgtn-client/api/t.rb
244
243
  - lib/sgtn-client/api/translation.rb
245
244
  - lib/sgtn-client/core/cache.rb
246
245
  - lib/sgtn-client/core/config.rb
@@ -253,31 +252,9 @@ files:
253
252
  - lib/sgtn-client/util/validate-util.rb
254
253
  - lib/singleton-ruby.rb
255
254
  - lib/version.rb
256
- - spec/config/locales/default/JAVA/default.yml
257
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_de.json
258
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_en.json
259
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_latest.json
260
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hans.json
261
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hant.json
262
- - spec/config/locales/l10n/bundles/test/4.8.1/creation.json
263
- - spec/config/locales/l10n/bundles/test/4.8.1/version.json
264
- - spec/config/sample_data.yml
265
- - spec/config/sgtnclient-invalidate.yml
266
- - spec/config/sgtnclient.yml
267
- - spec/log/http.log
268
- - spec/spec_helper.rb
269
- - spec/support/sample_data.rb
270
- - spec/unit/cache_spec.rb
271
- - spec/unit/config_spec.rb
272
- - spec/unit/inconfig_spec.rb
273
- - spec/unit/locale_spec.rb
274
- - spec/unit/logging_spec.rb
275
- - spec/unit/offclient_spec.rb
276
- - spec/unit/onclient_spec.rb
277
- - spec/unit/version_spec.rb
278
255
  homepage: https://github.com/vmware/singleton
279
256
  licenses:
280
- - EPL
257
+ - EPL 2.0
281
258
  metadata: {}
282
259
  post_install_message:
283
260
  rdoc_options: []
@@ -298,26 +275,4 @@ rubygems_version: 3.0.9
298
275
  signing_key:
299
276
  specification_version: 4
300
277
  summary: Singleton Ruby client
301
- test_files:
302
- - spec/config/locales/default/JAVA/default.yml
303
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_de.json
304
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_en.json
305
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_latest.json
306
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hans.json
307
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hant.json
308
- - spec/config/locales/l10n/bundles/test/4.8.1/creation.json
309
- - spec/config/locales/l10n/bundles/test/4.8.1/version.json
310
- - spec/config/sample_data.yml
311
- - spec/config/sgtnclient-invalidate.yml
312
- - spec/config/sgtnclient.yml
313
- - spec/log/http.log
314
- - spec/spec_helper.rb
315
- - spec/support/sample_data.rb
316
- - spec/unit/cache_spec.rb
317
- - spec/unit/config_spec.rb
318
- - spec/unit/inconfig_spec.rb
319
- - spec/unit/locale_spec.rb
320
- - spec/unit/logging_spec.rb
321
- - spec/unit/offclient_spec.rb
322
- - spec/unit/onclient_spec.rb
323
- - spec/unit/version_spec.rb
278
+ test_files: []
data/Gemfile DELETED
@@ -1,15 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- if !!File::ALT_SEPARATOR
4
- gemspec :name => 'singleton-ruby.windows'
5
- else
6
- gemspec :name => 'singleton-ruby'
7
- end
8
-
9
- gem 'rake', :require => false
10
-
11
- group :test do
12
- gem 'simplecov', :require => false
13
- gem 'rspec'
14
- gem 'webmock'
15
- end
data/Rakefile DELETED
@@ -1,140 +0,0 @@
1
- # load `rake build/install/release tasks'
2
- require 'bundler/setup'
3
- require_relative './lib/version'
4
-
5
- namespace :ruby do
6
- Bundler::GemHelper.install_tasks(:name => 'singleton-ruby')
7
- end
8
-
9
- require "rspec/core/rake_task"
10
-
11
- desc "Run all specs"
12
- RSpec::Core::RakeTask.new('spec')
13
-
14
- desc "Run unit specs"
15
- RSpec::Core::RakeTask.new('spec:unit') do |t|
16
- t.pattern = 'spec/unit/*_spec.rb'
17
- end
18
-
19
- desc "Run integration specs"
20
- RSpec::Core::RakeTask.new('spec:integration') do |t|
21
- t.pattern = 'spec/integration/*_spec.rb'
22
- end
23
-
24
- desc "Print specdocs"
25
- RSpec::Core::RakeTask.new(:doc) do |t|
26
- t.rspec_opts = ["--format", "specdoc", "--dry-run"]
27
- t.pattern = 'spec/**/*_spec.rb'
28
- end
29
-
30
- desc "Run all examples with RCov"
31
- RSpec::Core::RakeTask.new('rcov') do |t|
32
- t.pattern = 'spec/*_spec.rb'
33
- t.rcov = true
34
- t.rcov_opts = ['--exclude', 'examples']
35
- end
36
-
37
- desc 'Regenerate authors file'
38
- task :authors do
39
- Dir.chdir(File.dirname(__FILE__)) do
40
- File.open('AUTHORS', 'w') do |f|
41
- f.write <<-EOM
42
- The Ruby REST Client would not be what it is today without the help of
43
- the following kind souls:
44
-
45
- EOM
46
- end
47
-
48
- sh 'git shortlog -s | cut -f 2 >> AUTHORS'
49
- end
50
- end
51
-
52
- task :default do
53
- sh 'rake -T'
54
- end
55
-
56
- def alias_task(alias_task, original)
57
- desc "Alias for rake #{original}"
58
- task alias_task, Rake.application[original].arg_names => original
59
- end
60
- alias_task(:test, :spec)
61
-
62
- ############################
63
-
64
- WindowsPlatforms = %w{x86-mingw32 x64-mingw32 x86-mswin32}
65
-
66
- namespace :all do
67
-
68
- desc "Build rest-client #{VERSION} for all platforms"
69
- task :build => ['ruby:build'] + \
70
- WindowsPlatforms.map {|p| "windows:#{p}:build"}
71
-
72
- desc "Create tag v#{VERSION} and for all platforms build and " \
73
- "push rest-client #{VERSION} to Rubygems"
74
- task :release => ['build', 'ruby:release'] + \
75
- WindowsPlatforms.map {|p| "windows:#{p}:push"}
76
-
77
- end
78
-
79
- namespace :windows do
80
- spec_path = File.join(File.dirname(__FILE__), 'rest-client.windows.gemspec')
81
-
82
- WindowsPlatforms.each do |platform|
83
- namespace platform do
84
- gem_filename = "rest-client-#{VERSION}-#{platform}.gem"
85
- base = File.dirname(__FILE__)
86
- pkg_dir = File.join(base, 'pkg')
87
- gem_file_path = File.join(pkg_dir, gem_filename)
88
-
89
- desc "Build #{gem_filename} into the pkg directory"
90
- task 'build' do
91
- orig_platform = ENV['BUILD_PLATFORM']
92
- begin
93
- ENV['BUILD_PLATFORM'] = platform
94
-
95
- sh("gem build -V #{spec_path}") do |ok, res|
96
- if ok
97
- FileUtils.mkdir_p(pkg_dir)
98
- FileUtils.mv(File.join(base, gem_filename), pkg_dir)
99
- Bundler.ui.confirm("rest-client #{VERSION} " \
100
- "built to pkg/#{gem_filename}")
101
- else
102
- abort "Command `gem build` failed: #{res}"
103
- end
104
- end
105
-
106
- ensure
107
- ENV['BUILD_PLATFORM'] = orig_platform
108
- end
109
- end
110
-
111
- desc "Push #{gem_filename} to Rubygems"
112
- task 'push' do
113
- sh("gem push #{gem_file_path}")
114
- end
115
- end
116
- end
117
-
118
- end
119
-
120
- ############################
121
-
122
- require 'rdoc/task'
123
-
124
- Rake::RDocTask.new do |t|
125
- t.rdoc_dir = 'rdoc'
126
- t.title = "rest-client, fetch RESTful resources effortlessly"
127
- t.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
128
- t.options << '--charset' << 'utf-8'
129
- t.rdoc_files.include('README.md')
130
- t.rdoc_files.include('lib/*.rb')
131
- end
132
-
133
- ############################
134
-
135
- require 'rubocop/rake_task'
136
-
137
- RuboCop::RakeTask.new(:rubocop) do |t|
138
- t.options = ['--display-cop-names']
139
- end
140
- alias_task(:lint, :rubocop)
@@ -1,5 +0,0 @@
1
- default:
2
- helloworld: "Hello world"
3
- hello: "Hello"
4
- welcome: "%s, welcome login %s!"
5
- login: "%s login %s!"
@@ -1,8 +0,0 @@
1
- {
2
- "component" : "JAVA",
3
- "messages" : {
4
- "helloworld" : "Hallo Welt",
5
- "welcome": "%s, Willkommen in der %s des Logins!!"
6
- },
7
- "locale" : "de"
8
- }
@@ -1,8 +0,0 @@
1
- {
2
- "component" : "JAVA",
3
- "messages" : {
4
- "helloworld" : "Hello world",
5
- "welcome": "%s, welcome login %s!"
6
- },
7
- "locale" : "en"
8
- }
@@ -1,8 +0,0 @@
1
- {
2
- "component" : "JAVA",
3
- "messages" : {
4
- "helloworld" : "Hello world",
5
- "welcome": "%s, welcome login %s!"
6
- },
7
- "locale" : "latest"
8
- }
@@ -1,8 +0,0 @@
1
- {
2
- "component" : "JAVA",
3
- "messages" : {
4
- "helloworld" : "你好世界",
5
- "welcome": "%s,欢迎登录%s!"
6
- },
7
- "locale" : "zh-Hans"
8
- }
@@ -1,8 +0,0 @@
1
- {
2
- "component" : "JAVA",
3
- "messages" : {
4
- "helloworld" : "你好,世界",
5
- "welcome": "%s,歡迎登錄%s!"
6
- },
7
- "locale" : "zh-Hant"
8
- }
@@ -1,10 +0,0 @@
1
- {
2
- "de" : "grm-tos-360",
3
- "zh-Hans" : "grm-tos-360",
4
- "zh-Hant" : "grm-tos-360",
5
- "ko" : "grm-tos-360",
6
- "ja" : "grm-tos-360",
7
- "en" : "grm-tos-360",
8
- "fr" : "grm-tos-360",
9
- "es" : "grm-tos-360"
10
- }
@@ -1,38 +0,0 @@
1
- {
2
- "drop_id" : "1553634594698",
3
- "4.8.0" : {
4
- "JS" : {
5
- "zh-Hant" : "",
6
- "latest" : "",
7
- "fr" : "",
8
- "ko" : "",
9
- "zh-Hans" : "",
10
- "es" : "",
11
- "en" : "",
12
- "ja" : "",
13
- "de" : ""
14
- },
15
- "JSP" : {
16
- "zh-Hant" : "",
17
- "latest" : "",
18
- "fr" : "",
19
- "ko" : "",
20
- "zh-Hans" : "",
21
- "es" : "",
22
- "en" : "",
23
- "ja" : "",
24
- "de" : ""
25
- },
26
- "JAVA" : {
27
- "zh-Hant" : "",
28
- "latest" : "",
29
- "fr" : "",
30
- "ko" : "",
31
- "zh-Hans" : "",
32
- "es" : "",
33
- "en" : "",
34
- "ja" : "",
35
- "de" : ""
36
- }
37
- }
38
- }
@@ -1,3 +0,0 @@
1
- ipn:
2
- valid_message: item_number=&residence_country=US&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AXi5tzp0u2U-8QDyy.oC2A1Dhx04&address_country=United+States&address_city=San+Jose&address_status=unconfirmed&business=platfo_1255077030_biz%40gmail.com&payment_status=Pending&transaction_subject=&protection_eligibility=Ineligible&shipping=0.00&payer_id=934EKX9W68RRU&first_name=John&mc_fee=0.38&txn_id=5AL16697HX185734U&quantity=1&receiver_email=platfo_1255077030_biz%40gmail.com&notify_version=3.7&txn_type=web_accept&mc_gross=1.00&payer_status=unverified&mc_currency=USD&test_ipn=1&custom=&payment_date=01%3A48%3A31+Dec+04%2C+2012+PST&payment_fee=0.38&charset=windows-1252&address_country_code=US&payment_gross=1.00&address_zip=95131&ipn_track_id=af0f53159f21e&address_state=CA&receipt_id=4050-1771-4106-3070&pending_reason=paymentreview&tax=0.00&handling_amount=0.00&item_name=&address_name=John+Doe&last_name=Doe&payment_type=instant&receiver_id=HZH2W8NPXUE5W&address_street=1+Main+St
3
- invalid_message: invalid=invalid
@@ -1,44 +0,0 @@
1
- test: &default
2
-
3
- # Mode can be 'live' or 'sandbox'
4
- mode: sandbox1
5
-
6
- # Credentials for Classic APIs
7
- app_id: APP-80W284485P519543T
8
- username: linr
9
- password: fdasf
10
- signature: sfds-RWy
11
- # # With Certificate
12
- # cert_path: "config/cert_key.pem"
13
- sandbox_email_address: linr@aa.com
14
-
15
- # #Product Name
16
- product_name: test
17
-
18
- # # bundle version
19
- version: 4.8
20
-
21
- # # HTTP Proxy
22
- vip_server: https://server:8090
23
-
24
- # # mode of bundle: online/offline
25
- bundle_mode: offline1www
26
-
27
- # # translation bundle Path
28
- translation_bundle: ./spec/config/locales/l10n/bundles
29
-
30
- # # source bundle Path
31
- source_bundle: ./spec/config/locales/default
32
-
33
- # # memory cache's expration(minutes), default value is 24*60
34
- cache_expiry_period: 36t
35
-
36
- # # disable cache, it's optional setting
37
- disable_cache: true1
38
-
39
- development:
40
- <<: *default
41
-
42
- production:
43
- <<: *default
44
- mode: live
@@ -1,44 +0,0 @@
1
- test: &default
2
-
3
- # Mode can be 'live' or 'sandbox'
4
- mode: sandbox
5
-
6
- # Credentials for Classic APIs
7
- app_id: APP-80W284485P519543T
8
- username: linr
9
- password: fdasf
10
- signature: sfds-RWy
11
- # # With Certificate
12
- # cert_path: "config/cert_key.pem"
13
- sandbox_email_address: linr@aa.com
14
-
15
- # #Product Name
16
- product_name: test
17
-
18
- # # bundle version
19
- version: 4.8.1
20
-
21
- # # HTTP Proxy
22
- vip_server: https://server:8090
23
-
24
- # # mode of bundle: online/offline
25
- bundle_mode: offline
26
-
27
- # # translation bundle Path
28
- translation_bundle: ./spec/config/locales/l10n/bundles
29
-
30
- # # source bundle Path
31
- source_bundle: ./spec/config/locales/default
32
-
33
- # # memory cache's expration(minutes), default value is 24*60
34
- cache_expiry_period: 10
35
-
36
- # # disable cache, it's optional setting
37
- ##disable_cache: true
38
-
39
- development:
40
- <<: *default
41
-
42
- production:
43
- <<: *default
44
- mode: live
data/spec/log/http.log DELETED
File without changes
data/spec/spec_helper.rb DELETED
@@ -1,33 +0,0 @@
1
- require 'bundler/setup'
2
- require_relative '../lib/sgtn-client/sgtn-client.rb'
3
- require 'logger'
4
-
5
- if ENV['COVERAGE']
6
- require 'simplecov'
7
- require 'coveralls'
8
- Coveralls.wear!
9
- SimpleCov.start do
10
- add_filter "/spec/"
11
- end
12
- end
13
-
14
- Bundler.require :default, :test
15
-
16
- include SgtnClient
17
- include SgtnClient::Logging
18
- include SgtnClient::Exceptions
19
-
20
- SgtnClient.load("./spec/config/sgtnclient.yml", "test", './sgtnclient.log')
21
-
22
- Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f }
23
-
24
- # Set logger for http
25
- http_log = File.open(File.expand_path('../log/http.log', __FILE__), "w")
26
-
27
- RSpec.configure do |config|
28
- config.filter_run_excluding :integration => true
29
- config.filter_run_excluding :disabled => true
30
- config.include SampleData
31
- end
32
-
33
- WebMock.allow_net_connect!
@@ -1,5 +0,0 @@
1
- module SampleData
2
- def samples
3
- @@samples ||= YAML.load(File.read(File.expand_path("../../config/sample_data.yml", __FILE__)))
4
- end
5
- end
@@ -1,34 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SgtnClient do
4
- describe "Cache" do
5
-
6
- before :each do
7
- env = SgtnClient::Config.default_environment
8
- SgtnClient::Config.configurations[env]["bundle_mode"] = 'offline'
9
- SgtnClient::Config.configurations[env]["cache_expiry_period"] = 1
10
- SgtnClient::Source.loadBundles("default")
11
- end
12
-
13
- it "GETTranslation" do
14
-
15
- # get translation from server
16
- SgtnClient.logger.debug "----------Start to get translation from server---------"
17
- expect(SgtnClient::Translation.getString("JAVA", "helloworld", "zh-Hans")).to eq '你好世界'
18
- # get translation from cache
19
- SgtnClient.logger.debug "----------Start to get translation from cache---------"
20
- expect(SgtnClient::Translation.getString("JAVA", "helloworld", "zh-Hans")).to eq '你好世界'
21
-
22
- # get from server again after data is expired
23
- SgtnClient.logger.debug "----------Sleep 70s---------"
24
- puts Time.now
25
- #sleep 70
26
- puts Time.now
27
- SgtnClient.logger.debug "----------Start to get translation from expired cache---------"
28
- expect(SgtnClient::Translation.getString("JAVA", "helloworld", "zh-Hans")).to eq '你好世界'
29
-
30
- SgtnClient.logger.debug "----------End to get translation from server---------"
31
- end
32
- end
33
-
34
- end
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
- require_relative '../../lib/sgtn-client/sgtn-client.rb'
3
-
4
- describe SgtnClient do
5
-
6
- describe "loadconfig" do
7
-
8
- before :each do
9
- SgtnClient.load("./spec/config/sgtnclient.yml", "test", './sgtnclient_config.log')
10
- end
11
-
12
- it "define configuration" do
13
- env = SgtnClient::Config.default_environment
14
- mode = SgtnClient::Config.configurations[env]["mode"]
15
- expect(mode).to eq 'sandbox'
16
- end
17
-
18
- it "not define configuration" do
19
- begin
20
- SgtnClient::Config.config("aa", { :app_id => "XYZ" })
21
- rescue => exception
22
- expect(exception.message).to eq 'Configuration[aa] NotFound'
23
- end
24
- end
25
-
26
- end
27
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
- require_relative '../../lib/sgtn-client/sgtn-client.rb'
3
-
4
- describe SgtnClient do
5
-
6
- describe "loadinconfig" do
7
-
8
- before :each do
9
- #SgtnClient.load("./spec/config/sgtnclient-invalide.yml", "test", './sgtnclient_config.log')
10
- end
11
-
12
- it "validate_configuration" do
13
- SgtnClient.load("./spec/config/sgtnclient-invalidate.yml", "test", './sgtnclient_config.log')
14
- end
15
-
16
- end
17
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SgtnClient do
4
- describe "Locale" do
5
-
6
- before :each do
7
- end
8
-
9
- it "fallback" do
10
- expect(SgtnClient::LocaleUtil.fallback('ja-JP')).to eq 'ja'
11
- expect(SgtnClient::LocaleUtil.fallback('de-DE')).to eq 'de'
12
- expect(SgtnClient::LocaleUtil.fallback('zh')).to eq 'zh'
13
- expect(SgtnClient::LocaleUtil.fallback('zh-Hans')).to eq 'zh-Hans'
14
- expect(SgtnClient::LocaleUtil.fallback('zh-Hant')).to eq 'zh-Hant'
15
- expect(SgtnClient::LocaleUtil.fallback('zh-CN')).to eq 'zh-Hans'
16
- expect(SgtnClient::LocaleUtil.fallback('zh-TW')).to eq 'zh-Hant'
17
- expect(SgtnClient::LocaleUtil.fallback('zh-Hans-CN')).to eq 'zh-Hans'
18
- expect(SgtnClient::LocaleUtil.fallback('zh-Hant-TW')).to eq 'zh-Hant'
19
- expect(SgtnClient::LocaleUtil.fallback('kong-kong')).to eq 'kong-kong'
20
- end
21
- end
22
-
23
- end
@@ -1,33 +0,0 @@
1
- #require 'spec_helper'
2
- require 'stringio'
3
- require_relative '../../lib/sgtn-client/sgtn-client.rb'
4
-
5
- describe SgtnClient::Logging do
6
- #Logging = SgtnClient::Logging
7
-
8
- class TestLogging
9
- #include Logging
10
- end
11
-
12
- before :each do
13
- #@logger_file = StringIO.new
14
- #Logging.logger = Logger.new(@logger_file)
15
- #file = File.open('./spec/unit/foo.log', File::WRONLY | File::APPEND)
16
- #Logging.logger = Logger.new(file)
17
- #SgtnClient.logger = Logger.new(file)
18
- SgtnClient.load("./spec/config/sgtnclient.yml", "test", './sgtnclient.log')
19
- end
20
-
21
- it "get logger object" do
22
- #expect(@test_logging.logger).to be_a Logger
23
- expect(SgtnClient.logger).to be_a Logger
24
- end
25
-
26
- it "write message to logger" do
27
- test_message = "Example log message!!!"
28
- SgtnClient.logger.debug(test_message)
29
- # @logger_file.rewind
30
- # expect(@logger_file.read).to match test_message
31
- end
32
-
33
- end
@@ -1,53 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SgtnClient do
4
- describe "OfflineAPI" do
5
-
6
- before :each do
7
- env = SgtnClient::Config.default_environment
8
- SgtnClient::Config.configurations[env]["bundle_mode"] = 'offline'
9
- SgtnClient::Source.loadBundles("default")
10
- end
11
-
12
- it "GET" do
13
- expect(SgtnClient::Translation.getString("JAVA", "helloworld", "zh-Hans")).to eq '你好世界'
14
- # get from cache in 2nd time
15
- expect(SgtnClient::Translation.getString("JAVA", "helloworld", "zh-Hans")).to eq '你好世界'
16
-
17
- expect(SgtnClient::Translation.getString_f("JAVA", "welcome", ["机器人", "虚拟世界"], "zh-Hans")).to eq '机器人,欢迎登录虚拟世界!'
18
- # get from cache in 2nd time
19
- expect(SgtnClient::Translation.getString_f("JAVA", "welcome", ["机器人", "虚拟世界"], "zh-Hans")).to eq '机器人,欢迎登录虚拟世界!'
20
- end
21
-
22
- it "GET_EN" do
23
- expect(SgtnClient::Translation.getString("JAVA", "hello", "en")).to eq 'Hello'
24
- # get from cache in 2nd time
25
- expect(SgtnClient::Translation.getString("JAVA", "hello", "en")).to eq 'Hello'
26
- end
27
-
28
- it "GET_zh_CN" do
29
- expect(SgtnClient::Translation.getString("JAVA", "helloworld", "zh-CN")).to eq '你好世界'
30
- # get from cache in 2nd time
31
- expect(SgtnClient::Translation.getString("JAVA", "helloworld", "zh-CN")).to eq '你好世界'
32
- end
33
-
34
- it "NonExistingKey" do
35
- expect(SgtnClient::Translation.getString("JAVA", "hello", "zh-Hans")).to eq 'Hello'
36
- # get from cache in 2nd time
37
- expect(SgtnClient::Translation.getString("JAVA", "hello", "zh-Hans")).to eq 'Hello'
38
-
39
- expect(SgtnClient::Translation.getString_f("JAVA", "login", ["Robot", "VM"], "zh-Hans")).to eq 'Robot login VM!'
40
- # get from cache in 2nd time
41
- expect(SgtnClient::Translation.getString_f("JAVA", "login", ["Robot", "VM"], "zh-Hans")).to eq 'Robot login VM!'
42
- end
43
-
44
- it "Component" do
45
- jsonObj = SgtnClient::Translation.getStrings("JAVA", "zh-Hans");
46
- expect(jsonObj["component"]).to eq 'JAVA'
47
- # get from cache in 2nd time
48
- jsonObj_c = SgtnClient::Translation.getStrings("JAVA", "zh-Hans");
49
- expect(jsonObj_c["component"]).to eq 'JAVA'
50
- end
51
- end
52
-
53
- end
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SgtnClient do
4
- describe "OnlineAPI" do
5
-
6
- before :each do
7
- env = SgtnClient::Config.default_environment
8
- SgtnClient::CacheUtil.clear_cache()
9
- SgtnClient::Config.configurations[env]["bundle_mode"] = 'offline'
10
- SgtnClient::Source.loadBundles("default")
11
- end
12
-
13
- it "GET_EN" do
14
- expect(SgtnClient::Translation.getString("JAVA", "helloworld", "en")).to eq 'Hello world'
15
- # get from cache in 2nd time
16
- expect(SgtnClient::Translation.getString("JAVA", "helloworld", "en")).to eq 'Hello world'
17
- end
18
-
19
- it "GET" do
20
- expect(SgtnClient::Translation.getString("JAVA", "helloworld", "zh-Hans")).to eq '你好世界'
21
- # get from cache in 2nd time
22
- expect(SgtnClient::Translation.getString("JAVA", "helloworld", "zh-Hans")).to eq '你好世界'
23
- end
24
-
25
- it "NonExistingKey" do
26
- expect(SgtnClient::Translation.getString("JAVA", "hello", "zh-Hans")).to eq 'Hello'
27
- # get from cache in 2nd time
28
- expect(SgtnClient::Translation.getString("JAVA", "hello", "zh-Hans")).to eq 'Hello'
29
- end
30
- end
31
-
32
- end
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe VERSION do
4
- describe 'version' do
5
- # test that there is a sane version number to avoid accidental 0.0.0 again
6
- it 'has a version > 0.0.0, < 3.0' do
7
- ver = Gem::Version.new(VERSION)
8
- expect(Gem::Requirement.new('> 0.0.0', '< 3.0')).to be_satisfied_by(ver)
9
- end
10
- end
11
- end