singleton-ruby 0.1.4 → 0.1.8

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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -4
  3. data/lib/sgtn-client/api/translation.rb +16 -7
  4. data/lib/sgtn-client/cldr/core_ext.rb +4 -0
  5. data/lib/sgtn-client/cldr/localized_date.rb +27 -0
  6. data/lib/sgtn-client/cldr/localized_datetime.rb +27 -0
  7. data/lib/sgtn-client/cldr/localized_str.rb +11 -0
  8. data/lib/sgtn-client/cldr/localized_time.rb +27 -0
  9. data/lib/sgtn-client/core/exceptions.rb +2 -2
  10. data/lib/sgtn-client/formatters/plurals/plural_formatter.rb +38 -0
  11. data/lib/sgtn-client/sgtn-client.rb +5 -0
  12. data/lib/singleton-ruby.rb +2 -1
  13. data/lib/version.rb +1 -1
  14. metadata +39 -53
  15. data/Gemfile +0 -15
  16. data/Rakefile +0 -140
  17. data/spec/config/locales/default/JAVA/default.yml +0 -5
  18. data/spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_de.json +0 -8
  19. data/spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_en.json +0 -8
  20. data/spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_latest.json +0 -8
  21. data/spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hans.json +0 -8
  22. data/spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hant.json +0 -8
  23. data/spec/config/locales/l10n/bundles/test/4.8.1/creation.json +0 -10
  24. data/spec/config/locales/l10n/bundles/test/4.8.1/version.json +0 -38
  25. data/spec/config/sample_data.yml +0 -3
  26. data/spec/config/sgtnclient-invalidate.yml +0 -44
  27. data/spec/config/sgtnclient.yml +0 -44
  28. data/spec/log/http.log +0 -0
  29. data/spec/spec_helper.rb +0 -33
  30. data/spec/support/sample_data.rb +0 -5
  31. data/spec/unit/cache_spec.rb +0 -34
  32. data/spec/unit/config_spec.rb +0 -27
  33. data/spec/unit/inconfig_spec.rb +0 -17
  34. data/spec/unit/locale_spec.rb +0 -23
  35. data/spec/unit/logging_spec.rb +0 -33
  36. data/spec/unit/offclient_spec.rb +0 -53
  37. data/spec/unit/onclient_spec.rb +0 -32
  38. data/spec/unit/request_spec.rb +0 -22
  39. data/spec/unit/version_spec.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ffce54daa3338aaac24e5f302d46ea2b0d786def7c20dc5d737d5f8e839844d2
4
- data.tar.gz: 934df8d9afc326b09981f12460e822db864ccb35f3e992c67b066689258343bf
3
+ metadata.gz: c8b76321098ddc3fbe0600be0b766f3e1162d546bf162ca564e896cf570cbbfe
4
+ data.tar.gz: 8a87437293352085857b30878de95c74e2d9de24066c659e86ccd38fab7e811d
5
5
  SHA512:
6
- metadata.gz: 6ec453c3a483d728b165cf734a2aaf361f4be3582579ec1853b49aa9ac3ece43fd1ffb1215b42a13bb90662ad53c16d723eb8123a747d7a5aeeb3bc22310639a
7
- data.tar.gz: 2a073e29ebe320b9336156d80832f89f1b05300398d8ca5fb0551cc51772aa33359ee71652d0bc538d7e29e6f52b44bebc054232ec9bf06b22a7368710d61329
6
+ metadata.gz: d5230c379270046dd49f65164dbe68d71620944bebb09b338522e9b2753c858ad2a40dc7ed0a26c71468ea5ed6de02874217d1fe7542ca584b803fd7c1cada8e
7
+ data.tar.gz: cbbffd1ea904726238bdf5ef8662d82fcba89cca29416ac4424210ebd10077bcb5fbd7f1a152bf7157426634258c98b0a6143aef7462e85bbdd4db97e79d7e40
data/README.md CHANGED
@@ -23,7 +23,7 @@ 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)
@@ -35,10 +35,9 @@ SgtnClient::Translation.getString_f(component, key, args, locale)
35
35
  SgtnClient::Translation.getStrings(component, locale)
36
36
 
37
37
 
38
- ## API with request_store
38
+ ## API Usage(with request_store)
39
39
 
40
- Before call below APIs(without locale and component arguments), it requires to set the locale
41
- and component add the initial codes.
40
+ Before call below APIs(without locale and component arguments), it requires to set the locale and component in the initial codes.
42
41
 
43
42
  ### Get a string's translation
44
43
  SgtnClient::T.s(key)
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'multi_json'
2
2
 
3
3
  module SgtnClient
4
4
 
@@ -36,10 +36,14 @@ 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 args.is_a?(Hash)
40
+ args.each do |source, arg|
41
+ s.gsub! "{#{source}}", arg
42
+ end
43
+ elsif args.is_a?(Array)
44
+ s = sprintf s % args
45
+ end
46
+ return s
43
47
  end
44
48
 
45
49
  def self.getStrings(component, locale)
@@ -55,7 +59,12 @@ module SgtnClient
55
59
 
56
60
  default = SgtnClient::Config.configurations.default
57
61
  if items.nil? || items["messages"] == nil
58
- items = SgtnClient::Source.getSources(component, default)
62
+ items = {}
63
+ s = SgtnClient::Source.getSources(component, default)
64
+ default_component, value = s.first
65
+ items["component"] = default_component
66
+ items["messages"] = value
67
+ items["locale"] = 'source'
59
68
  end
60
69
  return items
61
70
  end
@@ -82,7 +91,7 @@ module SgtnClient
82
91
  SgtnClient.logger.debug "Getting translations from offline bundle: " + bundlepath
83
92
  begin
84
93
  file = File.read(bundlepath)
85
- data_hash = JSON.parse(file)
94
+ data_hash = MultiJson.load(file)
86
95
  rescue => exception
87
96
  SgtnClient.logger.error exception.message
88
97
  end
@@ -0,0 +1,4 @@
1
+ require 'sgtn-client/cldr/localized_datetime'
2
+ require 'sgtn-client/cldr/localized_date'
3
+ require 'sgtn-client/cldr/localized_time'
4
+ require 'sgtn-client/cldr/localized_str'
@@ -0,0 +1,27 @@
1
+ require 'date'
2
+ require 'time'
3
+
4
+ Date.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
5
+ def l_full_s(locale = TwitterCldr.locale)
6
+ self.to_datetime().localize(locale).to_date().to_full_s
7
+ end
8
+ LOCALIZE
9
+
10
+ Date.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
11
+ def l_long_s(locale = TwitterCldr.locale)
12
+ self.to_datetime().localize(locale).to_date().to_long_s
13
+ end
14
+ LOCALIZE
15
+
16
+ Date.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
17
+ def l_medium_s(locale = TwitterCldr.locale)
18
+ self.to_datetime().localize(locale).to_date().to_medium_s
19
+ end
20
+ LOCALIZE
21
+
22
+
23
+ Date.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
24
+ def l_short_s(locale = TwitterCldr.locale)
25
+ self.to_datetime().localize(locale).to_date().to_short_s
26
+ end
27
+ LOCALIZE
@@ -0,0 +1,27 @@
1
+ require 'date'
2
+ require 'time'
3
+
4
+ DateTime.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
5
+ def l_full_s(locale = TwitterCldr.locale)
6
+ self.localize(locale).to_full_s
7
+ end
8
+ LOCALIZE
9
+
10
+ DateTime.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
11
+ def l_long_s(locale = TwitterCldr.locale)
12
+ self.localize(locale).to_long_s
13
+ end
14
+ LOCALIZE
15
+
16
+ DateTime.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
17
+ def l_medium_s(locale = TwitterCldr.locale)
18
+ self.localize(locale).to_medium_s
19
+ end
20
+ LOCALIZE
21
+
22
+
23
+ DateTime.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
24
+ def l_short_s(locale = TwitterCldr.locale)
25
+ self.localize(locale).to_short_s
26
+ end
27
+ LOCALIZE
@@ -0,0 +1,11 @@
1
+
2
+ String.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
3
+ def to_plural_s(locale, arg)
4
+ num_str = SgtnClient::Formatters::PluralFormatter.new(locale).num_s(self, arg)
5
+ if num_str.nil? || num_str.empty?
6
+ self.localize(locale) % arg
7
+ else
8
+ num_str
9
+ end
10
+ end
11
+ LOCALIZE
@@ -0,0 +1,27 @@
1
+ require 'date'
2
+ require 'time'
3
+
4
+ Time.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
5
+ def l_full_s(locale = TwitterCldr.locale)
6
+ self.localize(locale).to_full_s
7
+ end
8
+ LOCALIZE
9
+
10
+ Time.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
11
+ def l_long_s(locale = TwitterCldr.locale)
12
+ self.localize(locale).to_long_s
13
+ end
14
+ LOCALIZE
15
+
16
+ Time.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
17
+ def l_medium_s(locale = TwitterCldr.locale)
18
+ self.localize(locale).to_medium_s
19
+ end
20
+ LOCALIZE
21
+
22
+
23
+ Time.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
24
+ def l_short_s(locale = TwitterCldr.locale)
25
+ self.localize(locale).to_short_s
26
+ end
27
+ LOCALIZE
@@ -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 == ''
@@ -0,0 +1,38 @@
1
+ require 'json'
2
+
3
+ module SgtnClient
4
+ module Formatters
5
+ class PluralFormatter
6
+
7
+ attr_reader :locale
8
+
9
+ def initialize(locale = TwitterCldr.locale)
10
+ @locale = TwitterCldr.convert_locale(locale)
11
+ end
12
+
13
+ def num_s(string, replacements)
14
+ reg = Regexp.union(
15
+ /%<(\{.*?\})>/
16
+ )
17
+ string.gsub(reg) do |match|
18
+ count_placeholder, patterns = if $1
19
+ pluralization_hash = JSON.parse($1)
20
+ if pluralization_hash.is_a?(Hash) && pluralization_hash.size == 1
21
+ pluralization_hash.first
22
+ else
23
+ raise ArgumentError.new('expected a Hash with a single key')
24
+ end
25
+ else
26
+ raise ArgumentError.new('invalide format')
27
+ end
28
+ count = replacements[count_placeholder.to_sym].to_s
29
+ if patterns.is_a?(Hash)
30
+ return TwitterCldr::Utils.deep_symbolize_keys(patterns)[count.to_sym]
31
+ else
32
+ raise ArgumentError.new('expected patterns to be a Hash')
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -12,6 +12,11 @@ module SgtnClient
12
12
  autoload :ValidateUtil, "sgtn-client/util/validate-util"
13
13
  autoload :LocaleUtil, "sgtn-client/util/locale-util"
14
14
 
15
+ module Formatters
16
+ autoload :PluralFormatter, "sgtn-client/formatters/plurals/plural_formatter"
17
+ end
18
+
19
+
15
20
  class << self
16
21
  def configure(options = {}, &block)
17
22
  SgtnClient::Config.configure(options, &block)
@@ -1,2 +1,3 @@
1
1
  require "sgtn-client/sgtn-client"
2
-
2
+ require 'sgtn-client/cldr/core_ext'
3
+ require 'twitter_cldr'
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
 
2
- VERSION_INFO = [0, 1, 4].freeze
2
+ VERSION_INFO = [0, 1, 8].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.4
4
+ version: 0.1.8
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-26 00:00:00.000000000 Z
11
+ date: 2021-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: twitter_cldr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '6.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '6.6'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: webmock
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -230,6 +244,20 @@ dependencies:
230
244
  - - "~>"
231
245
  - !ruby/object:Gem::Version
232
246
  version: '1.0'
247
+ - !ruby/object:Gem::Dependency
248
+ name: twitter_cldr
249
+ requirement: !ruby/object:Gem::Requirement
250
+ requirements:
251
+ - - "~>"
252
+ - !ruby/object:Gem::Version
253
+ version: '6.6'
254
+ type: :runtime
255
+ prerelease: false
256
+ version_requirements: !ruby/object:Gem::Requirement
257
+ requirements:
258
+ - - "~>"
259
+ - !ruby/object:Gem::Version
260
+ version: '6.6'
233
261
  description: Singleton Ruby client
234
262
  email: g11n-vip-project@vmware.com
235
263
  executables: []
@@ -237,49 +265,30 @@ extensions: []
237
265
  extra_rdoc_files:
238
266
  - README.md
239
267
  files:
240
- - Gemfile
241
268
  - README.md
242
- - Rakefile
243
269
  - lib/sgtn-client/api/source.rb
244
270
  - lib/sgtn-client/api/t.rb
245
271
  - lib/sgtn-client/api/translation.rb
272
+ - lib/sgtn-client/cldr/core_ext.rb
273
+ - lib/sgtn-client/cldr/localized_date.rb
274
+ - lib/sgtn-client/cldr/localized_datetime.rb
275
+ - lib/sgtn-client/cldr/localized_str.rb
276
+ - lib/sgtn-client/cldr/localized_time.rb
246
277
  - lib/sgtn-client/core/cache.rb
247
278
  - lib/sgtn-client/core/config.rb
248
279
  - lib/sgtn-client/core/exceptions.rb
249
280
  - lib/sgtn-client/core/logging.rb
250
281
  - lib/sgtn-client/core/request.rb
282
+ - lib/sgtn-client/formatters/plurals/plural_formatter.rb
251
283
  - lib/sgtn-client/sgtn-client.rb
252
284
  - lib/sgtn-client/util/cache-util.rb
253
285
  - lib/sgtn-client/util/locale-util.rb
254
286
  - lib/sgtn-client/util/validate-util.rb
255
287
  - lib/singleton-ruby.rb
256
288
  - lib/version.rb
257
- - spec/config/locales/default/JAVA/default.yml
258
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_de.json
259
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_en.json
260
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_latest.json
261
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hans.json
262
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hant.json
263
- - spec/config/locales/l10n/bundles/test/4.8.1/creation.json
264
- - spec/config/locales/l10n/bundles/test/4.8.1/version.json
265
- - spec/config/sample_data.yml
266
- - spec/config/sgtnclient-invalidate.yml
267
- - spec/config/sgtnclient.yml
268
- - spec/log/http.log
269
- - spec/spec_helper.rb
270
- - spec/support/sample_data.rb
271
- - spec/unit/cache_spec.rb
272
- - spec/unit/config_spec.rb
273
- - spec/unit/inconfig_spec.rb
274
- - spec/unit/locale_spec.rb
275
- - spec/unit/logging_spec.rb
276
- - spec/unit/offclient_spec.rb
277
- - spec/unit/onclient_spec.rb
278
- - spec/unit/request_spec.rb
279
- - spec/unit/version_spec.rb
280
289
  homepage: https://github.com/vmware/singleton
281
290
  licenses:
282
- - EPL
291
+ - EPL 2.0
283
292
  metadata: {}
284
293
  post_install_message:
285
294
  rdoc_options: []
@@ -296,31 +305,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
296
305
  - !ruby/object:Gem::Version
297
306
  version: '0'
298
307
  requirements: []
299
- rubygems_version: 3.0.9
308
+ rubygems_version: 3.2.3
300
309
  signing_key:
301
310
  specification_version: 4
302
311
  summary: Singleton Ruby client
303
- test_files:
304
- - spec/config/locales/default/JAVA/default.yml
305
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_de.json
306
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_en.json
307
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_latest.json
308
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hans.json
309
- - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hant.json
310
- - spec/config/locales/l10n/bundles/test/4.8.1/creation.json
311
- - spec/config/locales/l10n/bundles/test/4.8.1/version.json
312
- - spec/config/sample_data.yml
313
- - spec/config/sgtnclient-invalidate.yml
314
- - spec/config/sgtnclient.yml
315
- - spec/log/http.log
316
- - spec/spec_helper.rb
317
- - spec/support/sample_data.rb
318
- - spec/unit/cache_spec.rb
319
- - spec/unit/config_spec.rb
320
- - spec/unit/inconfig_spec.rb
321
- - spec/unit/locale_spec.rb
322
- - spec/unit/logging_spec.rb
323
- - spec/unit/offclient_spec.rb
324
- - spec/unit/onclient_spec.rb
325
- - spec/unit/request_spec.rb
326
- - spec/unit/version_spec.rb
312
+ 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,22 +0,0 @@
1
- require 'spec_helper'
2
- require 'request_store'
3
-
4
- describe SgtnClient do
5
- describe "Locale" do
6
-
7
- before :each do
8
- env = SgtnClient::Config.default_environment
9
- SgtnClient::Config.configurations[env]["bundle_mode"] = 'offline'
10
- SgtnClient::Source.loadBundles("default")
11
- RequestStore.store[:locale] = 'zh-Hans'
12
- RequestStore.store[:component] = 'JAVA'
13
- end
14
-
15
- it "GET" do
16
- expect(SgtnClient::T.s("helloworld")).to eq '你好世界'
17
- expect(SgtnClient::T.s_f("welcome", ["机器人", "虚拟世界"])).to eq '机器人,欢迎登录虚拟世界!'
18
- expect(SgtnClient::T.c()["component"]).to eq 'JAVA'
19
- end
20
- end
21
-
22
- 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