flipt_client 0.10.0 → 0.12.0

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: 86617c811bf4e751f1adf5c35fd0d31dce7972008f750298ce3b68139cec9b76
4
- data.tar.gz: 265a161fa3d212be996c5c95243573bc77981fef9c52acde70e85b1fec449311
3
+ metadata.gz: 20580ac221c34294feeb51f8a9198980d476fce87e8aafd50c9ac077df3ad498
4
+ data.tar.gz: f8342ae2127c00ca52b3f593bc094987050df738edf14567d4f5b988e22d4f47
5
5
  SHA512:
6
- metadata.gz: 3efeca0a33a34e86e9adf3df75bae40045b46ba505a8578cafc26ad3552e6b111ad5d08fb055b8041c2de57c9c4ee4b82758bf673ca0bcd00c220a2de8511aba
7
- data.tar.gz: 446c3d3dfca9e3fa6c1a10eff567da90ab5390b0b0d0cf1a90c1a6331d34ed8d156c15119d8678df2270fb7d875b8c653c1b124be871057f6a861edb889105de
6
+ metadata.gz: ab287927c314e8c00a930ca7bfb92eed25788ee82d9d600e2eabb564abba98e33e4af3bc0fa5706ff4a12c8e398c732db1b50697799bccd28d14cbaf59e0fafb
7
+ data.tar.gz: cfd783d6e15b9fb5613f1c793d06d965330f574491fd2046a284fc579542cef57ffb49b157e6db7deaaf032eedaa1ae694d68682dba17752bd10834530aab1b6
data/README.md CHANGED
@@ -10,6 +10,28 @@ The `flipt-client-ruby` library contains the Ruby source code for the Flipt [cli
10
10
  gem install flipt_client
11
11
  ```
12
12
 
13
+ ## How Does It Work?
14
+
15
+ The `flipt-client-ruby` library is a wrapper around the [flipt-engine-ffi](https://github.com/flipt-io/flipt-client-sdks/tree/main/flipt-engine-ffi) library.
16
+
17
+ All evaluation happens within the SDK, using the shared library built from the [flipt-engine-ffi](https://github.com/flipt-io/flipt-client-sdks/tree/main/flipt-engine-ffi) library.
18
+
19
+ Because the evaluation happens within the SDK, the SDKs can be used in environments where the Flipt server is not available or reachable after the initial data is fetched.
20
+
21
+ ## Data Fetching
22
+
23
+ Upon instantiation, the `flipt-client-ruby` library will fetch the flag state from the Flipt server and store it in memory. This means that the first time you use the SDK, it will make a request to the Flipt server.
24
+
25
+ ### Polling (Default)
26
+
27
+ By default, the SDK will poll the Flipt server for new flag state at a regular interval. This interval can be configured using the `update_interval` option when constructing a client. The default interval is 120 seconds.
28
+
29
+ ### Streaming (Flipt Cloud Only)
30
+
31
+ [Flipt Cloud](https://flipt.io/cloud) users can use the `streaming` fetch method to stream flag state changes from the Flipt server to the SDK.
32
+
33
+ When in streaming mode, the SDK will connect to the Flipt server and open a persistent connection that will remain open until the client is closed. The SDK will then receive flag state changes in real-time.
34
+
13
35
  ## Supported Architectures
14
36
 
15
37
  This SDK currently supports the following OSes/architectures:
@@ -18,6 +40,7 @@ This SDK currently supports the following OSes/architectures:
18
40
  - Linux arm64
19
41
  - MacOS x86_64
20
42
  - MacOS arm64
43
+ - Windows x86_64
21
44
 
22
45
  ### Using System Libffi
23
46
 
@@ -60,11 +83,12 @@ puts resp
60
83
  The `Flipt::EvaluationClient` constructor accepts two optional arguments:
61
84
 
62
85
  - `namespace`: The namespace to fetch flag state from. If not provided, the client will default to the `default` namespace.
63
- - `engine_opts`: A hash that supports several options for the client. The structure is:
86
+ - `opts`: A hash that supports several options for the client. The structure is:
64
87
  - `url`: The URL of the upstream Flipt instance. If not provided, the client will default to `http://localhost:8080`.
65
88
  - `update_interval`: The interval (in seconds) in which to fetch new flag state. If not provided, the client will default to 120 seconds.
66
89
  - `authentication`: The authentication strategy to use when communicating with the upstream Flipt instance. If not provided, the client will default to no authentication. See the [Authentication](#authentication) section for more information.
67
90
  - `reference`: The [reference](https://docs.flipt.io/guides/user/using-references) to use when fetching flag state. If not provided, reference will not be used.
91
+ - `fetch_mode`: The fetch mode to use when fetching flag state. If not provided, the client will default to polling.
68
92
 
69
93
  ### Authentication
70
94
 
@@ -92,3 +116,11 @@ The `FliptEvaluationClient` supports the following authentication strategies:
92
116
  ```bash
93
117
  bundle exec ruby load_test.rb
94
118
  ```
119
+
120
+ ## Contributing
121
+
122
+ Contributions are welcome! Please feel free to open an issue or submit a Pull Request.
123
+
124
+ ## License
125
+
126
+ This project is licensed under the [MIT License](LICENSE).
Binary file
Binary file
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flipt
4
- VERSION = '0.10.0'
4
+ VERSION = '0.12.0'
5
5
  end
data/lib/flipt_client.rb CHANGED
@@ -12,13 +12,14 @@ module Flipt
12
12
  class EvaluationClient
13
13
  extend FFI::Library
14
14
 
15
- FLIPTENGINE = 'libfliptengine'
15
+ FLIPTENGINE = 'fliptengine'
16
16
 
17
17
  LIB_FILES = {
18
- /arm64-darwin/ => "ext/darwin_arm64/#{FLIPTENGINE}.dylib",
19
- /x86_64-darwin/ => "ext/darwin_x86_64/#{FLIPTENGINE}.dylib",
20
- /arm64-linux|aarch64-linux/ => "ext/linux_arm64/#{FLIPTENGINE}.so",
21
- /x86_64-linux/ => "ext/linux_x86_64/#{FLIPTENGINE}.so"
18
+ /arm64-darwin/ => "ext/darwin_arm64/lib#{FLIPTENGINE}.dylib",
19
+ /x86_64-darwin/ => "ext/darwin_x86_64/lib#{FLIPTENGINE}.dylib",
20
+ /arm64-linux|aarch64-linux/ => "ext/linux_arm64/lib#{FLIPTENGINE}.so",
21
+ /x86_64-linux/ => "ext/linux_x86_64/lib#{FLIPTENGINE}.so",
22
+ /x86_64-mingw32/ => "ext/windows_x86_64/#{FLIPTENGINE}.dll"
22
23
  }.freeze
23
24
 
24
25
  def self.libfile
@@ -54,6 +55,8 @@ module Flipt
54
55
  # @option opts [AuthenticationStrategy] :authentication strategy to authenticate with Flipt
55
56
  # @option opts [Integer] :update_interval interval in seconds to update the cache
56
57
  # @option opts [String] :reference reference to use for namespace data
58
+ # @option opts [Symbol] :fetch_mode fetch mode to use for the client (:polling or :streaming).
59
+ # Note: Streaming is currently only supported when using the SDK with Flipt Cloud (https://flipt.io/cloud).
57
60
  def initialize(namespace = 'default', opts = {})
58
61
  @namespace = namespace
59
62
 
@@ -64,6 +67,11 @@ module Flipt
64
67
  'invalid authentication strategy'
65
68
  end
66
69
 
70
+ fetch_mode = opts.fetch(:fetch_mode, :polling)
71
+ unless %i[polling streaming].include?(fetch_mode)
72
+ raise ArgumentError, 'invalid fetch mode'
73
+ end
74
+
67
75
  opts[:authentication] = authentication.strategy
68
76
 
69
77
  @engine = self.class.initialize_engine(namespace, opts.to_json)
@@ -83,7 +91,10 @@ module Flipt
83
91
  validate_evaluation_request(evaluation_request)
84
92
  resp, ptr = self.class.evaluate_variant(@engine, evaluation_request.to_json)
85
93
  ptr = FFI::AutoPointer.new(ptr, EvaluationClient.method(:destroy_string))
86
- JSON.parse(resp)
94
+ data = JSON.parse(resp)
95
+ raise StandardError, data['error_message'] if data['status'] != 'success'
96
+
97
+ data['result']
87
98
  end
88
99
 
89
100
  # Evaluate a boolean flag for a given request
@@ -95,7 +106,10 @@ module Flipt
95
106
  validate_evaluation_request(evaluation_request)
96
107
  resp, ptr = self.class.evaluate_boolean(@engine, evaluation_request.to_json)
97
108
  ptr = FFI::AutoPointer.new(ptr, EvaluationClient.method(:destroy_string))
98
- JSON.parse(resp)
109
+ data = JSON.parse(resp)
110
+ raise StandardError, data['error_message'] if data['status'] != 'success'
111
+
112
+ data['result']
99
113
  end
100
114
 
101
115
  # Evaluate a batch of flags for a given request
@@ -110,14 +124,20 @@ module Flipt
110
124
 
111
125
  resp, ptr = self.class.evaluate_batch(@engine, batch_evaluation_request.to_json)
112
126
  ptr = FFI::AutoPointer.new(ptr, EvaluationClient.method(:destroy_string))
113
- JSON.parse(resp)
127
+ data = JSON.parse(resp)
128
+ raise StandardError, data['error_message'] if data['status'] != 'success'
129
+
130
+ data['result']
114
131
  end
115
132
 
116
133
  # List all flags in the namespace
117
134
  def list_flags
118
135
  resp, ptr = self.class.list_flags(@engine)
119
136
  ptr = FFI::AutoPointer.new(ptr, EvaluationClient.method(:destroy_string))
120
- JSON.parse(resp)
137
+ data = JSON.parse(resp)
138
+ raise StandardError, data['error_message'] if data['status'] != 'success'
139
+
140
+ data['result']
121
141
  end
122
142
 
123
143
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flipt_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flipt Devs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-31 00:00:00.000000000 Z
11
+ date: 2024-10-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Flipt Client Evaluation SDK
14
14
  email:
@@ -19,19 +19,12 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - README.md
21
21
  - flipt-client-ruby.gemspec
22
- - lib/ext/darwin_arm64/libfliptengine.d
23
22
  - lib/ext/darwin_arm64/libfliptengine.dylib
24
- - lib/ext/darwin_arm64/libfliptengine.rlib
25
- - lib/ext/darwin_x86_64/libfliptengine.d
26
23
  - lib/ext/darwin_x86_64/libfliptengine.dylib
27
- - lib/ext/darwin_x86_64/libfliptengine.rlib
28
24
  - lib/ext/flipt_engine.h
29
- - lib/ext/linux_arm64/libfliptengine.d
30
- - lib/ext/linux_arm64/libfliptengine.rlib
31
25
  - lib/ext/linux_arm64/libfliptengine.so
32
- - lib/ext/linux_x86_64/libfliptengine.d
33
- - lib/ext/linux_x86_64/libfliptengine.rlib
34
26
  - lib/ext/linux_x86_64/libfliptengine.so
27
+ - lib/ext/windows_x86_64/fliptengine.dll
35
28
  - lib/flipt_client.rb
36
29
  - lib/flipt_client/models.rb
37
30
  - lib/flipt_client/version.rb
@@ -1 +0,0 @@
1
- /Users/runner/work/flipt-client-sdks/flipt-client-sdks/target/aarch64-apple-darwin/release/libfliptengine.rlib: /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine-ffi/src/evaluator/mod.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine-ffi/src/lib.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine-ffi/src/parser/http.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine-ffi/src/parser/mod.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/error/mod.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/lib.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/models/common.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/models/flipt.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/models/mod.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/models/source.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/parser/mod.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/store/mod.rs
@@ -1 +0,0 @@
1
- /Users/runner/work/flipt-client-sdks/flipt-client-sdks/target/x86_64-apple-darwin/release/libfliptengine.rlib: /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine-ffi/src/evaluator/mod.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine-ffi/src/lib.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine-ffi/src/parser/http.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine-ffi/src/parser/mod.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/error/mod.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/lib.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/models/common.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/models/flipt.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/models/mod.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/models/source.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/parser/mod.rs /Users/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/store/mod.rs
@@ -1 +0,0 @@
1
- /target/aarch64-unknown-linux-gnu/release/libfliptengine.rlib: /project/flipt-engine-ffi/src/evaluator/mod.rs /project/flipt-engine-ffi/src/lib.rs /project/flipt-engine-ffi/src/parser/http.rs /project/flipt-engine-ffi/src/parser/mod.rs /project/flipt-evaluation/src/error/mod.rs /project/flipt-evaluation/src/lib.rs /project/flipt-evaluation/src/models/common.rs /project/flipt-evaluation/src/models/flipt.rs /project/flipt-evaluation/src/models/mod.rs /project/flipt-evaluation/src/models/source.rs /project/flipt-evaluation/src/parser/mod.rs /project/flipt-evaluation/src/store/mod.rs
@@ -1 +0,0 @@
1
- /home/runner/work/flipt-client-sdks/flipt-client-sdks/target/x86_64-unknown-linux-gnu/release/libfliptengine.rlib: /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine-ffi/src/evaluator/mod.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine-ffi/src/lib.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine-ffi/src/parser/http.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-engine-ffi/src/parser/mod.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/error/mod.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/lib.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/models/common.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/models/flipt.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/models/mod.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/models/source.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/parser/mod.rs /home/runner/work/flipt-client-sdks/flipt-client-sdks/flipt-evaluation/src/store/mod.rs