singleton-client-test 0.7.0.23 → 0.7.0.27
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sgtn-client/api/translation.rb +26 -24
- data/lib/sgtn-client/core/cache.rb +18 -18
- data/lib/sgtn-client/core/config.rb +1 -1
- data/lib/sgtn-client/core/request.rb +5 -1
- data/lib/sgtn-client/util/cache-util.rb +6 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0989ae16ca4fcfd6088931a367ac5eb671fd8e087a8d9e32539a2480d1107b34'
|
4
|
+
data.tar.gz: d750961a5b1c116914f50a947626e0fc4e8a391b3fa28b8e2a77e3651c823ba2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89e893c6f79dde564732300a4431581effb0dc6aeb7eb3f8fc665c8108d4eaf0292a64e962da259f931c9ebf21299ae05d0db4cac427ec78c5a50c3c81d9a562
|
7
|
+
data.tar.gz: fd50009cbda5e06c8e1a3d7f81ec02c6b1d060fec95d6824b8e8713f33c48acad660be1e276ee565403cc8eda5abcf9d8f6f0faa936b895ceb9cef29feec0dbd
|
@@ -42,16 +42,7 @@ module SgtnClient
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.getStrings(component, locale)
|
45
|
-
|
46
|
-
cache_key = SgtnClient::CacheUtil.get_cachekey(component, flocale)
|
47
|
-
items = SgtnClient::CacheUtil.get_cache(cache_key)
|
48
|
-
if items.nil?
|
49
|
-
items = getTranslations(component, flocale)
|
50
|
-
SgtnClient::CacheUtil.write_cache(cache_key, items)
|
51
|
-
else
|
52
|
-
SgtnClient.logger.debug "Getting translations from cache with key: " + cache_key
|
53
|
-
end
|
54
|
-
|
45
|
+
items = get_cs(component, locale)
|
55
46
|
default = SgtnClient::Config.configurations.default
|
56
47
|
if items.nil? || items["messages"] == nil
|
57
48
|
items = {}
|
@@ -68,33 +59,44 @@ module SgtnClient
|
|
68
59
|
private
|
69
60
|
|
70
61
|
def self.getTranslation(component, key, locale)
|
62
|
+
items = get_cs(component, locale)
|
63
|
+
if items.nil? || items["messages"] == nil
|
64
|
+
nil
|
65
|
+
else
|
66
|
+
items["messages"][key]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.get_cs(component, locale)
|
71
71
|
flocale = SgtnClient::LocaleUtil.fallback(locale)
|
72
72
|
cache_key = SgtnClient::CacheUtil.get_cachekey(component, flocale)
|
73
73
|
items = SgtnClient::CacheUtil.get_cache(cache_key)
|
74
74
|
if items.nil?
|
75
|
-
items =
|
76
|
-
|
75
|
+
items = load(component, flocale)
|
76
|
+
if items.nil?
|
77
|
+
items = SgtnClient::Source.getSources(component, SgtnClient::Config.configurations.default)
|
78
|
+
SgtnClient::Core::Cache.put(cache_key, items, 60)
|
79
|
+
else
|
80
|
+
SgtnClient::CacheUtil.write_cache(cache_key, items)
|
81
|
+
end
|
77
82
|
else
|
78
83
|
SgtnClient.logger.debug "Getting translations from cache with key: " + cache_key
|
79
84
|
end
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
def self.getTranslations(component, locale)
|
85
|
+
|
86
|
+
return items
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.load(component, locale)
|
88
90
|
env = SgtnClient::Config.default_environment
|
89
91
|
mode = SgtnClient::Config.configurations[env]["bundle_mode"]
|
90
92
|
if mode == 'offline'
|
91
|
-
return
|
93
|
+
return load_o(component, locale)
|
92
94
|
else
|
93
|
-
return
|
95
|
+
return load_s(component, locale)
|
94
96
|
end
|
95
97
|
end
|
96
98
|
|
97
|
-
def self.
|
99
|
+
def self.load_o(component, locale)
|
98
100
|
env = SgtnClient::Config.default_environment
|
99
101
|
product_name = SgtnClient::Config.configurations[env]["product_name"]
|
100
102
|
version = SgtnClient::Config.configurations[env]["version"].to_s
|
@@ -104,7 +106,7 @@ module SgtnClient
|
|
104
106
|
SgtnClient::FileUtil.read_json(bundlepath)
|
105
107
|
end
|
106
108
|
|
107
|
-
def self.
|
109
|
+
def self.load_s(component, locale)
|
108
110
|
env = SgtnClient::Config.default_environment
|
109
111
|
product_name = SgtnClient::Config.configurations[env]["product_name"]
|
110
112
|
vip_server = SgtnClient::Config.configurations[env]["vip_server"]
|
@@ -5,11 +5,11 @@ module SgtnClient::Core
|
|
5
5
|
Entry = Struct.new(:expiry, :value)
|
6
6
|
|
7
7
|
def self.initialize(disabled=false, opts={})
|
8
|
-
|
8
|
+
@@opts = opts
|
9
9
|
@mutex = Mutex.new
|
10
10
|
SgtnClient.logger.debug "Initialize cache......"
|
11
11
|
if disabled == false
|
12
|
-
|
12
|
+
@@data = Hash.new
|
13
13
|
SgtnClient.logger.debug "Cache is enabled!"
|
14
14
|
else
|
15
15
|
SgtnClient.logger.debug "Cache is disabled!"
|
@@ -17,74 +17,74 @@ module SgtnClient::Core
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.keys
|
20
|
-
if
|
20
|
+
if @@data == nil
|
21
21
|
return nil
|
22
22
|
end
|
23
23
|
SgtnClient.logger.debug "Get cache keys"
|
24
|
-
|
24
|
+
@@data.keys
|
25
25
|
end
|
26
26
|
|
27
27
|
def self.get(key)
|
28
|
-
if
|
28
|
+
if @@data == nil
|
29
29
|
return nil
|
30
30
|
end
|
31
31
|
SgtnClient.logger.debug "Get cache for key: " + key
|
32
32
|
invalidate
|
33
|
-
|
33
|
+
@@data[key][:value] if has(key)
|
34
34
|
end
|
35
35
|
|
36
36
|
def self.has(key)
|
37
|
-
if
|
37
|
+
if @@data == nil
|
38
38
|
return nil
|
39
39
|
end
|
40
40
|
SgtnClient.logger.debug "Has cache for key: " + key
|
41
|
-
|
41
|
+
@@data.has_key? key
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.put(key, value, ttl=nil)
|
45
45
|
@mutex.synchronize do
|
46
|
-
if
|
46
|
+
if @@data == nil
|
47
47
|
return nil
|
48
48
|
end
|
49
|
-
ttl ||=
|
49
|
+
ttl ||= @@opts[:ttl]
|
50
50
|
# hours from new
|
51
51
|
SgtnClient.logger.debug "Put cache for key '" + key + "' with expired time at'" + (Time.now + ttl*60).to_s
|
52
|
-
|
52
|
+
@@data[key] = Entry.new(Time.now + ttl*60, value)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
def self.delete(key)
|
57
57
|
@mutex.synchronize do
|
58
|
-
if
|
58
|
+
if @@data == nil
|
59
59
|
return nil
|
60
60
|
end
|
61
61
|
SgtnClient.logger.debug "Delete cache for key: " + key
|
62
|
-
|
62
|
+
@@data.delete key
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
def self.clear
|
67
67
|
@mutex.synchronize do
|
68
|
-
if
|
68
|
+
if @@data == nil
|
69
69
|
return nil
|
70
70
|
end
|
71
71
|
SgtnClient.logger.debug "Clear cache!"
|
72
|
-
|
72
|
+
@@data = Hash.new
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
76
|
def self.invalidate
|
77
77
|
@mutex.synchronize do
|
78
|
-
if
|
78
|
+
if @@data == nil
|
79
79
|
return nil
|
80
80
|
end
|
81
81
|
SgtnClient.logger.debug "Invalidating expired cache......"
|
82
82
|
now = Time.now
|
83
|
-
|
83
|
+
@@data.each {
|
84
84
|
|k, v|
|
85
85
|
SgtnClient.logger.debug "Checking cache: key=#{k}, expiredtime=#{v[:expiry]}, now=#{now}, expired=#{(v[:expiry] < now)}"
|
86
86
|
}
|
87
|
-
|
87
|
+
@@data.delete_if {|k, v| v[:expiry] < now}
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
@@ -40,7 +40,7 @@ module SgtnClient
|
|
40
40
|
:rest_endpoint, :rest_token_endpoint, :client_id, :client_secret,
|
41
41
|
:openid_endpoint, :openid_redirect_uri, :openid_client_id, :openid_client_secret,
|
42
42
|
:verbose_logging, :product_name, :version, :vip_server, :bundle_mode,
|
43
|
-
:translation_bundle, :source_bundle, :cache_expiry_period, :disable_cache
|
43
|
+
:translation_bundle, :source_bundle, :cache_expiry_period, :disable_cache, :default_language
|
44
44
|
|
45
45
|
|
46
46
|
# Create Config object
|
@@ -4,7 +4,11 @@ require 'multi_json'
|
|
4
4
|
module SgtnClient::Core
|
5
5
|
class Request
|
6
6
|
def self.get(url)
|
7
|
-
res = RestClient.get(url)
|
7
|
+
#res = RestClient.get(url)
|
8
|
+
res = RestClient::Resource.new(
|
9
|
+
url,
|
10
|
+
:verify_ssl => false
|
11
|
+
).get
|
8
12
|
begin
|
9
13
|
obj = MultiJson.load(res)
|
10
14
|
rescue MultiJson::ParseError => exception
|
@@ -32,7 +32,12 @@ module SgtnClient
|
|
32
32
|
env = SgtnClient::Config.default_environment
|
33
33
|
product_name = SgtnClient::Config.configurations[env]["product_name"]
|
34
34
|
version = SgtnClient::Config.configurations[env]["version"].to_s
|
35
|
-
|
35
|
+
default_l = SgtnClient::Config.configurations[env]["default_language"]
|
36
|
+
if default_l == nil
|
37
|
+
default_l = 'en'
|
38
|
+
end
|
39
|
+
lc = locale == default_l ? SgtnClient::Config.configurations.default: locale
|
40
|
+
return product_name + "_" + version + "_" + component + "_" + lc
|
36
41
|
end
|
37
42
|
end
|
38
43
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: singleton-client-test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.0.
|
4
|
+
version: 0.7.0.27
|
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: 2022-01-
|
11
|
+
date: 2022-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -306,7 +306,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
306
306
|
- !ruby/object:Gem::Version
|
307
307
|
version: '0'
|
308
308
|
requirements: []
|
309
|
-
rubygems_version: 3.
|
309
|
+
rubygems_version: 3.2.22
|
310
310
|
signing_key:
|
311
311
|
specification_version: 4
|
312
312
|
summary: Singleton Ruby client
|