launchdarkly_api_helper 0.3.0 → 0.4.0

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: ce783cd020dfb08afa37d2c2def2a34e637ac5206372cde1e33692fce4fc7e9c
4
- data.tar.gz: 001f9d326e6361449587ac36107296af04e02cacc1d238c903a7622cb9af718f
3
+ metadata.gz: f063313104693353f6dd3e18a6ecd69c5142b62eb3f072b08f96b8b51e9175e0
4
+ data.tar.gz: 1f83a4dc6665e8864605decdb1d265178232785d44cca584488533fe21bd4ce6
5
5
  SHA512:
6
- metadata.gz: 97992fe3501448666a630a59f779e35228fe75afa9e2b57d55396d56e2a8917caac50f232041bb5c59e6d9f356093628c4730db192dca2225bbd384323f57e0f
7
- data.tar.gz: ebb0edb818fb938053a390ee8680d6fe6e309a6433c634ad2cd0e9de93220577584db74aa5157ea643b6f0a19f8ba70591e780493cce4fb0e6d776546cd7b628
6
+ metadata.gz: e9fadbf1588e1d429f3cf3d1bf9bcccf6b06bda032baa707970a65714321a970e8e5d8f952baa99be5115e4986564c45bbcfcc07034f829637522569e5fd9f15
7
+ data.tar.gz: b947d46ef24947acba122a57ce2e2c582af6342806e357de59864523ba4b8e78e9d81185dc6f51d4b183621d94b97d206840d020dc5226731db866ef77a25c7a
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # LaunchdarklyApiHelper
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/launchdarkly_api_helper`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [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
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ ![alt text](https://docs.launchdarkly.com/static/de107a76f0cd388da14d5bd650ec1f5c/b8471/settings-access-tokens-obscured-callout.png)
6
+
7
+ [Launch Darkly API Documentation](https://apidocs.launchdarkly.com/)
6
8
 
7
9
  ## Installation
8
10
 
@@ -16,7 +18,193 @@ If bundler is not being used to manage dependencies, install the gem by executin
16
18
 
17
19
  ## Usage
18
20
 
19
- TODO: Write usage instructions here
21
+ add `require 'launchdarkly_api_helper'` line at the beginning of your Ruby file
22
+
23
+ add `include LaunchdarklyApiHelper` line to access LaunchdarklyApiHelper module in gem _launchdarkly_api_helper_
24
+
25
+ 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
+
27
+ ```ruby
28
+ parameters:
29
+ access_token (*required): this token will be used to send all requests to LaunchDarkly (string)
30
+ log_file: all logs will be writeen to file 'launchdarkly.log' by default if no file name specified
31
+
32
+ # set your LD API token and log file to capture logs
33
+ def ld_access_token(access_token, log_file = 'launchdarkly.log')
34
+ # code ...
35
+ end
36
+ ```
37
+
38
+ [Get feature flag](https://apidocs.launchdarkly.com/tag/Feature-flags#operation/getFeatureFlag)
39
+
40
+ ```ruby
41
+ GET REQUEST
42
+ https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression
43
+
44
+ parameters:
45
+ env (*required): name of the environment for which you want to get the details (string)
46
+ flag (*required): name of the feature flag for which you want to get the details (string)
47
+
48
+ Here, 'developer_flag_for_regression' is the feature flag name and default is our Project name - eg. AmitSinghBisht
49
+ By default, this returns the configurations for all environments
50
+ You can filter environments with the env query parameter. For example, setting env=staging restricts the returned configurations to just the staging environment
51
+ https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression?env=staging
52
+
53
+ # this method will give you entire details about a flag for that particular environment
54
+ def ld_fetch_flag_details(env, flag)
55
+ # code ...
56
+ end
57
+
58
+ @return value (response of feature flag details):
59
+ response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}" (string)
60
+ ```
61
+
62
+ ```ruby
63
+ Get toggle status feature flag
64
+
65
+ parameters:
66
+ env (*required): name of the environment for which you want to get the details (string)
67
+ flag (*required): name of the feature flag for which you want to get the details (string)
68
+
69
+ response = https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression?env=staging
70
+ grab the value of the ['environments'][env]['on'] obtained from the above response
71
+
72
+ # this method will return the status of the flag, whether it is on or off viz set to true or false
73
+ def ld_fetch_flag_toggle_status(env, flag)
74
+ # code ...
75
+ end
76
+
77
+ @return value (response of feature flag toggle status):
78
+ response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}"
79
+ response['environments'][env]['on'] (boolean)
80
+ ```
81
+
82
+ ```ruby
83
+ Create a feature flag
84
+ https://apidocs.launchdarkly.com/tag/Feature-flags/#operation/postFeatureFlag
85
+
86
+ POST REQUEST
87
+ https://app.launchdarkly.com/api/v2/flags/default
88
+
89
+ Here, default is our Project name - eg. AmitSinghBisht
90
+
91
+ parameters:
92
+ key (*required): A unique key used to reference the feature flag in your code (string)
93
+ name (*required): A human-friendly name for the feature flag (string)
94
+ description: Description of the feature flag. Defaults to an empty string (string)
95
+ tags: Tags for the feature flag. Defaults to an empty array (Array of strings)
96
+ 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)
97
+
98
+ defaults
99
+ * onVariation (*required): The index, from the array of variations for this flag, of the variation to serve by default when targeting is on (integer)
100
+ * offVariation (*required): The index, from the array of variations for this flag, of the variation to serve by default when targeting is off (integer)
101
+
102
+ {
103
+ "key": "developer_flag_for_regression",
104
+ "name": "developer_flag_for_regression",
105
+ "description": "developer_flag_for_regression is created via regression api on 18_10_2022",
106
+ "tags": [
107
+ "created_via_regression_api_on_18_10_2022"
108
+ ],
109
+ "variations": [
110
+ {
111
+ "age": 10
112
+ },
113
+ {
114
+ "age": 20
115
+ }
116
+ ],
117
+ "defaults": {
118
+ "onVariation": 1,
119
+ "offVariation": 0
120
+ }
121
+ }
122
+
123
+ 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'
124
+
125
+ 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
126
+
127
+ Also, variation has by default two values, and you must also define two variations while creating your own custom feature flag
128
+
129
+ 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
130
+
131
+ # this method will create a new feature flag, NOTE: feature falg are created at global level and environment resides inside feature flag
132
+ def ld_create_flag(key, name = key, description = key, tags = ['created_via_regression_api'])
133
+ # code ...
134
+ end
135
+ ```
136
+
137
+ ```ruby
138
+ Update feature flag
139
+ https://apidocs.launchdarkly.com/tag/Feature-flags#operation/patchFeatureFlag
140
+
141
+ PATCH REQUEST
142
+ https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression
143
+
144
+ parameters:
145
+ env (*required): name of the environment for which you want to get the details (string)
146
+ flag (*required): name of the feature flag for which you want to get the details (string)
147
+ flag_value: status of the feature flag that you want to set either on (true) or off (false) (boolean)
148
+
149
+ Here, 'developer_flag_for_regression' is the flag key and default is our Project name - eg. AmitSinghBisht
150
+ You can update any parameter of feature flag using this method
151
+
152
+ # this method will be used to toggle status of feature flag either on / off for a particular environment
153
+ def ld_toggle_specific_environment(env, flag, flag_value = true)
154
+ # code ...
155
+ end
156
+
157
+ @return value (response of feature flag toggle status):
158
+ response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}"
159
+ response['environments'][env]['on'] (boolean)
160
+ ```
161
+
162
+ ```ruby
163
+ Get status of feature flag
164
+ https://apidocs.launchdarkly.com/tag/Feature-flags#operation/patchFeatureFlag
165
+
166
+ def ld_toggle_variation_served(env, flag)
167
+ # code ...
168
+ end
169
+
170
+ @returns: [fetch_flag_toggle_status_response, feature_flag_variation_index_response, feature_flag_variation_value_response, feature_flag_variation_name_response]
171
+ @return parameter:
172
+ response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}"
173
+ fetch_flag_toggle_status_response: response['environments'][env]['on'] (boolean)
174
+ feature_flag_variation_index_response: response (integer)
175
+ feature_flag_variation_value_response: response['variations'][feature_flag_variation_index_response]['value'] (object)
176
+ feature_flag_variation_name_response: response['variations'][feature_flag_variation_index_response]['name'] (string)
177
+ ```
178
+
179
+ ```ruby
180
+ def ld_rules_clauses_index(env, flag, clause_name)
181
+ # code ...
182
+ end
183
+ ```
184
+
185
+ ```ruby
186
+ def ld_get_values_from_clauses(env, flag, clause_name)
187
+ # code ...
188
+ end
189
+ ```
190
+
191
+ ```ruby
192
+ def ld_add_values_to_clause(env, flag, clause_name, clause_value)
193
+ # code ...
194
+ end
195
+ ```
196
+
197
+ ```ruby
198
+ def ld__remove_values_from_clause(env, flag, clause_name, clause_value)
199
+ # code ...
200
+ end
201
+ ```
202
+
203
+ ```ruby
204
+ def ld_delete_flag(flag)
205
+ # code ...
206
+ end
207
+ ```
20
208
 
21
209
  ## Development
22
210
 
@@ -21,4 +21,4 @@ REQUEST_CLASSES = {
21
21
  'code' => 204,
22
22
  'message' => 'No Content'
23
23
  }
24
- }.freeze
24
+ }.freeze
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LaunchdarklyApiHelper
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: launchdarkly_api_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - amit-singh-bisht
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-18 00:00:00.000000000 Z
11
+ date: 2022-11-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Write a longer description or delete this line.
14
14
  email: