ff-ruby-server-sdk 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1338c83b2248c11382717371743495cb32eefda503c06f107465bee5feeb783
4
- data.tar.gz: f2b12848cfbd2366db0937ffae69abd2337e74fe6498fda2abf3b202440ed166
3
+ metadata.gz: b96f2c46067899e6d26411471722640dab5b9fc27d3325c938bd06ae81e12972
4
+ data.tar.gz: 8323abe069396213c89144542e301c7865422dec5298be018e80e39a02d0a907
5
5
  SHA512:
6
- metadata.gz: 39fb700e43c01f53804f542916f6db018747f68097731a10a85593068b667c5fe4c0749f84d84adc9136c8490d84a0b0d2b77c73b39107cfdd2fa7a84ec9523f
7
- data.tar.gz: 34ef0734b8db6ca79bb81abc1af862165a185e665d3d57e63ec62dc952bd7eedb659f2dff8fdfb5d0fee32bd724c81e7ac2c290a533bb7145e4c53a486bd3eb4
6
+ metadata.gz: d3395923af630e74a29f094e5d61275dd43bf7885a76f1c952d15b9671c2e279609a982969b443b921c0dd2e8bb5eaaae428277f96713e1e7a4dd20cdf1d6fc2
7
+ data.tar.gz: 2c6ce8e325afe95845a8f978b3c39f6c8dc82c49f23d0c1941fbac0653620e20e6e5001db280b36eb2ad0ca94fadd477573b004a554bd22795a07bdf11cf000f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ # [1.0.4]
2
+
3
+ - [FFM-5478] Fixes bug caching some flags due to encoding
4
+
5
+ # [1.0.3]
6
+
7
+ - [FFM-4058] Fixes bug in storing target segments
8
+ - [FFM-4755] Fixes multi-variate number variation to return floats instead of int
9
+ - [FFM-5355] Fixes bug in pre-requisite evaluation
10
+ - [FFM-5354] Fixes compatibility with Ruby-2.6
11
+
1
12
  # [1.0.2]
2
13
 
3
14
  - Runtime and development dependencies specified.
data/Gemfile CHANGED
@@ -9,7 +9,6 @@ gem "minitest", "~> 5.0"
9
9
  gem "standard", "~> 1.3"
10
10
 
11
11
  # Caching support:
12
- gem "pp"
13
12
  gem "rufus-scheduler"
14
13
  gem "libcache"
15
14
  gem "jwt"
data/README.md CHANGED
@@ -1,38 +1,45 @@
1
1
  Harness CF Ruby Server SDK
2
2
  ========================
3
3
 
4
- ## Overview
4
+ ## Table of Contents
5
+ **[Intro](#Intro)**<br>
6
+ **[Requirements](#Requirements)**<br>
7
+ **[Quickstart](#Quickstart)**<br>
8
+ **[Further Reading](docs/further_reading.md)**<br>
9
+ **[Build Instructions](docs/build.md)**<br>
5
10
 
6
- -------------------------
7
- [Harness](https://www.harness.io/) is a feature management platform that helps teams to build better software and to
8
- test features quicker.
9
-
10
- -------------------------
11
+ ## Intro
11
12
 
12
- ## Setup
13
+ Harness Feature Flags (FF) is a feature management solution that enables users to change the software’s functionality, without deploying new code. FF uses feature flags to hide code or behaviours without having to ship new versions of the software. A feature flag is like a powerful if statement.
14
+ * For more information, see https://harness.io/products/feature-flags/
15
+ * To read more, see https://ngdocs.harness.io/category/vjolt35atg-feature-flags
16
+ * To sign up, https://app.harness.io/auth/#/signup/
13
17
 
14
- Add the following snippet to your project's `Gemfile` file:
18
+ ![FeatureFlags](./docs/images/ff-gui.png)
15
19
 
16
- ```
17
- gem "ff-ruby-server-sdk"
18
- ```
20
+ ## Requirements
21
+ [Ruby 2.7](https://www.ruby-lang.org/en/documentation/installation/) or newer (ruby --version)<br>
19
22
 
20
- ## Cloning the SDK repository
23
+ ## Quickstart
24
+ The Feature Flag SDK provides a client that connects to the feature flag service, and fetches the value
25
+ of feature flags. The following section provides an example of how to install the SDK and initialize it from
26
+ an application.
27
+ This quickstart assumes you have followed the instructions to [setup a Feature Flag project and have created a flag called `harnessappdemodarkmode` and created a server API Key](https://ngdocs.harness.io/article/1j7pdkqh7j-create-a-feature-flag#step_1_create_a_project).
21
28
 
22
- In order to clone SDK repository properly perform cloning like in the following example:
29
+ ### Install the SDK
30
+ Install the ruby SDK using gem
31
+ ```bash
32
+ gem install ff-ruby-server-sdk
33
+ ```
34
+ or by adding the following snippet to your project's `Gemfile` file:
23
35
 
24
36
  ```
25
- git clone --recurse-submodules git@github.com:harness/ff-ruby-server-sdk.git
37
+ gem "ff-ruby-server-sdk"
26
38
  ```
27
39
 
28
- After dependency has been added, the SDK elements, primarily `CfClient` should be accessible in the main application.
29
-
30
- ## Initialization
31
-
32
- `CfClient` is a base class that provides all features of the SDK.
33
-
34
- We can instantiate by calling the `instance` method or by using public
35
- constructor (making multiple instances).
40
+ ### A Simple Example
41
+ Here is a complete example that will connect to the feature flag service and report the flag value every 10 seconds until the connection is closed.
42
+ Any time a flag is toggled from the feature flag service you will receive the updated value.
36
43
 
37
44
  ```ruby
38
45
  require 'ff/ruby/server/sdk/api/config'
@@ -40,123 +47,70 @@ require 'ff/ruby/server/sdk/dto/target'
40
47
  require 'ff/ruby/server/sdk/api/cf_client'
41
48
  require 'ff/ruby/server/sdk/api/config_builder'
42
49
 
43
- client = CfClient.instance
44
-
45
- key = "YOUR_API_KEY_GOES_HERE"
50
+ require "logger"
51
+ require "securerandom"
46
52
 
47
- logger = Logger.new(STDOUT)
53
+ $stdout.sync = true
54
+ logger = Logger.new $stdout
48
55
 
49
- # Or saving logs into the filesystem with daily rotation:
50
- # logger = Logger.new("example.log", "daily")
56
+ # API Key
57
+ apiKey = ENV['FF_API_KEY'] || 'changeme'
51
58
 
52
- config = ConfigBuilder.new
53
- .logger(logger)
54
- .build
55
-
56
- client.init(key, config)
57
-
58
- config.logger.debug 'We will wait for the initialization'
59
+ # Flag Name
60
+ flagName = ENV['FF_FLAG_NAME'] || 'harnessappdemodarkmode'
59
61
 
62
+ # Create a Feature Flag Client and wait for it to initialize
63
+ client = CfClient.instance
64
+ client.init(apiKey, ConfigBuilder.new.logger(logger).build)
60
65
  client.wait_for_initialization
61
66
 
62
- config.logger.debug 'Initialization is complete'
63
-
64
- target = Target.new("YOUR_TARGET_NAME")
65
- ```
66
-
67
- `target` represents the desired target for which we want features to be evaluated.
68
-
69
- `"YOUR_API_KEY"` is an authentication key, needed for access to Harness services.
70
-
71
- **Your Harness SDK is now initialized. Congratulations!**
72
-
73
- ### Public API Methods ###
74
-
75
- The Public API exposes a few methods that you can utilize:
76
-
77
- Instantiate, initialize and close when done:
78
-
79
- * `def initialize(api_key = nil, config = nil, connector = nil)`
80
- * `def init(api_key = nil, config = nil, connector = nil)`
81
- * `def wait_for_initialization`
82
- * `def close`
83
-
84
- Evaluations:
85
-
86
- * `def bool_variation(identifier, target, default_value)`
87
- * `def string_variation(identifier, target, default_value)`
88
- * `def number_variation(identifier, target, default_value)`
89
- * `def json_variation(identifier, target, default_value)`
67
+ # Create a target (different targets can get different results based on rules. This include a custom attribute 'location')
68
+ target = Target.new("RubySDK", identifier="rubysdk", attributes={"location": "emea"})
90
69
 
91
- ## Fetch evaluation's value
70
+ # Loop forever reporting the state of the flag
71
+ loop do
72
+ result = client.bool_variation(flagName, target, false)
73
+ logger.info "Flag variation: #{result}"
74
+ sleep 10
75
+ end
92
76
 
93
- It is possible to fetch a value for a given evaluation. Evaluation is performed based on a different type. In case there
94
- is no evaluation with provided id, the default value is returned.
95
-
96
- Use the appropriate method to fetch the desired Evaluation of a certain type.
97
-
98
- ### Bool variation
99
-
100
- ```
101
- bool_result = client.bool_variation(bool_flag, target, false)
102
- ```
103
-
104
- ### Number variation
105
-
106
- ```
107
- number_result = client.number_variation(number_flag, target, -1)
77
+ client.close
108
78
  ```
109
79
 
110
- ### String variation
80
+ ### Running the example
111
81
 
112
- ```
113
- string_result = client.string_variation(string_flag, target, "unavailable !!!")
114
- ```
82
+ ```bash
83
+ # Install the deps
84
+ gem install ff-ruby-server-sdk typhoeus
115
85
 
116
- ### JSON variation
86
+ # Set your API Key
87
+ export FF_API_KEY=<your key here>
117
88
 
118
- ```
119
- json_result = client.json_variation(json_flag, target, JSON.parse("{}"))
89
+ # Run the example
90
+ ruby ./example/gettting_started.rb
120
91
  ```
121
92
 
122
- ## Using feature flags metrics
93
+ ### Running with docker
94
+ If you don't have the right version of ruby installed locally, or don't want to install the dependencies you can
95
+ use docker to quickly get started
123
96
 
124
- Metrics API endpoint can be changed like this (if ever needed):
97
+ ```bash
98
+ # Install the package
99
+ docker run -v $(pwd):/app -w /app -e FF_API_KEY=$FF_API_KEY ruby:2.7-buster gem install --install-dir ./gems ff-ruby-server-sdk typhoeus
125
100
 
101
+ # Run the script
102
+ docker run -v $(pwd):/app -w /app -e FF_API_KEY=$FF_API_KEY -e GEM_HOME=/app/gems ruby:2.7-buster ruby ./example/getting_started.rb
126
103
  ```
127
- config = ConfigBuilder.new
128
- .event_url("SOME_ENDPOINT_URL")
129
- .build
130
- ```
131
-
132
- Otherwise, the default metrics endpoint URL will be used.
133
104
 
134
- ## Connector
105
+ ### Additional Reading
135
106
 
136
- This is a new feature that allows you to create or use other connectors.
137
- Connector is just a proxy to your data. Currently supported connectors:
107
+ Further examples and config options are in the further reading section:
138
108
 
139
- * Harness (the default implementation)
140
-
141
- ```
142
- connector = YourConnectorImplementation.new
143
-
144
- client.init(
145
-
146
- key,
147
- config,
148
- connector
149
- )
150
- ```
151
-
152
- ## Shutting down the SDK
153
-
154
- To avoid potential memory leak, when SDK is no longer needed
155
- (when the app is closed, for example), a caller should call the `close` method:
156
-
157
- ```
158
- client.close
159
- ```
109
+ [Further Reading](docs/further_reading.md)
160
110
 
161
111
 
112
+ -------------------------
113
+ [Harness](https://www.harness.io/) is a feature management platform that helps teams to build better software and to
114
+ test features quicker.
162
115
 
116
+ -------------------------
data/docs/build.md ADDED
@@ -0,0 +1,24 @@
1
+ # Building ff-ruby-server-sdk
2
+
3
+ This document shows the instructions on how to build and contribute to the SDK.
4
+
5
+ ## Requirements
6
+ [Ruby 2.7](https://www.ruby-lang.org/en/documentation/installation/) or newer (ruby --version)<br>
7
+ [openapi-generator-cli](https://openapi-generator.tech/docs/installation/)
8
+ ## Cloning the SDK repository
9
+ In order to clone SDK repository properly perform cloning like in the following example:
10
+ ```
11
+ git clone --recurse-submodules git@github.com:harness/ff-ruby-server-sdk.git
12
+ ```
13
+
14
+ ## Install Dependencies
15
+ ```bash
16
+ npm install @openapitools/openapi-generator-cli -g
17
+ npm install @openapitools/openapi-generator-cli -D
18
+ bundle install
19
+ ```
20
+
21
+ ## Build the SDK
22
+ ```bash
23
+ gem build ff-ruby-server-sdk.gemspec
24
+ ```
@@ -0,0 +1,119 @@
1
+ # Further Reading
2
+
3
+ Covers advanced topics (different config options and scenarios)
4
+
5
+ ## Configuration Options
6
+ The following configuration options are available to control the behaviour of the SDK.
7
+ You can provide options by passing them in when the client is created e.g.
8
+
9
+ ```ruby
10
+ client.init(apiKey, ConfigBuilder
11
+ .config_url("https://config.ff.harness.io/api/1.0")
12
+ .event_url("https://events.ff.harness.io/api/1.0")
13
+ .poll_interval_in_seconds(60)
14
+ .analytics_enabled(true)
15
+ .stream_enabled(true)
16
+ .build)
17
+ ```
18
+
19
+ | Name | Config Option | Description | default |
20
+ |-----------------|----------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------|
21
+ | baseUrl | config_url("https://config.ff.harness.io/api/1.0") | the URL used to fetch feature flag evaluations. You should change this when using the Feature Flag proxy to http://localhost:7000 | https://config.ff.harness.io/api/1.0 |
22
+ | eventsUrl | event_url("https://events.ff.harness.io/api/1.0"), | the URL used to post metrics data to the feature flag service. You should change this when using the Feature Flag proxy to http://localhost:7000 | https://events.ff.harness.io/api/1.0 |
23
+ | pollInterval | poll_interval_in_seconds(60) | when running in stream mode, the interval in seconds that we poll for changes. | 60 |
24
+ | enableStream | analytics_enabled(false) | Enable streaming mode. | true |
25
+ | enableAnalytics | stream_enabled(true) | Enable analytics. Metrics data is posted every 60s | true |
26
+
27
+ ## Logging Configuration
28
+ You can provide your own logger to the SDK i.e. using the moneta logger we can do this
29
+
30
+ ```ruby
31
+ require "logger"
32
+
33
+ logger = Logger.new(STDOUT)
34
+ logger.level = Logger::DEBUG
35
+ client.init(apiKey, ConfigBuilder.new.logger(logger).build)
36
+ ```
37
+
38
+
39
+ ## Recommended reading
40
+
41
+ [Feature Flag Concepts](https://ngdocs.harness.io/article/7n9433hkc0-cf-feature-flag-overview)
42
+
43
+ [Feature Flag SDK Concepts](https://ngdocs.harness.io/article/rvqprvbq8f-client-side-and-server-side-sdks)
44
+
45
+ ## Setting up your Feature Flags
46
+
47
+ [Feature Flags Getting Started](https://ngdocs.harness.io/article/0a2u2ppp8s-getting-started-with-feature-flags)
48
+
49
+ ### Public API Methods ###
50
+
51
+ The Public API exposes a few methods that you can utilize:
52
+
53
+ Instantiate, initialize and close when done:
54
+
55
+ * `def initialize(api_key = nil, config = nil, connector = nil)`
56
+ * `def init(api_key = nil, config = nil, connector = nil)`
57
+ * `def wait_for_initialization`
58
+ * `def close`
59
+
60
+ Evaluations:
61
+
62
+ * `def bool_variation(identifier, target, default_value)`
63
+ * `def string_variation(identifier, target, default_value)`
64
+ * `def number_variation(identifier, target, default_value)`
65
+ * `def json_variation(identifier, target, default_value)`
66
+
67
+ ## Fetch evaluation's value
68
+
69
+ It is possible to fetch a value for a given evaluation. Evaluation is performed based on a different type. In case there
70
+ is no evaluation with provided id, the default value is returned.
71
+
72
+ Use the appropriate method to fetch the desired Evaluation of a certain type.
73
+
74
+ ### Bool variation
75
+
76
+ ```
77
+ bool_result = client.bool_variation(bool_flag, target, false)
78
+ ```
79
+
80
+ ### Number variation
81
+
82
+ ```
83
+ number_result = client.number_variation(number_flag, target, -1)
84
+ ```
85
+
86
+ ### String variation
87
+
88
+ ```
89
+ string_result = client.string_variation(string_flag, target, "unavailable !!!")
90
+ ```
91
+
92
+ ### JSON variation
93
+
94
+ ```
95
+ json_result = client.json_variation(json_flag, target, JSON.parse("{}"))
96
+ ```
97
+
98
+ ## Shutting down the SDK
99
+
100
+ To avoid potential memory leak, when SDK is no longer needed
101
+ (when the app is closed, for example), a caller should call the `close` method:
102
+
103
+ ```
104
+ client.close
105
+ ```
106
+
107
+ ## Change default URL
108
+
109
+ When using your Feature Flag SDKs with a [Harness Relay Proxy](https://ngdocs.harness.io/article/q0kvq8nd2o-relay-proxy) you need to change the default URL.
110
+
111
+
112
+ ```
113
+ config = ConfigBuilder.new
114
+ .config_url("https://config.feature-flags.uat.harness.io/api/1.0")
115
+ .event_url("https://event.feature-flags.uat.harness.io/api/1.0")
116
+ .build
117
+ ```
118
+
119
+
Binary file
@@ -0,0 +1,36 @@
1
+ require 'ff/ruby/server/sdk/api/config'
2
+ require 'ff/ruby/server/sdk/dto/target'
3
+ require 'ff/ruby/server/sdk/api/cf_client'
4
+ require 'ff/ruby/server/sdk/api/config_builder'
5
+
6
+ require "logger"
7
+ require "securerandom"
8
+
9
+ $stdout.sync = true
10
+ logger = Logger.new $stdout
11
+
12
+ # API Key
13
+ apiKey = ENV['FF_API_KEY'] || 'changeme'
14
+
15
+ # Flag Name
16
+ flagName = ENV['FF_FLAG_NAME'] || 'identifier_of_your_bool_flag'
17
+
18
+ # Create a Feature Flag Client and wait for it to initialize
19
+ client = CfClient.instance
20
+
21
+ client.init(apiKey, ConfigBuilder.new.logger(logger).build)
22
+ client.wait_for_initialization
23
+
24
+ # Create a target (different targets can get different results based on rules. This include a custom attribute 'location')
25
+ target = Target.new("RubySDK", identifier="rubysdk", attributes={"location": "emea"})
26
+
27
+ # Loop forever reporting the state of the flag
28
+ loop do
29
+ result = client.bool_variation(flagName, target, false)
30
+ logger.info "Flag variation: #{result}"
31
+ sleep 10
32
+ end
33
+
34
+ client.close
35
+
36
+
@@ -0,0 +1,38 @@
1
+ require 'ff/ruby/server/sdk/api/config'
2
+ require 'ff/ruby/server/sdk/dto/target'
3
+ require 'ff/ruby/server/sdk/api/cf_client'
4
+ require 'ff/ruby/server/sdk/api/config_builder'
5
+
6
+ require "logger"
7
+ require "securerandom"
8
+
9
+ $stdout.sync = true
10
+ logger = Logger.new $stdout
11
+
12
+ # API Key
13
+ apiKey = ENV['FF_API_KEY'] || 'changeme'
14
+
15
+ # Flag Name
16
+ flagName = ENV['FF_FLAG_NAME'] || 'harnessappdemodarkmode'
17
+
18
+ logger.info "Harness Ruby SDK Getting Started"
19
+
20
+ # Create a Feature Flag Client and wait for it to initialize
21
+ client = CfClient.instance
22
+
23
+ client.init(apiKey, ConfigBuilder.new.logger(logger).build)
24
+ client.wait_for_initialization
25
+
26
+ # Create a target (different targets can get different results based on rules. This include a custom attribute 'location')
27
+ target = Target.new("RubySDK", identifier="rubysdk", attributes={"location": "emea"})
28
+
29
+ # Loop forever reporting the state of the flag
30
+ loop do
31
+ result = client.bool_variation(flagName, target, false)
32
+ logger.info "Flag variation: #{result}"
33
+ sleep 10
34
+ end
35
+
36
+ client.close
37
+
38
+
@@ -0,0 +1,38 @@
1
+ require 'ff/ruby/server/sdk/api/config'
2
+ require 'ff/ruby/server/sdk/dto/target'
3
+ require 'ff/ruby/server/sdk/api/cf_client'
4
+ require 'ff/ruby/server/sdk/api/config_builder'
5
+
6
+ require "logger"
7
+ require "securerandom"
8
+
9
+ $stdout.sync = true
10
+ logger = Logger.new $stdout
11
+
12
+ # API Key
13
+ apiKey = ENV['FF_API_KEY'] || 'changeme'
14
+
15
+ # Flag Name
16
+ flagName = ENV['FF_FLAG_NAME'] || 'identifier_of_your_json_flag'
17
+
18
+ logger.info "Harness Ruby SDK Getting Started"
19
+
20
+ # Create a Feature Flag Client and wait for it to initialize
21
+ client = CfClient.instance
22
+
23
+ client.init(apiKey, ConfigBuilder.new.logger(logger).build)
24
+ client.wait_for_initialization
25
+
26
+ # Create a target (different targets can get different results based on rules. This include a custom attribute 'location')
27
+ target = Target.new("RubySDK", identifier="rubysdk", attributes={"location": "emea"})
28
+
29
+ # Loop forever reporting the state of the flag
30
+ loop do
31
+ result = client.json_variation(flagName, target, JSON.parse("{}"))
32
+ logger.info "Flag variation: #{result.to_json}"
33
+ sleep 10
34
+ end
35
+
36
+ client.close
37
+
38
+
@@ -0,0 +1,38 @@
1
+ require 'ff/ruby/server/sdk/api/config'
2
+ require 'ff/ruby/server/sdk/dto/target'
3
+ require 'ff/ruby/server/sdk/api/cf_client'
4
+ require 'ff/ruby/server/sdk/api/config_builder'
5
+
6
+ require "logger"
7
+ require "securerandom"
8
+
9
+ $stdout.sync = true
10
+ logger = Logger.new $stdout
11
+
12
+ # API Key
13
+ apiKey = ENV['FF_API_KEY'] || 'changeme'
14
+
15
+ # Flag Name
16
+ flagName = ENV['FF_FLAG_NAME'] || 'identifier_of_your_number_flag'
17
+
18
+ logger.info "Harness Ruby SDK Getting Started"
19
+
20
+ # Create a Feature Flag Client and wait for it to initialize
21
+ client = CfClient.instance
22
+
23
+ client.init(apiKey, ConfigBuilder.new.logger(logger).build)
24
+ client.wait_for_initialization
25
+
26
+ # Create a target (different targets can get different results based on rules. This include a custom attribute 'location')
27
+ target = Target.new("RubySDK", identifier="rubysdk", attributes={"location": "emea"})
28
+
29
+ # Loop forever reporting the state of the flag
30
+ loop do
31
+ result = client.number_variation(flagName, target, -1)
32
+ logger.info "Flag variation: #{result}"
33
+ sleep 10
34
+ end
35
+
36
+ client.close
37
+
38
+
File without changes
@@ -0,0 +1,38 @@
1
+ require 'ff/ruby/server/sdk/api/config'
2
+ require 'ff/ruby/server/sdk/dto/target'
3
+ require 'ff/ruby/server/sdk/api/cf_client'
4
+ require 'ff/ruby/server/sdk/api/config_builder'
5
+
6
+ require "logger"
7
+ require "securerandom"
8
+
9
+ $stdout.sync = true
10
+ logger = Logger.new $stdout
11
+
12
+ # API Key
13
+ apiKey = ENV['FF_API_KEY'] || 'changeme'
14
+
15
+ # Flag Name
16
+ flagName = ENV['FF_FLAG_NAME'] || 'identifier_of_your_string_flag'
17
+
18
+ logger.info "Harness Ruby SDK Getting Started"
19
+
20
+ # Create a Feature Flag Client and wait for it to initialize
21
+ client = CfClient.instance
22
+
23
+ client.init(apiKey, ConfigBuilder.new.logger(logger).build)
24
+ client.wait_for_initialization
25
+
26
+ # Create a target (different targets can get different results based on rules. This include a custom attribute 'location')
27
+ target = Target.new("RubySDK", identifier="rubysdk", attributes={"location": "emea"})
28
+
29
+ # Loop forever reporting the state of the flag
30
+ loop do
31
+ result = client.string_variation(flagName, target, "")
32
+ logger.info "Flag variation: #{result}"
33
+ sleep 10
34
+ end
35
+
36
+ client.close
37
+
38
+
@@ -0,0 +1,40 @@
1
+ require 'ff/ruby/server/sdk/api/config'
2
+ require 'ff/ruby/server/sdk/dto/target'
3
+ require 'ff/ruby/server/sdk/api/cf_client'
4
+ require 'ff/ruby/server/sdk/api/config_builder'
5
+
6
+ require "logger"
7
+ require "securerandom"
8
+
9
+ $stdout.sync = true
10
+ logger = Logger.new $stdout
11
+
12
+ # API Key
13
+ apiKey = ENV['FF_API_KEY'] || 'changeme'
14
+
15
+ # Flag Name
16
+ flagName = ENV['FF_FLAG_NAME'] || 'harnessappdemodarkmode'
17
+
18
+ logger.info "Harness Ruby SDK Getting Started"
19
+
20
+
21
+
22
+ # Create a Feature Flag Client and wait for it to initialize
23
+ client = CfClient.instance
24
+
25
+ client.init(apiKey, ConfigBuilder.new.logger(logger).config_url("https://config.ff.harness.io/api/1.0").event_url("https://events.ff.harness.io/api/1.0").build)
26
+ client.wait_for_initialization
27
+
28
+ # Create a target (different targets can get different results based on rules. This include a custom attribute 'location')
29
+ target = Target.new("RubySDK", identifier="rubysdk", attributes={"location": "emea"})
30
+
31
+ # Loop forever reporting the state of the flag
32
+ loop do
33
+ result = client.bool_variation(flagName, target, false)
34
+ logger.info "Flag variation: #{result}"
35
+ sleep 10
36
+ end
37
+
38
+ client.close
39
+
40
+
@@ -21,22 +21,6 @@ class DefaultCache < Cache
21
21
 
22
22
  lambda = lambda { |*key| @logger.debug "Retrieved #{key}" }
23
23
 
24
- cache_dir = "./cache"
25
- unless directory_exists?(cache_dir)
26
-
27
- FileUtils.mkdir_p cache_dir
28
- unless directory_exists?(cache_dir)
29
-
30
- raise "Failed to initialize filesystem cache at: " + cache_dir
31
- end
32
- end
33
-
34
- @filesystem = CacheBuilder.with(FileCache)
35
- .set_store(cache_dir)
36
- .set_max(@capacity)
37
- .set_post_get(lambda)
38
- .build
39
-
40
24
  @in_memory = CacheBuilder.with(Cache)
41
25
  .set_max(@capacity)
42
26
  .set_post_get(lambda)
@@ -44,16 +28,13 @@ class DefaultCache < Cache
44
28
  end
45
29
 
46
30
  def verify
47
-
48
- @in_memory != nil && @filesystem != nil && @capacity > 0
31
+ @in_memory != nil && @capacity > 0
49
32
  end
50
33
 
51
34
  def set(key, value)
52
35
 
53
36
  begin
54
37
  @in_memory.put(key, value)
55
- @filesystem.put(key, value)
56
- keys.add(key)
57
38
 
58
39
  rescue ArgumentError => e
59
40
 
@@ -66,15 +47,6 @@ class DefaultCache < Cache
66
47
  def get(key)
67
48
 
68
49
  value = @in_memory.get(key)
69
-
70
- if value == nil
71
-
72
- value = @filesystem.get(key)
73
- if value != nil
74
-
75
- @in_memory.put(key, value)
76
- end
77
- end
78
50
  value
79
51
  end
80
52
 
@@ -90,11 +62,6 @@ class DefaultCache < Cache
90
62
  @in_memory.invalidate(key)
91
63
  end
92
64
 
93
- if @filesystem.exists?(key)
94
-
95
- @filesystem.invalidate(key)
96
- end
97
-
98
65
  @keys.delete(key)
99
66
  end
100
67
 
@@ -48,7 +48,7 @@ class Evaluator < Evaluation
48
48
  default_value
49
49
  end
50
50
 
51
- def number_variation(identifier, target, default_value, callback)
51
+ def integer_variation(identifier, target, default_value, callback)
52
52
 
53
53
  variation = evaluate(identifier, target, "int", callback)
54
54
 
@@ -60,6 +60,17 @@ class Evaluator < Evaluation
60
60
  default_value
61
61
  end
62
62
 
63
+ def number_variation(identifier, target, default_value, callback)
64
+ variation = evaluate(identifier, target, "int", callback)
65
+
66
+ if variation != nil
67
+
68
+ return variation.value.to_f
69
+ end
70
+
71
+ default_value
72
+ end
73
+
63
74
  def json_variation(identifier, target, default_value, callback)
64
75
 
65
76
  variation = evaluate(identifier, target, "json", callback)
@@ -486,7 +497,7 @@ class Evaluator < Evaluation
486
497
 
487
498
  valid_pre_req_variations.each do |element|
488
499
 
489
- if element.include?(pre_req_evaluated_variation.value)
500
+ if element.include?(pre_req_evaluated_variation.identifier)
490
501
 
491
502
  none_match = false
492
503
  break
@@ -523,4 +534,4 @@ class Evaluator < Evaluation
523
534
 
524
535
  false
525
536
  end
526
- end
537
+ end
@@ -68,8 +68,8 @@ class PollingProcessor < Closeable
68
68
 
69
69
  if s != nil
70
70
 
71
- @repository.set_flag(s.identifier, s)
72
- flags.push(s)
71
+ @repository.set_segment(s.identifier, s)
72
+ segments.push(s)
73
73
  end
74
74
  }
75
75
  end
@@ -5,7 +5,7 @@ module Ff
5
5
  module Server
6
6
  module Sdk
7
7
 
8
- VERSION = "1.0.2"
8
+ VERSION = "1.0.4"
9
9
  end
10
10
  end
11
11
  end
data/scripts/openapi.sh CHANGED
@@ -43,12 +43,11 @@ if which openapi-generator-cli; then
43
43
  fi
44
44
  fi
45
45
 
46
- if gem install rspec-expectations -v 3.11.0 && \
47
- gem install rspec-mocks -v 3.11.0 && \
46
+ if gem install rspec-expectations -v 3.12.0 && \
47
+ gem install rspec-mocks -v 3.12.0 && \
48
48
  gem install rake -v 13.0 && \
49
49
  gem install minitest -v 5.15.0 && \
50
50
  gem install standard -v 1.11.0 && \
51
- gem install pp -v 0.3.0 && \
52
51
  gem install libcache -v 0.4.2 && \
53
52
  gem install rufus-scheduler -v 3.8.1 && \
54
53
  gem install jwt -v 2.3.0 && \
data/scripts/sdk_specs.sh CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/bin/bash
2
2
 
3
3
  export ff_ruby_sdk="ff-ruby-server-sdk"
4
- export ff_ruby_sdk_version="1.0.2"
4
+ export ff_ruby_sdk_version="1.0.4"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ff-ruby-server-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - 'Miloš Vasić, cyr.: Милош Васић'
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-09 00:00:00.000000000 Z
11
+ date: 2022-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
- - !ruby/object:Gem::Dependency
56
- name: pp
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '='
60
- - !ruby/object:Gem::Version
61
- version: 0.3.0
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '='
67
- - !ruby/object:Gem::Version
68
- version: 0.3.0
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rufus-scheduler
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -198,7 +184,16 @@ files:
198
184
  - api.yaml
199
185
  - bin/console
200
186
  - bin/setup
201
- - example/example.rb
187
+ - docs/build.md
188
+ - docs/further_reading.md
189
+ - docs/images/ff-gui.png
190
+ - example/bool_variation_example/bool_variation_example.rb
191
+ - example/getting_started/getting_started.rb
192
+ - example/json_variation_example/json_variation_example.rb
193
+ - example/number_variation_example/number_variation_example.rb
194
+ - example/simple_example/example.rb
195
+ - example/string_variation_example/string_variation_example.rb
196
+ - example/url_change_example/url_change_example.rb
202
197
  - lib/ff/ruby/server/generated/lib/openapi_client.rb
203
198
  - lib/ff/ruby/server/generated/lib/openapi_client/api/client_api.rb
204
199
  - lib/ff/ruby/server/generated/lib/openapi_client/api/metrics_api.rb
@@ -298,7 +293,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
298
293
  - !ruby/object:Gem::Version
299
294
  version: '0'
300
295
  requirements: []
301
- rubygems_version: 3.3.11
296
+ rubygems_version: 3.1.6
302
297
  signing_key:
303
298
  specification_version: 4
304
299
  summary: Harness is a feature management platform that helps teams to build better