1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-09 00:18:00 +01:00

Added video link and fixed types (#7942)

Kudos to GitHub for showing the diff despite me renaming the file
This commit is contained in:
Alvin Bryan 2024-08-20 19:00:38 +01:00 committed by GitHub
parent 500a9c7df4
commit 2ec2639fa3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 6 deletions

View File

@ -4,6 +4,8 @@ description: "How to use Unleash feature flags with Ruby."
slug: /feature-flag-tutorials/ruby slug: /feature-flag-tutorials/ruby
--- ---
import VideoContent from '@site/src/components/VideoContent.jsx';
Hello! In this tutorial well show you how to add feature flags to your Ruby app , using [Unleash](https://www.getunleash.io/) and the official [Unleash Ruby SDK](https://docs.getunleash.io/reference/sdks/ruby). With Unleash, an open-source feature flag service, you can use our tooling to add feature flags to your application and release new features faster. Hello! In this tutorial well show you how to add feature flags to your Ruby app , using [Unleash](https://www.getunleash.io/) and the official [Unleash Ruby SDK](https://docs.getunleash.io/reference/sdks/ruby). With Unleash, an open-source feature flag service, you can use our tooling to add feature flags to your application and release new features faster.
In a classic tutorial fashion, well get a list of planets from the [Star Wars API](https://swapi.dev/), with just Ruby (i.e., not Ruby on Rails). Well use feature flags to decide whether to call the REST or the GraphQL version of the API. In a classic tutorial fashion, well get a list of planets from the [Star Wars API](https://swapi.dev/), with just Ruby (i.e., not Ruby on Rails). Well use feature flags to decide whether to call the REST or the GraphQL version of the API.
@ -17,6 +19,11 @@ In a classic tutorial fashion, well get a list of planets from the [Star Wars
- [6. Verify the toggle experience](#6-verify-the-toggle-experience) - [6. Verify the toggle experience](#6-verify-the-toggle-experience)
- [Conclusion](#conclusion) - [Conclusion](#conclusion)
Watch the video tutorial and follow along with the code from this documentation.
<VideoContent videoUrls={["https://www.youtube.com/embed/lgR9jUek94U?si=nEX9vnAehlSMpkzw"]}/>
## Prerequisites ## Prerequisites
For this tutorial, youll need the following: For this tutorial, youll need the following:

View File

@ -204,12 +204,13 @@ We want to let you choose the nature of that concurrency, so we're compatible wi
```rust ```rust
use enum_map::Enum; use enum_map::Enum;
use image::ImageReader; use image::ImageReader;
use serde::{Deserialize, Serialize};
use std::error::Error; use std::error::Error;
use std::fs; use std::fs;
use serde::{Deserialize, Serialize};
use std::time::Duration; use std::time::Duration;
use tokio::time::sleep; use tokio::time::sleep;
use unleash_api_client::client::ClientBuilder; use unleash_api_client::client::ClientBuilder;
use unleash_api_client::Client;
use webp::Encoder; use webp::Encoder;
#[derive(Debug, Deserialize, Serialize, Enum, Clone)] #[derive(Debug, Deserialize, Serialize, Enum, Clone)]
@ -218,8 +219,8 @@ enum Flags {
} }
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> { async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let client = ClientBuilder::default().into_client::<Flags, reqwest::Client>( let client:Client<Flags, reqwest::Client> = ClientBuilder::default().into_client(
"http://localhost:4242/api", "http://localhost:4242/api",
"unleash-rust-client-example", "unleash-rust-client-example",
"unleash-rust-client-example", "unleash-rust-client-example",
@ -232,17 +233,17 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
sleep(Duration::from_millis(500)).await; sleep(Duration::from_millis(500)).await;
let is_webp = client.is_enabled(Flags::webp, None, false); let is_webp = client.is_enabled(Flags::webp, None, false);
process_images(is_webp)?; process_image(is_webp)?;
// allow tokio::join to finish // allow tokio::join to finish
client.stop_poll().await; client.stop_poll().await;
Ok::<(), Box<dyn Error + Send + Sync + 'static>>(()) Ok::<(), Box<dyn Error + Send + Sync>>(())
}); });
Ok(()) Ok(())
} }
fn process_image(is_webp: bool) -> Result<(), Box<dyn Error>> { fn process_image(is_webp: bool) -> Result<(), Box<dyn Error + Send + Sync>> {
let img = ImageReader::open("input.png")?.decode()?; let img = ImageReader::open("input.png")?.decode()?;
if is_webp { if is_webp {