groundcontrolsh 0.1.0 → 0.1.1
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 +4 -4
- data/lib/groundcontrolsh.rb +16 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47cd56b1bd7755057d733359ef3e4291b1eccf94435843e1f7e6625d5131956f
|
4
|
+
data.tar.gz: 7c78379b5a082803d9dd154d23a819a0fd42542efc52ce0eab2c82a56633cbcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb5e7467b6a1c14dbc22deb1ba984983877211c449a5a6bcf1c728aa2b3b1a8f32d938ee86b4d3d10aa995c6169078620a4f675c336474d40fa2c9b2808d17a5
|
7
|
+
data.tar.gz: 67932fe1d30795d5cefcd8a8bdf4ea0166a4d43a19d150178570ba131a7eb1a922b1d5fa9933f9c33e7b26e77565f6d80219fbd84b2c9e3bb745e9edafef61bb
|
data/lib/groundcontrolsh.rb
CHANGED
@@ -9,16 +9,24 @@ class GroundControl
|
|
9
9
|
@project_id = project_id
|
10
10
|
@api_key = api_key
|
11
11
|
@base_url = options[:base_url] || 'https://api.groundcontrol.sh'
|
12
|
-
|
12
|
+
@ttl = options[:cache] || nil
|
13
|
+
@cache = {}
|
13
14
|
end
|
14
15
|
|
15
16
|
def feature_flag_enabled?(feature_name, options = {})
|
16
17
|
actors = options[:actors] || []
|
17
18
|
|
18
19
|
query = actors.map { |actor| "actorIds=#{CGI.escape(actor)}" }
|
19
|
-
# query << "cache=#{@cache}" if @cache
|
20
20
|
|
21
21
|
url = URI("#{@base_url}/projects/#{@project_id}/flags/#{feature_name}/check?#{query.join('&')}")
|
22
|
+
cached = @cache[url]
|
23
|
+
if cached
|
24
|
+
if cached[:expires] < Time.now.to_i
|
25
|
+
@cache.delete(url)
|
26
|
+
end
|
27
|
+
return cached[:enabled]
|
28
|
+
end
|
29
|
+
|
22
30
|
http = Net::HTTP.new(url.host, url.port)
|
23
31
|
http.use_ssl = true
|
24
32
|
|
@@ -29,7 +37,12 @@ class GroundControl
|
|
29
37
|
return nil if response.code != '200'
|
30
38
|
|
31
39
|
body = JSON.parse(response.body)
|
40
|
+
enabled = body["enabled"]
|
41
|
+
|
42
|
+
if @ttl
|
43
|
+
@cache[url] = { expires: Time.now.to_i + @ttl, enabled: enabled }
|
44
|
+
end
|
32
45
|
|
33
|
-
return
|
46
|
+
return enabled
|
34
47
|
end
|
35
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groundcontrolsh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alberto Gimeno
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Verify the rollout status of feature flags created in your groundcontrol.sh
|
14
14
|
project
|