singleton-ruby 0.1.1 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +43 -0
  3. data/lib/sgtn-client/api/source.rb +15 -5
  4. data/lib/sgtn-client/api/t.rb +22 -0
  5. data/lib/sgtn-client/api/translation.rb +23 -8
  6. data/lib/sgtn-client/core/exceptions.rb +2 -2
  7. data/lib/sgtn-client/sgtn-client.rb +1 -0
  8. data/lib/version.rb +1 -1
  9. metadata +22 -71
  10. data/Gemfile +0 -15
  11. data/Rakefile +0 -140
  12. data/lib/generators/sgtnclient/USAGE +0 -3
  13. data/lib/generators/sgtnclient/install_generator.rb +0 -15
  14. data/lib/generators/sgtnclient/templates/sgtnclient.rb +0 -2
  15. data/lib/generators/sgtnclient/templates/sgtnclient.yml +0 -33
  16. data/spec/config/locales/default/JAVA/default.yml +0 -5
  17. data/spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_de.json +0 -8
  18. data/spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_en.json +0 -8
  19. data/spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_latest.json +0 -8
  20. data/spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hans.json +0 -8
  21. data/spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hant.json +0 -8
  22. data/spec/config/locales/l10n/bundles/test/4.8.1/creation.json +0 -10
  23. data/spec/config/locales/l10n/bundles/test/4.8.1/version.json +0 -38
  24. data/spec/config/sample_data.yml +0 -3
  25. data/spec/config/sgtnclient-invalidate.yml +0 -48
  26. data/spec/config/sgtnclient.yml +0 -48
  27. data/spec/log/http.log +0 -0
  28. data/spec/spec_helper.rb +0 -39
  29. data/spec/support/sample_data.rb +0 -5
  30. data/spec/unit/cache_spec.rb +0 -34
  31. data/spec/unit/config_spec.rb +0 -27
  32. data/spec/unit/inconfig_spec.rb +0 -17
  33. data/spec/unit/locale_spec.rb +0 -23
  34. data/spec/unit/logging_spec.rb +0 -33
  35. data/spec/unit/offclient_spec.rb +0 -45
  36. data/spec/unit/onclient_spec.rb +0 -32
  37. data/spec/unit/version_spec.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9dac766ea3b943c3cd35b8ad820eb885f21b4f1c40620c10bce89bfa85301b69
4
- data.tar.gz: 4a63575c8fbe69875e57af536891712571e5f1c310ddc299e8268829ce8e2b11
3
+ metadata.gz: 4a1123e189882d4867128d6933adccda07f53b44ff5b9206ef4d90d6210cc8d7
4
+ data.tar.gz: fa5d43b9fb1b15aab4008cf0d3fa6138137d96eed5eacb8b92c26c79d75f46a8
5
5
  SHA512:
6
- metadata.gz: fc786fd34da1d82450a3f03a860b0cb3458c303c32f8152792484a9ae0cb84060618ddb93acb3b119edf289daccbb2b83ac540e6ed71f02f1c8aae7bf0cb7cde
7
- data.tar.gz: 7c6558c05674b4b786e2245fcdb2b6437d3f495f2c8789e00cd3397f0338d405dc52e4cdcbe92c33c08efbeee2f04721352ee74dc0290f74a0c88f70239dac76
6
+ metadata.gz: fe0b2657ce521442d0987728ce63993f27b928d618a55e8a9e0b020a632ae797c37fc8ad3316295c08292dc08b3d8a2a8f57a4581e2a8e143e10ecf312182e2d
7
+ data.tar.gz: 2fe5be7449a0e5bcd2fa5b9264a35bd625e8987518539f78498ba07da09c6c3269eba4bdfe703b56a932b426c9ac68ac36ad43654866970944923ee097065eb2
data/README.md CHANGED
@@ -7,5 +7,48 @@
7
7
  ## Run Unit Test
8
8
  rake spec:unit
9
9
 
10
+ ## Usage
11
+
12
+ Basic Usage:
13
+
14
+ ```ruby
15
+ require 'singleton-ruby'
16
+
17
+ include SgtnClient
18
+
19
+ SgtnClient.load(file, mode)
20
+
21
+ SgtnClient::Source.loadBundles(locale)
22
+
23
+ @Result = SgtnClient::Translation.getString(component, key, locale)
24
+
25
+ ```
26
+ ## API Usage
27
+
28
+ ### Get a string's translation
29
+ SgtnClient::Translation.getString(component, key, locale)
30
+
31
+ ### Get a string's translation and format it with placeholders
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()
50
+
51
+
52
+
10
53
 
11
54
 
@@ -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
@@ -24,22 +24,33 @@ module SgtnClient
24
24
  return str
25
25
  end
26
26
 
27
+ def self.getSources(component, locale)
28
+ cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale)
29
+ items = SgtnClient::CacheUtil.get_cache(cache_key)
30
+ if items.nil?
31
+ items = getBundle(component, locale)
32
+ SgtnClient.logger.debug "Putting sources items into cache with key: " + cache_key
33
+ SgtnClient::CacheUtil.write_cache(cache_key, items)
34
+ else
35
+ SgtnClient.logger.debug "Getting sources from cache with key: " + cache_key
36
+ end
37
+ return items
38
+ end
39
+
27
40
  def self.loadBundles(locale)
28
41
  env = SgtnClient::Config.default_environment
29
42
  SgtnClient::Config.configurations.default = locale
30
43
  source_bundle = SgtnClient::Config.configurations[env]["source_bundle"]
31
- SgtnClient.logger.debug "Loading [" + locale + "] bundles from path: " + source_bundle
44
+ SgtnClient.logger.debug "Loading [" + locale + "] source bundles from path: " + source_bundle
32
45
  Dir.children(source_bundle).each do |component|
33
46
  yamlfile = File.join(source_bundle, component + "/" + locale + ".yml")
34
47
  bundle = read_yml(yamlfile)
35
48
  cachekey = SgtnClient::CacheUtil.get_cachekey(component, locale)
36
49
  SgtnClient::CacheUtil.write_cache(cachekey,bundle)
37
50
  end
38
-
39
51
  end
40
52
 
41
53
  private
42
-
43
54
  def self.getBundle(component, locale)
44
55
  env = SgtnClient::Config.default_environment
45
56
  source_bundle = SgtnClient::Config.configurations[env]["source_bundle"]
@@ -58,7 +69,6 @@ module SgtnClient
58
69
  erb.filename = file_name
59
70
  YAML.load(erb.result)
60
71
  end
61
-
62
72
  end
63
73
 
64
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
 
@@ -32,17 +32,32 @@ module SgtnClient
32
32
  else
33
33
  return str
34
34
  end
35
-
36
- end
35
+ end
37
36
 
38
37
  def self.getString_f(component, key, args, locale)
39
38
  s = getString(component, key, locale)
40
- puts 1111
41
- puts SgtnClient::Config.configurations.default
42
- puts s
43
- return s % args
39
+ return sprintf s % args
44
40
  end
45
41
 
42
+ def self.getStrings(component, locale)
43
+ flocale = SgtnClient::LocaleUtil.fallback(locale)
44
+ cache_key = SgtnClient::CacheUtil.get_cachekey(component, flocale)
45
+ items = SgtnClient::CacheUtil.get_cache(cache_key)
46
+ if items.nil?
47
+ items = getTranslations(component, flocale)
48
+ SgtnClient::CacheUtil.write_cache(cache_key, items)
49
+ else
50
+ SgtnClient.logger.debug "Getting translations from cache with key: " + cache_key
51
+ end
52
+
53
+ default = SgtnClient::Config.configurations.default
54
+ if items.nil? || items["messages"] == nil
55
+ items = SgtnClient::Source.getSources(component, default)
56
+ end
57
+ return items
58
+ end
59
+
60
+
46
61
  private
47
62
 
48
63
  def self.getTranslations(component, locale)
@@ -64,7 +79,7 @@ module SgtnClient
64
79
  SgtnClient.logger.debug "Getting translations from offline bundle: " + bundlepath
65
80
  begin
66
81
  file = File.read(bundlepath)
67
- data_hash = JSON.parse(file)
82
+ data_hash = MultiJson.load(file)
68
83
  rescue => exception
69
84
  SgtnClient.logger.error exception.message
70
85
  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, 1].freeze
2
+ VERSION_INFO = [0, 1, 5].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.1
4
+ version: 0.1.5
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-20 00:00:00.000000000 Z
11
+ date: 2021-08-27 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,35 +230,16 @@ 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
- description: A Singleton client for Ruby
234
- email: li@vmware.com
233
+ description: Singleton Ruby client
234
+ email: g11n-vip-project@vmware.com
235
235
  executables: []
236
236
  extensions: []
237
237
  extra_rdoc_files:
238
238
  - README.md
239
239
  files:
240
- - Gemfile
241
240
  - README.md
242
- - Rakefile
243
- - lib/generators/sgtnclient/USAGE
244
- - lib/generators/sgtnclient/install_generator.rb
245
- - lib/generators/sgtnclient/templates/sgtnclient.rb
246
- - lib/generators/sgtnclient/templates/sgtnclient.yml
247
241
  - lib/sgtn-client/api/source.rb
242
+ - lib/sgtn-client/api/t.rb
248
243
  - lib/sgtn-client/api/translation.rb
249
244
  - lib/sgtn-client/core/cache.rb
250
245
  - lib/sgtn-client/core/config.rb
@@ -257,31 +252,9 @@ files:
257
252
  - lib/sgtn-client/util/validate-util.rb
258
253
  - lib/singleton-ruby.rb
259
254
  - lib/version.rb
260
- - spec/config/locales/default/JAVA/default.yml
261
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_de.json
262
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_en.json
263
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_latest.json
264
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hans.json
265
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hant.json
266
- - spec/config/locales/l10n/bundles/test/4.8.1/creation.json
267
- - spec/config/locales/l10n/bundles/test/4.8.1/version.json
268
- - spec/config/sample_data.yml
269
- - spec/config/sgtnclient-invalidate.yml
270
- - spec/config/sgtnclient.yml
271
- - spec/log/http.log
272
- - spec/spec_helper.rb
273
- - spec/support/sample_data.rb
274
- - spec/unit/cache_spec.rb
275
- - spec/unit/config_spec.rb
276
- - spec/unit/inconfig_spec.rb
277
- - spec/unit/locale_spec.rb
278
- - spec/unit/logging_spec.rb
279
- - spec/unit/offclient_spec.rb
280
- - spec/unit/onclient_spec.rb
281
- - spec/unit/version_spec.rb
282
255
  homepage: https://github.com/vmware/singleton
283
256
  licenses:
284
- - MIT
257
+ - EPL 2.0
285
258
  metadata: {}
286
259
  post_install_message:
287
260
  rdoc_options: []
@@ -301,27 +274,5 @@ requirements: []
301
274
  rubygems_version: 3.0.9
302
275
  signing_key:
303
276
  specification_version: 4
304
- summary: Singleton client for Ruby.
305
- test_files:
306
- - spec/config/locales/default/JAVA/default.yml
307
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_de.json
308
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_en.json
309
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_latest.json
310
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hans.json
311
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hant.json
312
- - spec/config/locales/l10n/bundles/test/4.8.1/creation.json
313
- - spec/config/locales/l10n/bundles/test/4.8.1/version.json
314
- - spec/config/sample_data.yml
315
- - spec/config/sgtnclient-invalidate.yml
316
- - spec/config/sgtnclient.yml
317
- - spec/log/http.log
318
- - spec/spec_helper.rb
319
- - spec/support/sample_data.rb
320
- - spec/unit/cache_spec.rb
321
- - spec/unit/config_spec.rb
322
- - spec/unit/inconfig_spec.rb
323
- - spec/unit/locale_spec.rb
324
- - spec/unit/logging_spec.rb
325
- - spec/unit/offclient_spec.rb
326
- - spec/unit/onclient_spec.rb
327
- - spec/unit/version_spec.rb
277
+ summary: Singleton Ruby client
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,3 +0,0 @@
1
- To copy a sgtnclient SDK default configuration and initializer to your Rails App.
2
-
3
- rails g sgtnclient:install
@@ -1,15 +0,0 @@
1
- module SgtnClient
2
- module Generators
3
- class InstallGenerator < Rails::Generators::Base
4
- source_root File.expand_path('../templates', __FILE__)
5
-
6
- def copy_config_file
7
- copy_file "sgtnclient.yml", "config/sgtnclient.yml"
8
- end
9
-
10
- def copy_initializer_file
11
- copy_file "sgtnclient.rb", "config/initializers/sgtnclient.rb"
12
- end
13
- end
14
- end
15
- end
@@ -1,2 +0,0 @@
1
- SgtnClient.load("config/sgtnclient.yml", Rails.env)
2
- PSgtnClient.logger = Rails.logger
@@ -1,33 +0,0 @@
1
- test: &default
2
-
3
- # Credentials for REST APIs
4
- client_id: tee
5
- client_secret: 89987
6
-
7
- # Mode can be 'live' or 'sandbox'
8
- mode: sandbox
9
-
10
- # Credentials for Classic APIs
11
- app_id: APP-80W284485P519543T
12
- username: linr
13
- password: fdasf
14
- signature: sfds-RWy
15
- # # With Certificate
16
- # cert_path: "config/cert_key.pem"
17
- sandbox_email_address: linr@aa.com
18
-
19
- # #Product Name
20
- product_name: test
21
-
22
- # # bundle version
23
- version: 4.8.1
24
-
25
- # # HTTP Proxy
26
- vip_server: https://server:8090
27
-
28
- development:
29
- <<: *default
30
-
31
- production:
32
- <<: *default
33
- mode: live
@@ -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,48 +0,0 @@
1
- test: &default
2
-
3
- # Credentials for REST APIs
4
- client_id: tee
5
- client_secret: 89987
6
-
7
- # Mode can be 'live' or 'sandbox'
8
- mode: sandbox1
9
-
10
- # Credentials for Classic APIs
11
- app_id: APP-80W284485P519543T
12
- username: linr
13
- password: fdasf
14
- signature: sfds-RWy
15
- # # With Certificate
16
- # cert_path: "config/cert_key.pem"
17
- sandbox_email_address: linr@aa.com
18
-
19
- # #Product Name
20
- product_name: test
21
-
22
- # # bundle version
23
- version: 4.8
24
-
25
- # # HTTP Proxy
26
- vip_server: https://server:8090
27
-
28
- # # mode of bundle: online/offline
29
- bundle_mode: offline1www
30
-
31
- # # translation bundle Path
32
- translation_bundle: ./spec/config/locales/l10n/bundles
33
-
34
- # # source bundle Path
35
- source_bundle: ./spec/config/locales/default
36
-
37
- # # memory cache's expration(minutes), default value is 24*60
38
- cache_expiry_period: 36t
39
-
40
- # # disable cache, it's optional setting
41
- disable_cache: true1
42
-
43
- development:
44
- <<: *default
45
-
46
- production:
47
- <<: *default
48
- mode: live
@@ -1,48 +0,0 @@
1
- test: &default
2
-
3
- # Credentials for REST APIs
4
- client_id: tee
5
- client_secret: 89987
6
-
7
- # Mode can be 'live' or 'sandbox'
8
- mode: sandbox
9
-
10
- # Credentials for Classic APIs
11
- app_id: APP-80W284485P519543T
12
- username: linr
13
- password: fdasf
14
- signature: sfds-RWy
15
- # # With Certificate
16
- # cert_path: "config/cert_key.pem"
17
- sandbox_email_address: linr@aa.com
18
-
19
- # #Product Name
20
- product_name: test
21
-
22
- # # bundle version
23
- version: 4.8.1
24
-
25
- # # HTTP Proxy
26
- vip_server: https://server:8090
27
-
28
- # # mode of bundle: online/offline
29
- bundle_mode: offline
30
-
31
- # # translation bundle Path
32
- translation_bundle: ./spec/config/locales/l10n/bundles
33
-
34
- # # source bundle Path
35
- source_bundle: ./spec/config/locales/default
36
-
37
- # # memory cache's expration(minutes), default value is 24*60
38
- cache_expiry_period: 10
39
-
40
- # # disable cache, it's optional setting
41
- ##disable_cache: true
42
-
43
- development:
44
- <<: *default
45
-
46
- production:
47
- <<: *default
48
- mode: live
data/spec/log/http.log DELETED
File without changes
data/spec/spec_helper.rb DELETED
@@ -1,39 +0,0 @@
1
- require 'bundler/setup'
2
- require_relative '../lib/sgtn-client/sgtn-client.rb'
3
- require 'twitter_cldr'
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
- #SgtnClient.load("./spec/config/sgtnclient.yml", "test")
16
-
17
- #require 'SgtnClient'
18
-
19
- include SgtnClient
20
- include SgtnClient::Logging
21
- include SgtnClient::Exceptions
22
-
23
- require 'logger'
24
-
25
- SgtnClient.load("./spec/config/sgtnclient.yml", "test", './sgtnclient.log')
26
-
27
- Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f }
28
-
29
- # Set logger for http
30
- http_log = File.open(File.expand_path('../log/http.log', __FILE__), "w")
31
- #Payment.api.http.set_debug_output(http_log)
32
-
33
- RSpec.configure do |config|
34
- config.filter_run_excluding :integration => true
35
- config.filter_run_excluding :disabled => true
36
- config.include SampleData
37
- end
38
-
39
- 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,45 +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
- end
44
-
45
- 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