{"id":19261092,"url":"https://github.com/amit-singh-bisht/launchdarkly_api_helper_ruby","last_synced_at":"2025-04-21T17:30:35.598Z","repository":{"id":63405169,"uuid":"567591295","full_name":"amit-singh-bisht/launchdarkly_api_helper_ruby","owner":"amit-singh-bisht","description":"LaunchDarklyApiHelper provides you a way to access your Launch Darkly account using API token to view, edit or delete them accordingly.","archived":false,"fork":false,"pushed_at":"2022-11-21T06:39:47.000Z","size":77,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-01T14:45:54.665Z","etag":null,"topics":["api-client","api-client-ruby","feature-flags","feature-toggle","launchdarkly","launchdarkly-api","launchdarkly-api-automation","launchdarkly-automation","ruby"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/launchdarkly_api_helper","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amit-singh-bisht.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-11-18T05:41:25.000Z","updated_at":"2022-11-20T12:00:33.000Z","dependencies_parsed_at":"2023-01-22T17:31:09.377Z","dependency_job_id":null,"html_url":"https://github.com/amit-singh-bisht/launchdarkly_api_helper_ruby","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amit-singh-bisht%2Flaunchdarkly_api_helper_ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amit-singh-bisht%2Flaunchdarkly_api_helper_ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amit-singh-bisht%2Flaunchdarkly_api_helper_ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amit-singh-bisht%2Flaunchdarkly_api_helper_ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amit-singh-bisht","download_url":"https://codeload.github.com/amit-singh-bisht/launchdarkly_api_helper_ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248860044,"owners_count":21173342,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-client","api-client-ruby","feature-flags","feature-toggle","launchdarkly","launchdarkly-api","launchdarkly-api-automation","launchdarkly-automation","ruby"],"created_at":"2024-11-09T19:24:32.089Z","updated_at":"2025-04-21T17:30:35.377Z","avatar_url":"https://github.com/amit-singh-bisht.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LaunchdarklyApiHelper \n\u003cdiv\u003e\n    \u003ca href=\"https://rubygems.org/gems/launchdarkly_api_helper\"\u003e\n        \u003cimg alt=\"GEM Version\" src=\"https://img.shields.io/gem/v/launchdarkly_api_helper?color=38C160\u0026logo=ruby\u0026logoColor=FE1616\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://rubygems.org/gems/launchdarkly_api_helper\"\u003e\n        \u003cimg alt=\"Gem Downloads\" src=\"https://img.shields.io/gem/dt/launchdarkly_api_helper?color=38C160\u0026logo=ruby\u0026logoColor=FE1616\"\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\n\u003cbr\u003e\n\n[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.\n\n\u003cbr\u003e\n\n[Launch Darkly API Documentation](https://apidocs.launchdarkly.com/)\n\n## Installation\n\nInstall the gem and add to the application's Gemfile by executing:\n\n    $ bundle add launchdarkly_api_helper\n\nIf bundler is not being used to manage dependencies, install the gem by executing:\n\n    $ gem install launchdarkly_api_helper\n\n## Usage\n\nadd `require 'launchdarkly_api_helper'` line at the beginning of your Ruby file\n\nadd `include LaunchdarklyApiHelper` line to access LaunchdarklyApiHelper module in gem _launchdarkly_api_helper_\n\nTo 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)\n\n\u003cbr\u003e\n\nProjects 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)\n\n![alt text](https://docs.launchdarkly.com/static/082f7fa3cbb6ed1081425340586e47ad/fe238/projects-two-app-types.png)\n\n![alt text](https://docs.launchdarkly.com/static/55307ea3f0a386269181a1982fcc20ff/75a80/settings-projects-create.png)\n\n\u003cbr\u003e\n\n### [Set Access Token](https://apidocs.launchdarkly.com/tag/Access-tokens)\n\n![alt text](https://docs.launchdarkly.com/static/de107a76f0cd388da14d5bd650ec1f5c/b8471/settings-access-tokens-obscured-callout.png)\n\n**_parameters for `ld_access_token` method_**\n- **access_token (*required)**: this token will be used to send all requests to LaunchDarkly (string)\n- **project_name**: provide project name of your organization (NOTE: for most, it should be `default` unless you have made some explicit changes)\n- **log_file**: all logs will be written to file 'launchdarkly.log' by default if no file name specified (string)\n\n```ruby\n# set your LD API token and log file to capture logs\ndef ld_access_token(access_token, project_name = 'default', log_file = 'launchdarkly.log') \n  # code ...\nend\n```\n\n\u003cbr\u003e\n\n### [Create a feature flag](https://apidocs.launchdarkly.com/tag/Feature-flags/#operation/postFeatureFlag)\n\nSample: `https://app.launchdarkly.com/api/v2/flags/\u003cproject_name\u003e`\n\nExample: `https://app.launchdarkly.com/api/v2/flags/default`\n\nHere, `default` is our Project name - eg. AmitSinghBisht\n\nparameters:\n\n- **key (*required)**: A unique key used to reference the feature flag in your code (string)\n- **name (*required)**: A human-friendly name for the feature flag (string)\n- **description**: Description of the feature flag. Defaults to an empty string (string)\n- **tags**: Tags for the feature flag. Defaults to an empty array (Array of strings)\n- **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)\n- **defaults**\n  - **onVariation** (*required): The index, from the array of variations for this flag, of the variation to serve by default when targeting is on (integer)\n  - **offVariation** (*required): The index, from the array of variations for this flag, of the variation to serve by default when targeting is off (integer)\n\n```ruby\n{\n  \"key\": \"developer_flag_for_regression\",\n  \"name\": \"developer_flag_for_regression\",\n  \"description\": \"developer_flag_for_regression is created via regression api on 18_10_2022\",\n  \"tags\": [\n    \"created_via_regression_api_on_18_10_2022\"\n  ],\n  \"variations\": [\n    {\n      \"age\": 10\n    },\n    {\n      \"age\": 20\n    }\n  ],\n  \"defaults\": {\n    \"onVariation\": 1,\n    \"offVariation\": 0\n  }\n}\n```\n\nAbove 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`\n\nVariations 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\n\nAlso, variation has by default two values, and you must also define two variations while creating your own custom feature flag\n\nDefault 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\n\n**_parameters for `ld_create_flag` method_**\n- **key (*required)**: A unique key used to reference the feature flag in your code (string)\n- **name**: A human-friendly name for the feature flag (string)\n- **description**: Description of the feature flag. Defaults to an empty string (string)\n- **tags**: Tags for the feature flag. Defaults to an empty array (Array of strings)\n\n```ruby\n# this method will create a new feature flag, NOTE: feature falg are created at global level and environment resides inside feature flag\ndef ld_create_flag(key, name = key, description = key, tags = ['created_via_regression_api'])\n  # code ...\nend\n```\n\n**_@return parameter_**: (response of feature flag details)\n\n- response = `https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}` (string)\n\n\u003cbr\u003e\n\n### [Get feature flag](https://apidocs.launchdarkly.com/tag/Feature-flags#operation/getFeatureFlag)\n\nSample: `https://app.launchdarkly.com/api/v2/flags/\u003cproject_name\u003e/\u003cfeature_flag_name\u003e`\n\nExample: `https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression`\n\n\u003cbr\u003e\n\n**1. GET FEATURE FLAG DETAILS**\n\nHere, `developer_flag_for_regression` is the feature flag name and `default` is our Project name - eg. AmitSinghBisht\n\nBy default, this returns the configurations for all environments\n\nYou can filter environments with the env query parameter. For example, setting env=staging restricts the returned configurations to just the staging environment\n`https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression?env=staging`\n\n**_parameters for `ld_fetch_flag_details` method_**\n- **env** (*required): name of the environment for which you want to get the details (string)\n- **flag** (*required): name of the feature flag for which you want to get the details (string)\n\n```ruby\n# this method will give you entire details about a flag for that particular environment\ndef ld_fetch_flag_details(env, flag)\n  # code ...\nend\n```\n\n**_@return parameter_**: (response of feature flag details)\n\n- response = `https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}` (string)\n\n\u003cbr\u003e\n\n**2. GET FEATURE FLAG TOGGLE STATUS DETAILS**\n\n**_parameters for `ld_fetch_flag_details` method_**\n- **env** (*required): name of the environment for which you want to get the details (string)\n- **flag** (*required): name of the feature flag for which you want to get the details (string)\n\n```ruby\n# this method will return the status of the flag, whether it is on or off viz set to true or false\ndef ld_fetch_flag_toggle_status(env, flag)\n  # code ...\nend\n```\n\n**_@return parameter_**: (response of feature flag toggle status viz. response_on)\n\n- response = `https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}`\n- response_on = `response['environments'][env]['on']` (boolean)\n\n\u003cbr\u003e\n\n**3. GET FEW IMPORTANT PARAMETERS FROM FEATURE FLAG**\n\n**_parameters for `ld_fetch_flag_details` method_**\n- **env** (*required): name of the environment for which you want to get the details (string)\n- **flag** (*required): name of the feature flag for which you want to get the details (string)\n\n```ruby\n# this method will get important parameters from the response\ndef flag_variation_served(env, flag)\n  # code ...\nend\n```\n\n**@returns**: [fetch_flag_toggle_status_response, feature_flag_variation_index_response, feature_flag_variation_value_response, feature_flag_variation_name_response]\n\n**_@return parameter_**:\n\n- response = `https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}`\n- fetch_flag_toggle_status_response: `response['environments'][#{env}]['on']` (boolean)\n- feature_flag_variation_index_response: `response` (integer)\n- feature_flag_variation_value_response: `response['variations'][#{feature_flag_variation_index_response}]['value']` (string)\n- feature_flag_variation_name_response: `response['variations'][#{feature_flag_variation_index_response}]['name']` (string)\n\n\u003cbr\u003e\n\n### [Update feature flag](https://apidocs.launchdarkly.com/tag/Feature-flags#operation/patchFeatureFlag)\n\nSample: `https://app.launchdarkly.com/api/v2/flags/\u003cproject_name\u003e/\u003cfeature_flag_name\u003e`\n\nExample: `https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression`\n\n\u003cbr\u003e\n\n**1. UPDATE FEATURE FLAG TOGGLE STATUS**\n\nHere, `developer_flag_for_regression` is the flag key and `default` is our Project name - eg. AmitSinghBisht\n\nYou can update any parameter of feature flag using this method\n\n**_parameters for `ld_toggle_specific_environment` method_**\n- **env** (*required): name of the environment for which you want to get the details (string)\n- **flag** (*required): name of the feature flag for which you want to get the details (string)\n- **flag_value**: status of the feature flag that you want to set either on (true) or off (false) (boolean)\n\n```ruby\n# this method will be used to toggle status of feature flag either on / off for a particular environment\ndef ld_toggle_specific_environment(env, flag, flag_value = true)\n  # code ...\nend\n```\n\n**_@return parameter_**: (response of feature flag toggle status viz. response_on)\n\n- response = `https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}`\n- response_on = `response['environments'][env]['on']` (boolean)\n\n\u003cbr\u003e\n\n**2. UPDATE FEATURE FLAG VALUES INSIDE CLAUSES INSIDE RULES**\n\n```ruby\n\"rules\": [\n  {                                   # rules/0\n    \"variation\": 0,\n    \"clauses\": [\n      {                               # rules/0/clauses/0\n        \"attribute\": \"groups\",\n        \"op\": \"in\",\n        \"values\": [\"Top Customers\"],\n        \"negate\": false\n      },\n      {                               # rules/0/clauses/1\n        \"attribute\": \"email\",\n        \"op\": \"endsWith\",\n        \"values\": [\"gmail.com\"],\n        \"negate\": false\n      }\n    ]\n  },\n  {                                   # rules/1\n    \"variation\": 1,\n    \"clauses\": [\n      {                               # rules/1/clauses/0\n        \"attribute\": \"country\",\n        \"op\": \"in\",\n        \"values\": [\n          \"in\",                       # rules/1/clauses/0/values/0\n          \"eu\"                        # rules/1/clauses/0/values/1\n        ],\n        \"negate\": false\n      }\n    ]\n  }\n]\n```\n\n\u003cbr\u003e\n\n**2.a. TO UPDATE FEATURE FLAG - FIRST, GET THE INDEX OF RULES AND CLAUSE INSIDE WHICH VALUE RESIDES**\n\n**_parameters  for `ld_rules_clauses_index` method_**:\n- **env** (*required): name of the environment for which you want to get the details (string)\n- **flag** (*required): name of the feature flag for which you want to get the details (string)\n- **clause_name** (*required): name of clause that you want to search for in response (string)\n\n```ruby\n# this method will return the index of rules and clauses by searching for clause_name in response\ndef ld_rules_clauses_index(env, flag, clause_name)\n  # code ...\nend\n```\n\n**@returns**: [rule_at_index, clause_at_index]\n\n**_@return parameter_**:\n\n- response = `https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}`\n- response_rules = `response['environments'][#{env}]['rules']`\n- rule_at_index = `response_rules[rule_index]`  (integer) # index at which rule is found\n- clause_at_index = `response_rules[rule_index]['clauses'][clause_index]`  (integer) # index at which clause is found \n\n\u003cbr\u003e\n\n**2.b. GET VALUES INSIDE A CLAUSE BY ITERATING THROUGH REQUIRED INDEX OF RULES AND CLAUSES**\n\n**_parameters  for `ld_get_values_from_clauses` method_**:\n- **env** (*required): name of the environment for which you want to get the details (string)\n- **flag** (*required): name of the feature flag for which you want to get the details (string)\n- **clause_name** (*required): name of clause that you want to search for in response (string)\n\n```ruby\n# this method will return values inside a particular clause by searching for clause_name in response\ndef ld_get_values_from_clauses(env, flag, clause_name)\n  # code ...\nend\n```\n\n**@return parameter**: values_for_clause_name\n\n- response = `https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}`\n- response_rules = `response['environments'][#{env}]['rules']`\n- values_for_clause_name = `response_rules[rule_at_index]['clauses'][clause_at_index]['values']` (string)\n\n\u003cbr\u003e\n\n**2.c. ADD VALUES TO A PARTICULAR CLAUSE**\n\n**_parameters  for `ld_add_values_to_clause` method_**:\n- **env** (*required): name of the environment for which you want to get the details (string)\n- **flag** (*required): name of the feature flag for which you want to get the details (string)\n- **clause_name** (*required): name of clause that you want to search for in response (string)\n- **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)\n\n```ruby\n# this method will help you to add a value to a particular clause by searching for clause_name in response\ndef ld_add_values_to_clause(env, flag, clause_name, clause_value)\n  # code ...\nend\n```\n\n**@return parameter**: (response of feature flag details viz. updated_clause_value)\n\n- response = `https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}`\n- response_rules = `response['environments'][#{env}]['rules']`\n- updated_clause_value = `response_rules[rule_at_index]['clauses'][clause_at_index]['values']` (string)\n\n\u003cbr\u003e\n\n**2.d. DELETE VALUES TO A PARTICULAR CLAUSE**\n\n**_parameters  for `ld_remove_values_from_clause` method_**:\n- **env** (*required): name of the environment for which you want to get the details (string)\n- **flag** (*required): name of the feature flag for which you want to get the details (string)\n- **clause_name** (*required): name of clause that you want to search for in response (string)\n- **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)\n\n\n```ruby\n# this method will help you to remove a value to a particular clause by searching for clause_name in response\ndef ld_remove_values_from_clause(env, flag, clause_name, clause_value)\n  # code ...\nend\n```\n**@return parameter**: (response of feature flag details viz. updated_clause_value)\n\n- response = `https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}`\n- response_rules = `response['environments'][#{env}]['rules']`\n- updated_clause_value = `response_rules[rule_at_index]['clauses'][clause_at_index]['values']` (string)\n\n\u003cbr\u003e\n\n### [Delete feature flag](https://apidocs.launchdarkly.com/tag/Feature-flags#operation/deleteFeatureFlag)\n\nSample: `https://app.launchdarkly.com/api/v2/flags/\u003cproject_name\u003e/\u003cfeature_flag_name\u003e`\n\nExample: `https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression`\n\nHere, `developer_flag_for_regression` is the flag key and default is our Project name - eg. AmitSinghBisht\n\nYou can delete any feature flag using this method\n\n**_parameters  for `ld_delete_flag` method_**:\n- **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)\n \n```ruby\n# 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)\ndef ld_delete_flag(flag)\n  # code ...\nend\n```\n\n**@return parameter**: (response of feature flag details)\n\n- response = `https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}` (string)\n\n\u003cbr\u003e\n\n## Development\n\nAfter 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.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/launchdarkly_api_helper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/launchdarkly_api_helper/blob/master/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the LaunchdarklyApiHelper project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/launchdarkly_api_helper/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famit-singh-bisht%2Flaunchdarkly_api_helper_ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famit-singh-bisht%2Flaunchdarkly_api_helper_ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famit-singh-bisht%2Flaunchdarkly_api_helper_ruby/lists"}