launchdarkly_api_helper 0.6.0 → 0.8.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 +4 -4
- data/README.md +237 -137
- data/lib/launchdarkly_api_helper/version.rb +1 -1
- data/lib/launchdarkly_api_helper.rb +12 -96
- metadata +11 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76248b30b1edaa307a8bb4e1975cccb94c7e28f00535e46de2a199884f97987c
|
4
|
+
data.tar.gz: 3ea7fbdc37be4d4f7de4de14c1e1c0101907383a52fbd64e577da8eb01c68197
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f21e3dd1dcc6acda981da928e169872964650f00f928909fbd7e25e4d44daf04c0b54307f9d87c23f2823a5b9ec8c0ce446ba3208b167ee1d5449ca974daeed
|
7
|
+
data.tar.gz: 54fb63330243f55083d1f02636a696ebf3bb717264745878184ac1e6d8af8fa2b5a65a24d798e6754fccea728dccef97a48e9a204c65cc7e0039b3cbf192375b
|
data/README.md
CHANGED
@@ -1,8 +1,18 @@
|
|
1
|
-
# LaunchdarklyApiHelper
|
1
|
+
# LaunchdarklyApiHelper
|
2
|
+
<div>
|
3
|
+
<a href="https://rubygems.org/gems/launchdarkly_api_helper">
|
4
|
+
<img alt="GEM Version" src="https://img.shields.io/gem/v/launchdarkly_api_helper?color=38C160&logo=ruby&logoColor=FE1616">
|
5
|
+
</a>
|
6
|
+
<a href="https://rubygems.org/gems/launchdarkly_api_helper">
|
7
|
+
<img alt="Gem Downloads" src="https://img.shields.io/gem/dt/launchdarkly_api_helper?color=38C160&logo=ruby&logoColor=FE1616">
|
8
|
+
</a>
|
9
|
+
</div>
|
10
|
+
|
11
|
+
<br>
|
2
12
|
|
3
13
|
[LaunchDarklyApiHelper](https://rubygems.org/gems/launchdarkly_api_helper) provides you a way to access your [Launch Darkly](https://apidocs.launchdarkly.com/) account using [API token](https://app.launchdarkly.com/settings/authorization/tokens/new) to view, edit or delete them accordingly.
|
4
14
|
|
5
|
-
|
15
|
+
<br>
|
6
16
|
|
7
17
|
[Launch Darkly API Documentation](https://apidocs.launchdarkly.com/)
|
8
18
|
|
@@ -24,79 +34,54 @@ add `include LaunchdarklyApiHelper` line to access LaunchdarklyApiHelper module
|
|
24
34
|
|
25
35
|
To perform any operations such as add, remove, replace, move, copy, test you should have a working knowledge of [JSON Patch](https://datatracker.ietf.org/doc/html/rfc6902)
|
26
36
|
|
27
|
-
|
28
|
-
parameters:
|
29
|
-
access_token (*required): this token will be used to send all requests to LaunchDarkly (string)
|
30
|
-
project_name: provide project name of your organistaion (NOTE: for most, it should be `default` unless you have made some explicit changes)
|
31
|
-
log_file: all logs will be written to file 'launchdarkly.log' by default if no file name specified (string)
|
37
|
+
<br>
|
32
38
|
|
33
|
-
|
34
|
-
def ld_access_token(access_token, project_name = 'default', log_file = 'launchdarkly.log')
|
35
|
-
# code ...
|
36
|
-
end
|
37
|
-
```
|
39
|
+
Projects allow you to manage multiple different software projects under one LaunchDarkly account. Each project has its own unique set of environments and feature flags. To learn more, read [Projects](https://docs.launchdarkly.com/home/organize/projects)
|
38
40
|
|
39
|
-
[
|
41
|
+

|
40
42
|
|
41
|
-
|
42
|
-
GET REQUEST
|
43
|
-
https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression
|
43
|
+

|
44
44
|
|
45
|
-
|
46
|
-
By default, this returns the configurations for all environments
|
47
|
-
You can filter environments with the env query parameter. For example, setting env=staging restricts the returned configurations to just the staging environment
|
48
|
-
https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression?env=staging
|
45
|
+
<br>
|
49
46
|
|
50
|
-
|
51
|
-
env (*required): name of the environment for which you want to get the details (string)
|
52
|
-
flag (*required): name of the feature flag for which you want to get the details (string)
|
47
|
+
### [Set Access Token](https://apidocs.launchdarkly.com/tag/Access-tokens)
|
53
48
|
|
54
|
-
|
55
|
-
def ld_fetch_flag_details(env, flag)
|
56
|
-
# code ...
|
57
|
-
end
|
49
|
+

|
58
50
|
|
59
|
-
|
60
|
-
|
61
|
-
|
51
|
+
**_parameters for `ld_access_token` method_**
|
52
|
+
- **access_token (*required)**: this token will be used to send all requests to LaunchDarkly (string)
|
53
|
+
- **project_name**: provide project name of your organization (NOTE: for most, it should be `default` unless you have made some explicit changes)
|
54
|
+
- **log_file**: all logs will be written to file 'launchdarkly.log' by default if no file name specified (string)
|
62
55
|
|
63
56
|
```ruby
|
64
|
-
|
65
|
-
|
66
|
-
parameters:
|
67
|
-
env (*required): name of the environment for which you want to get the details (string)
|
68
|
-
flag (*required): name of the feature flag for which you want to get the details (string)
|
69
|
-
|
70
|
-
# this method will return the status of the flag, whether it is on or off viz set to true or false
|
71
|
-
def ld_fetch_flag_toggle_status(env, flag)
|
57
|
+
# set your LD API token and log file to capture logs
|
58
|
+
def ld_access_token(access_token, project_name = 'default', log_file = 'launchdarkly.log')
|
72
59
|
# code ...
|
73
60
|
end
|
74
|
-
|
75
|
-
@return parameter: (response of feature flag toggle status)
|
76
|
-
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}"
|
77
|
-
response['environments'][env]['on'] (boolean)
|
78
61
|
```
|
79
62
|
|
80
|
-
|
81
|
-
|
82
|
-
https://apidocs.launchdarkly.com/tag/Feature-flags/#operation/postFeatureFlag
|
63
|
+
<br>
|
64
|
+
|
65
|
+
### [Create a feature flag](https://apidocs.launchdarkly.com/tag/Feature-flags/#operation/postFeatureFlag)
|
83
66
|
|
84
|
-
|
85
|
-
https://app.launchdarkly.com/api/v2/flags/default
|
67
|
+
Sample: `https://app.launchdarkly.com/api/v2/flags/<project_name>`
|
86
68
|
|
87
|
-
|
69
|
+
Example: `https://app.launchdarkly.com/api/v2/flags/default`
|
70
|
+
|
71
|
+
Here, `default` is our Project name - eg. AmitSinghBisht
|
88
72
|
|
89
73
|
parameters:
|
90
|
-
key (*required): A unique key used to reference the feature flag in your code (string)
|
91
|
-
name (*required): A human-friendly name for the feature flag (string)
|
92
|
-
description: Description of the feature flag. Defaults to an empty string (string)
|
93
|
-
tags: Tags for the feature flag. Defaults to an empty array (Array of strings)
|
94
|
-
variations: An array of possible variations for the flag. The variation values must be unique. If omitted, two boolean variations of true and false will be used (Array of objects)
|
95
74
|
|
96
|
-
|
97
|
-
|
98
|
-
|
75
|
+
- **key (*required)**: A unique key used to reference the feature flag in your code (string)
|
76
|
+
- **name (*required)**: A human-friendly name for the feature flag (string)
|
77
|
+
- **description**: Description of the feature flag. Defaults to an empty string (string)
|
78
|
+
- **tags**: Tags for the feature flag. Defaults to an empty array (Array of strings)
|
79
|
+
- **variations**: An array of possible variations for the flag. The variation values must be unique. If omitted, two boolean variations of true and false will be used (Array of objects)
|
80
|
+
- **defaults**
|
81
|
+
- **onVariation** (*required): The index, from the array of variations for this flag, of the variation to serve by default when targeting is on (integer)
|
82
|
+
- **offVariation** (*required): The index, from the array of variations for this flag, of the variation to serve by default when targeting is off (integer)
|
99
83
|
|
84
|
+
```ruby
|
100
85
|
{
|
101
86
|
"key": "developer_flag_for_regression",
|
102
87
|
"name": "developer_flag_for_regression",
|
@@ -117,70 +102,150 @@ defaults
|
|
117
102
|
"offVariation": 0
|
118
103
|
}
|
119
104
|
}
|
105
|
+
```
|
120
106
|
|
121
|
-
Above code will create a key
|
107
|
+
Above code will create a key `developer_flag_for_regression` with name as `developer_flag_for_regression` and description as `developer_flag_for_regression is created via regression api on 18_10_2022`
|
122
108
|
|
123
|
-
Variations are provided while creating key, by default variation is a boolean value (true and false). once flag with a specific variation is created, its type cannot be modified later, hence choose your variation type smartly (Boolean, String, Number, JSON) In above example we are creating a flag with JSON type and its two values are 'age': 10 and 'age': 20
|
109
|
+
Variations are provided while creating key, by default variation is a boolean value (true and false). **once flag with a specific variation is created, its type cannot be modified later, hence choose your variation type smartly (Boolean, String, Number, JSON)** In above example we are creating a flag with JSON type and its two values are 'age': 10 and 'age': 20
|
124
110
|
|
125
111
|
Also, variation has by default two values, and you must also define two variations while creating your own custom feature flag
|
126
112
|
|
127
113
|
Default will specify which variation to serve when flag is on or off. In above example when flag is turned on, '1' variation is served [Note: 0 and 1 are index position], so variations at first index ie variations[1] will be served when flag is turned on ie 'age': 20
|
128
114
|
|
115
|
+
**_parameters for `ld_create_flag` method_**
|
116
|
+
- **key (*required)**: A unique key used to reference the feature flag in your code (string)
|
117
|
+
- **name**: A human-friendly name for the feature flag (string)
|
118
|
+
- **description**: Description of the feature flag. Defaults to an empty string (string)
|
119
|
+
- **tags**: Tags for the feature flag. Defaults to an empty array (Array of strings)
|
120
|
+
|
121
|
+
```ruby
|
129
122
|
# this method will create a new feature flag, NOTE: feature falg are created at global level and environment resides inside feature flag
|
130
123
|
def ld_create_flag(key, name = key, description = key, tags = ['created_via_regression_api'])
|
131
124
|
# code ...
|
132
125
|
end
|
133
126
|
```
|
134
127
|
|
135
|
-
|
136
|
-
Update feature flag
|
137
|
-
https://apidocs.launchdarkly.com/tag/Feature-flags#operation/patchFeatureFlag
|
128
|
+
**_@return parameter_**: (response of feature flag details)
|
138
129
|
|
139
|
-
|
140
|
-
https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression
|
130
|
+
- response = `https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}` (string)
|
141
131
|
|
142
|
-
|
143
|
-
You can update any parameter of feature flag using this method
|
132
|
+
<br>
|
144
133
|
|
145
|
-
|
146
|
-
env (*required): name of the environment for which you want to get the details (string)
|
147
|
-
flag (*required): name of the feature flag for which you want to get the details (string)
|
148
|
-
flag_value: status of the feature flag that you want to set either on (true) or off (false) (boolean)
|
134
|
+
### [Get feature flag](https://apidocs.launchdarkly.com/tag/Feature-flags#operation/getFeatureFlag)
|
149
135
|
|
150
|
-
|
151
|
-
|
136
|
+
Sample: `https://app.launchdarkly.com/api/v2/flags/<project_name>/<feature_flag_name>`
|
137
|
+
|
138
|
+
Example: `https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression`
|
139
|
+
|
140
|
+
<br>
|
141
|
+
|
142
|
+
**1. GET FEATURE FLAG DETAILS**
|
143
|
+
|
144
|
+
Here, `developer_flag_for_regression` is the feature flag name and `default` is our Project name - eg. AmitSinghBisht
|
145
|
+
|
146
|
+
By default, this returns the configurations for all environments
|
147
|
+
|
148
|
+
You can filter environments with the env query parameter. For example, setting env=staging restricts the returned configurations to just the staging environment
|
149
|
+
`https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression?env=staging`
|
150
|
+
|
151
|
+
**_parameters for `ld_fetch_flag_details` method_**
|
152
|
+
- **env** (*required): name of the environment for which you want to get the details (string)
|
153
|
+
- **flag** (*required): name of the feature flag for which you want to get the details (string)
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
# this method will give you entire details about a flag for that particular environment
|
157
|
+
def ld_fetch_flag_details(env, flag)
|
152
158
|
# code ...
|
153
159
|
end
|
154
|
-
|
155
|
-
@return parameter: (response of feature flag toggle status)
|
156
|
-
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}"
|
157
|
-
response['environments'][env]['on'] (boolean)
|
158
160
|
```
|
159
161
|
|
162
|
+
**_@return parameter_**: (response of feature flag details)
|
163
|
+
|
164
|
+
- response = `https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}` (string)
|
165
|
+
|
166
|
+
<br>
|
167
|
+
|
168
|
+
**2. GET FEATURE FLAG TOGGLE STATUS DETAILS**
|
169
|
+
|
170
|
+
**_parameters for `ld_fetch_flag_details` method_**
|
171
|
+
- **env** (*required): name of the environment for which you want to get the details (string)
|
172
|
+
- **flag** (*required): name of the feature flag for which you want to get the details (string)
|
173
|
+
|
160
174
|
```ruby
|
161
|
-
|
162
|
-
|
175
|
+
# this method will return the status of the flag, whether it is on or off viz set to true or false
|
176
|
+
def ld_fetch_flag_toggle_status(env, flag)
|
177
|
+
# code ...
|
178
|
+
end
|
179
|
+
```
|
163
180
|
|
164
|
-
|
165
|
-
|
166
|
-
|
181
|
+
**_@return parameter_**: (response of feature flag toggle status viz. response_on)
|
182
|
+
|
183
|
+
- response = `https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}`
|
184
|
+
- response_on = `response['environments'][env]['on']` (boolean)
|
167
185
|
|
186
|
+
<br>
|
187
|
+
|
188
|
+
**3. GET FEW IMPORTANT PARAMETERS FROM FEATURE FLAG**
|
189
|
+
|
190
|
+
**_parameters for `ld_fetch_flag_details` method_**
|
191
|
+
- **env** (*required): name of the environment for which you want to get the details (string)
|
192
|
+
- **flag** (*required): name of the feature flag for which you want to get the details (string)
|
193
|
+
|
194
|
+
```ruby
|
168
195
|
# this method will get important parameters from the response
|
169
196
|
def flag_variation_served(env, flag)
|
170
197
|
# code ...
|
171
198
|
end
|
172
|
-
|
173
|
-
@returns: [fetch_flag_toggle_status_response, feature_flag_variation_index_response, feature_flag_variation_value_response, feature_flag_variation_name_response]
|
174
|
-
@return parameter:
|
175
|
-
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}"
|
176
|
-
fetch_flag_toggle_status_response: response['environments'][env]['on'] (boolean)
|
177
|
-
feature_flag_variation_index_response: response (integer)
|
178
|
-
feature_flag_variation_value_response: response['variations'][feature_flag_variation_index_response]['value'] (string)
|
179
|
-
feature_flag_variation_name_response: response['variations'][feature_flag_variation_index_response]['name'] (string)
|
180
199
|
```
|
181
200
|
|
201
|
+
**@returns**: [fetch_flag_toggle_status_response, feature_flag_variation_index_response, feature_flag_variation_value_response, feature_flag_variation_name_response]
|
202
|
+
|
203
|
+
**_@return parameter_**:
|
204
|
+
|
205
|
+
- response = `https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}`
|
206
|
+
- fetch_flag_toggle_status_response: `response['environments'][#{env}]['on']` (boolean)
|
207
|
+
- feature_flag_variation_index_response: `response` (integer)
|
208
|
+
- feature_flag_variation_value_response: `response['variations'][#{feature_flag_variation_index_response}]['value']` (string)
|
209
|
+
- feature_flag_variation_name_response: `response['variations'][#{feature_flag_variation_index_response}]['name']` (string)
|
210
|
+
|
211
|
+
<br>
|
212
|
+
|
213
|
+
### [Update feature flag](https://apidocs.launchdarkly.com/tag/Feature-flags#operation/patchFeatureFlag)
|
214
|
+
|
215
|
+
Sample: `https://app.launchdarkly.com/api/v2/flags/<project_name>/<feature_flag_name>`
|
216
|
+
|
217
|
+
Example: `https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression`
|
218
|
+
|
219
|
+
<br>
|
220
|
+
|
221
|
+
**1. UPDATE FEATURE FLAG TOGGLE STATUS**
|
222
|
+
|
223
|
+
Here, `developer_flag_for_regression` is the flag key and `default` is our Project name - eg. AmitSinghBisht
|
224
|
+
|
225
|
+
You can update any parameter of feature flag using this method
|
226
|
+
|
227
|
+
**_parameters for `ld_toggle_specific_environment` method_**
|
228
|
+
- **env** (*required): name of the environment for which you want to get the details (string)
|
229
|
+
- **flag** (*required): name of the feature flag for which you want to get the details (string)
|
230
|
+
- **flag_value**: status of the feature flag that you want to set either on (true) or off (false) (boolean)
|
231
|
+
|
182
232
|
```ruby
|
233
|
+
# this method will be used to toggle status of feature flag either on / off for a particular environment
|
234
|
+
def ld_toggle_specific_environment(env, flag, flag_value = true)
|
235
|
+
# code ...
|
236
|
+
end
|
237
|
+
```
|
238
|
+
|
239
|
+
**_@return parameter_**: (response of feature flag toggle status viz. response_on)
|
240
|
+
|
241
|
+
- response = `https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}`
|
242
|
+
- response_on = `response['environments'][env]['on']` (boolean)
|
243
|
+
|
244
|
+
<br>
|
183
245
|
|
246
|
+
**2. UPDATE FEATURE FLAG VALUES INSIDE CLAUSES INSIDE RULES**
|
247
|
+
|
248
|
+
```ruby
|
184
249
|
"rules": [
|
185
250
|
{ # rules/0
|
186
251
|
"variation": 0,
|
@@ -214,94 +279,129 @@ feature_flag_variation_name_response: response['variations'][feature_flag_variat
|
|
214
279
|
]
|
215
280
|
}
|
216
281
|
]
|
282
|
+
```
|
217
283
|
|
218
|
-
|
219
|
-
env (*required): name of the environment for which you want to get the details (string)
|
220
|
-
flag (*required): name of the feature flag for which you want to get the details (string)
|
221
|
-
clause_name (*required): name of clause that you want to search for in response
|
284
|
+
<br>
|
222
285
|
|
286
|
+
**2.a. TO UPDATE FEATURE FLAG - FIRST, GET THE INDEX OF RULES AND CLAUSE INSIDE WHICH VALUE RESIDES**
|
287
|
+
|
288
|
+
**_parameters for `ld_rules_clauses_index` method_**:
|
289
|
+
- **env** (*required): name of the environment for which you want to get the details (string)
|
290
|
+
- **flag** (*required): name of the feature flag for which you want to get the details (string)
|
291
|
+
- **clause_name** (*required): name of clause that you want to search for in response (string)
|
292
|
+
|
293
|
+
```ruby
|
223
294
|
# this method will return the index of rules and clauses by searching for clause_name in response
|
224
295
|
def ld_rules_clauses_index(env, flag, clause_name)
|
225
296
|
# code ...
|
226
297
|
end
|
227
|
-
|
228
|
-
@returns: [rule_at_index, clause_at_index]
|
229
|
-
@return parameter:
|
230
|
-
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}" ['environments'][env]['rules']
|
231
|
-
rule_at_index = response[rule_index] (integer) # index at which rule is found
|
232
|
-
clause_at_index = response[rule_index]['clauses'][clause_index] (integer) # index at which clause is found
|
233
298
|
```
|
234
299
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
300
|
+
**@returns**: [rule_at_index, clause_at_index]
|
301
|
+
|
302
|
+
**_@return parameter_**:
|
303
|
+
|
304
|
+
- response = `https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}`
|
305
|
+
- response_rules = `response['environments'][#{env}]['rules']`
|
306
|
+
- rule_at_index = `response_rules[rule_index]` (integer) # index at which rule is found
|
307
|
+
- clause_at_index = `response_rules[rule_index]['clauses'][clause_index]` (integer) # index at which clause is found
|
240
308
|
|
309
|
+
<br>
|
310
|
+
|
311
|
+
**2.b. GET VALUES INSIDE A CLAUSE BY ITERATING THROUGH REQUIRED INDEX OF RULES AND CLAUSES**
|
312
|
+
|
313
|
+
**_parameters for `ld_get_values_from_clauses` method_**:
|
314
|
+
- **env** (*required): name of the environment for which you want to get the details (string)
|
315
|
+
- **flag** (*required): name of the feature flag for which you want to get the details (string)
|
316
|
+
- **clause_name** (*required): name of clause that you want to search for in response (string)
|
317
|
+
|
318
|
+
```ruby
|
241
319
|
# this method will return values inside a particular clause by searching for clause_name in response
|
242
320
|
def ld_get_values_from_clauses(env, flag, clause_name)
|
243
321
|
# code ...
|
244
322
|
end
|
245
|
-
|
246
|
-
@return parameter: values_for_clause_name
|
247
|
-
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}" ['environments'][env]['rules']
|
248
|
-
values_for_clause_name = response[rule_at_index]['clauses'][clause_at_index]['values'] (string)
|
249
323
|
```
|
250
324
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
325
|
+
**@return parameter**: values_for_clause_name
|
326
|
+
|
327
|
+
- response = `https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}`
|
328
|
+
- response_rules = `response['environments'][#{env}]['rules']`
|
329
|
+
- values_for_clause_name = `response_rules[rule_at_index]['clauses'][clause_at_index]['values']` (string)
|
330
|
+
|
331
|
+
<br>
|
257
332
|
|
333
|
+
**2.c. ADD VALUES TO A PARTICULAR CLAUSE**
|
334
|
+
|
335
|
+
**_parameters for `ld_add_values_to_clause` method_**:
|
336
|
+
- **env** (*required): name of the environment for which you want to get the details (string)
|
337
|
+
- **flag** (*required): name of the feature flag for which you want to get the details (string)
|
338
|
+
- **clause_name** (*required): name of clause that you want to search for in response (string)
|
339
|
+
- **clause_value** (*required): value that you want to add to a particular clause (NOTE: it will be appended at zeroth 0th index) (string or number or json or object)
|
340
|
+
|
341
|
+
```ruby
|
258
342
|
# this method will help you to add a value to a particular clause by searching for clause_name in response
|
259
343
|
def ld_add_values_to_clause(env, flag, clause_name, clause_value)
|
260
344
|
# code ...
|
261
345
|
end
|
262
|
-
|
263
|
-
@return parameter: (response of feature flag details)
|
264
|
-
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}" (string)
|
265
346
|
```
|
266
347
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
348
|
+
**@return parameter**: (response of feature flag details viz. updated_clause_value)
|
349
|
+
|
350
|
+
- response = `https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}`
|
351
|
+
- response_rules = `response['environments'][#{env}]['rules']`
|
352
|
+
- updated_clause_value = `response_rules[rule_at_index]['clauses'][clause_at_index]['values']` (string)
|
353
|
+
|
354
|
+
<br>
|
273
355
|
|
356
|
+
**2.d. DELETE VALUES TO A PARTICULAR CLAUSE**
|
357
|
+
|
358
|
+
**_parameters for `ld_remove_values_from_clause` method_**:
|
359
|
+
- **env** (*required): name of the environment for which you want to get the details (string)
|
360
|
+
- **flag** (*required): name of the feature flag for which you want to get the details (string)
|
361
|
+
- **clause_name** (*required): name of clause that you want to search for in response (string)
|
362
|
+
- **clause_value** (*required): value that you want to add to a particular clause (NOTE: it will be appended at zeroth 0th index) (string or number or json or object)
|
363
|
+
|
364
|
+
|
365
|
+
```ruby
|
274
366
|
# this method will help you to remove a value to a particular clause by searching for clause_name in response
|
275
367
|
def ld_remove_values_from_clause(env, flag, clause_name, clause_value)
|
276
368
|
# code ...
|
277
369
|
end
|
278
|
-
|
279
|
-
@return parameter: (response of feature flag details)
|
280
|
-
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}" (string)
|
281
370
|
```
|
371
|
+
**@return parameter**: (response of feature flag details viz. updated_clause_value)
|
282
372
|
|
283
|
-
|
284
|
-
|
285
|
-
|
373
|
+
- response = `https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}`
|
374
|
+
- response_rules = `response['environments'][#{env}]['rules']`
|
375
|
+
- updated_clause_value = `response_rules[rule_at_index]['clauses'][clause_at_index]['values']` (string)
|
286
376
|
|
287
|
-
|
288
|
-
https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression
|
377
|
+
<br>
|
289
378
|
|
290
|
-
|
291
|
-
You can delete any feature flag using this method
|
379
|
+
### [Delete feature flag](https://apidocs.launchdarkly.com/tag/Feature-flags#operation/deleteFeatureFlag)
|
292
380
|
|
293
|
-
|
294
|
-
|
381
|
+
Sample: `https://app.launchdarkly.com/api/v2/flags/<project_name>/<feature_flag_name>`
|
382
|
+
|
383
|
+
Example: `https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression`
|
295
384
|
|
385
|
+
Here, `developer_flag_for_regression` is the flag key and default is our Project name - eg. AmitSinghBisht
|
386
|
+
|
387
|
+
You can delete any feature flag using this method
|
388
|
+
|
389
|
+
**_parameters for `ld_delete_flag` method_**:
|
390
|
+
- **flag** (*required): name of the feature flag you want to delete (NOTE: env resided inside flag which means flag is parent, so deleting a feature flag will delete it from all environment) (string)
|
391
|
+
|
392
|
+
```ruby
|
296
393
|
# this method will delete a feature flag in launchdarkly (NOTE: env resided inside flag which means flag is parent, so deleting a feature flag will delete it from all environment)
|
297
394
|
def ld_delete_flag(flag)
|
298
395
|
# code ...
|
299
396
|
end
|
300
|
-
|
301
|
-
@return parameter: (response of feature flag details)
|
302
|
-
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}" (string)
|
303
397
|
```
|
304
398
|
|
399
|
+
**@return parameter**: (response of feature flag details)
|
400
|
+
|
401
|
+
- response = `https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}` (string)
|
402
|
+
|
403
|
+
<br>
|
404
|
+
|
305
405
|
## Development
|
306
406
|
|
307
407
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -25,145 +25,61 @@
|
|
25
25
|
require_relative 'launchdarkly_api_helper/constants'
|
26
26
|
require_relative 'launchdarkly_api_helper/launchdarkly_api_helper_class'
|
27
27
|
|
28
|
-
#
|
28
|
+
# LaunchDarklyApiHelper provides you a way to access your Launch Darkly account using API token to view, edit or delete them accordingly.
|
29
29
|
module LaunchdarklyApiHelper
|
30
30
|
class Error < StandardError; end
|
31
31
|
|
32
|
-
#
|
33
|
-
# https://apidocs.launchdarkly.com/
|
34
|
-
# == To perform any operations such as add, remove, replace, move, copy, test you should have a working knowledge of JSON Patch
|
35
|
-
# https://datatracker.ietf.org/doc/html/rfc6902
|
36
|
-
|
32
|
+
# set your LD API token and log file to capture logs
|
37
33
|
def ld_access_token(access_token, project_name = 'default', log_file = 'launchdarkly.log')
|
38
34
|
@launchdarkly_helper = LaunchdarklyApiHelperClass.new(access_token, project_name, log_file)
|
39
35
|
end
|
40
36
|
|
41
|
-
#
|
42
|
-
# https://apidocs.launchdarkly.com/tag/Feature-flags#operation/getFeatureFlag
|
43
|
-
#
|
44
|
-
# == GET REQUEST
|
45
|
-
# https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression
|
46
|
-
#
|
47
|
-
# == key (*required)
|
48
|
-
# env, flag
|
49
|
-
#
|
50
|
-
# == Here, 'developer_flag_for_regression' is the feature flag name and default is our Project name - eg. AmitSinghBisht
|
51
|
-
# == By default, this returns the configurations for all environments
|
52
|
-
# == You can filter environments with the env query parameter. For example, setting env=staging restricts the returned configurations to just the staging environment
|
53
|
-
# https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression?env=staging
|
54
|
-
|
37
|
+
# this method will give you entire details about a flag for that particular environment
|
55
38
|
def ld_fetch_flag_details(env, flag)
|
56
39
|
@launchdarkly_helper.fetch_flag_details(env, flag)
|
57
40
|
end
|
58
41
|
|
59
|
-
#
|
60
|
-
#
|
61
|
-
# == key (*required)
|
62
|
-
# env, flag
|
63
|
-
#
|
64
|
-
# response = https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression?env=staging
|
65
|
-
# grab the value of the ['environments'][env]['on'] obtained from the above response
|
66
|
-
|
42
|
+
# this method will return the status of the flag, whether it is on or off viz set to true or false
|
67
43
|
def ld_fetch_flag_toggle_status(env, flag)
|
68
44
|
@launchdarkly_helper.fetch_flag_toggle_status(env, flag)
|
69
45
|
end
|
70
46
|
|
71
|
-
#
|
72
|
-
# https://apidocs.launchdarkly.com/tag/Feature-flags/#operation/postFeatureFlag
|
73
|
-
#
|
74
|
-
# == POST REQUEST
|
75
|
-
# https://app.launchdarkly.com/api/v2/flags/default
|
76
|
-
#
|
77
|
-
# Here, default is our Project name - Browserstack
|
78
|
-
#
|
79
|
-
# key (*required): A unique key used to reference the flag in your code (string)
|
80
|
-
#
|
81
|
-
# name (*required): A human-friendly name for the feature flag (string)
|
82
|
-
#
|
83
|
-
# description: Description of the feature flag. Defaults to an empty string (string)
|
84
|
-
#
|
85
|
-
# tags: Tags for the feature flag. Defaults to an empty array (Array of strings)
|
86
|
-
#
|
87
|
-
# variations: An array of possible variations for the flag. The variation values must be unique. If omitted, two boolean variations of true and false will be used (Array of objects)
|
88
|
-
#
|
89
|
-
# defaults
|
90
|
-
# * onVariation (*required): The index, from the array of variations for this flag, of the variation to serve by default when targeting is on (integer)
|
91
|
-
# * offVariation (*required): The index, from the array of variations for this flag, of the variation to serve by default when targeting is off (integer)
|
92
|
-
#
|
93
|
-
# {
|
94
|
-
# "key": "developer_flag_for_regression",
|
95
|
-
# "name": "developer_flag_for_regression",
|
96
|
-
# "description": "developer_flag_for_regression is created via regression
|
97
|
-
# api on 18_10_2022",
|
98
|
-
# "tags": [
|
99
|
-
# "created_via_regression_api_on_18_10_2022"
|
100
|
-
# ],
|
101
|
-
# "variations": [
|
102
|
-
# {
|
103
|
-
# "age": 10
|
104
|
-
# },
|
105
|
-
# {
|
106
|
-
# "age": 20
|
107
|
-
# }
|
108
|
-
# ],
|
109
|
-
# "defaults": {
|
110
|
-
# "onVariation": 1,
|
111
|
-
# "offVariation": 0
|
112
|
-
# }
|
113
|
-
# }
|
114
|
-
#
|
115
|
-
# Above code will create a key 'developer_flag_for_regression' with name as 'developer_flag_for_regression' and description as 'developer_flag_for_regression is created via regression api on 18_10_2022'
|
116
|
-
#
|
117
|
-
# Variations are provided while creating key, by default variation is a boolean value (true and false). once flag with a specific variation is created, its type cannot be modified later, hence choose your variation type smartly (Boolean, String, Number, JSON) In above example we are creating a flag with JSON type and its two values are 'age': 10 and 'age': 20
|
118
|
-
#
|
119
|
-
# Also, variation has by default two values, and you must also define two variations while creating your own custom feature flag
|
120
|
-
#
|
121
|
-
# Default will specify which variation to serve when flag is on or off. In above example when flag is turned on, '1' variation is served [Note: 0 and 1 are index position], so variations at first index ie variations[1] will be served when flag is turned on ie 'age': 20
|
122
|
-
|
47
|
+
# this method will create a new feature flag, NOTE: feature falg are created at global level and environment resides inside feature flag
|
123
48
|
def ld_create_flag(key, name = key, description = key, tags = ['created_via_regression_api'])
|
124
49
|
@launchdarkly_helper.create_flag(key, name, description, tags)
|
125
50
|
end
|
126
51
|
|
127
|
-
#
|
128
|
-
# https://apidocs.launchdarkly.com/tag/Feature-flags#operation/patchFeatureFlag
|
129
|
-
#
|
130
|
-
# == PATCH REQUEST
|
131
|
-
# https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression
|
132
|
-
#
|
133
|
-
# key (*required)
|
134
|
-
#
|
135
|
-
# == Here, 'developer_flag_for_regression' is the flag key and default is our Project name - Browserstack
|
136
|
-
# == You can update any parameter of feature flag using this method
|
137
|
-
|
52
|
+
# this method will be used to toggle status of feature flag either on / off for a particular environment
|
138
53
|
def ld_toggle_specific_environment(env, flag, flag_value = true)
|
139
54
|
@launchdarkly_helper.toggle_specific_environment(env, flag, flag_value)
|
140
55
|
end
|
141
56
|
|
142
|
-
#
|
143
|
-
# https://apidocs.launchdarkly.com/tag/Feature-flags#operation/patchFeatureFlag
|
144
|
-
#
|
145
|
-
# [fetch_flag_toggle_status_response, feature_flag_variation_index_response, feature_flag_variation_value_response, feature_flag_variation_name_response]
|
146
|
-
|
57
|
+
# this method will get important parameters from the response
|
147
58
|
def ld_flag_variation_served(env, flag)
|
148
59
|
@launchdarkly_helper.flag_variation_served(env, flag)
|
149
60
|
end
|
150
61
|
|
62
|
+
# this method will return the index of rules and clauses by searching for clause_name in response
|
151
63
|
def ld_rules_clauses_index(env, flag, clause_name)
|
152
64
|
@launchdarkly_helper.rules_clauses_index(env, flag, clause_name)
|
153
65
|
end
|
154
66
|
|
67
|
+
# this method will return values inside a particular clause by searching for clause_name in response
|
155
68
|
def ld_get_values_from_clauses(env, flag, clause_name)
|
156
69
|
@launchdarkly_helper.get_values_from_clauses(env, flag, clause_name)
|
157
70
|
end
|
158
71
|
|
72
|
+
# this method will help you to add a value to a particular clause by searching for clause_name in response
|
159
73
|
def ld_add_values_to_clause(env, flag, clause_name, clause_value)
|
160
74
|
@launchdarkly_helper.add_values_to_clause(env, flag, clause_name, clause_value)
|
161
75
|
end
|
162
76
|
|
77
|
+
# this method will help you to remove a value to a particular clause by searching for clause_name in response
|
163
78
|
def ld_remove_values_from_clause(env, flag, clause_name, clause_value)
|
164
79
|
@launchdarkly_helper.remove_values_from_clause(env, flag, clause_name, clause_value)
|
165
80
|
end
|
166
81
|
|
82
|
+
# this method will delete a feature flag in launchdarkly (NOTE: env resided inside flag which means flag is parent, so deleting a feature flag will delete it from all environment)
|
167
83
|
def ld_delete_flag(flag)
|
168
84
|
@launchdarkly_helper.delete_flag(flag)
|
169
85
|
end
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: launchdarkly_api_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- amit-singh-bisht
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: LaunchDarklyApiHelper provides you a way to access your Launch Darkly
|
14
|
+
account using API token to view, edit or delete them accordingly. https://bit.ly/ld_doc
|
14
15
|
email:
|
15
16
|
- bishtamitsingh98@gmail.com
|
16
17
|
executables: []
|
@@ -34,7 +35,7 @@ metadata:
|
|
34
35
|
homepage_uri: https://github.com/amit-singh-bisht/launchdarkly_api_helper_ruby
|
35
36
|
source_code_uri: https://github.com/amit-singh-bisht/launchdarkly_api_helper_ruby
|
36
37
|
changelog_uri: https://github.com/amit-singh-bisht/launchdarkly_api_helper_ruby/blob/master/README.md
|
37
|
-
post_install_message:
|
38
|
+
post_install_message:
|
38
39
|
rdoc_options: []
|
39
40
|
require_paths:
|
40
41
|
- lib
|
@@ -49,8 +50,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
50
|
- !ruby/object:Gem::Version
|
50
51
|
version: '0'
|
51
52
|
requirements: []
|
52
|
-
|
53
|
-
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.7.3
|
55
|
+
signing_key:
|
54
56
|
specification_version: 4
|
55
|
-
summary:
|
57
|
+
summary: LaunchDarklyApiHelper provides you a way to access your Launch Darkly account
|
58
|
+
using API token to view, edit or delete them accordingly. https://bit.ly/ld_doc
|
56
59
|
test_files: []
|