From 6336937ce5d494d1133e0e83196674b4997885a7 Mon Sep 17 00:00:00 2001 From: Ben Rometsch Date: Wed, 28 Feb 2024 13:59:40 +0000 Subject: [PATCH] chore/remove examples --- example/Cargo.toml | 19 ------- example/Rocket.toml | 3 - example/readme.md | 21 ------- example/src/main.rs | 95 -------------------------------- example/templates/home.html.tera | 25 --------- 5 files changed, 163 deletions(-) delete mode 100644 example/Cargo.toml delete mode 100644 example/Rocket.toml delete mode 100644 example/readme.md delete mode 100644 example/src/main.rs delete mode 100644 example/templates/home.html.tera diff --git a/example/Cargo.toml b/example/Cargo.toml deleted file mode 100644 index f342028..0000000 --- a/example/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "example" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[net] -git-fetch-with-cli = true # use the `git` executable for git operations - -[dependencies] -rocket = "0.4.10" -serde = "1.0" -serde_derive = "1.0" -serde_json = "1.0" -rocket_contrib = {version = "0.4.10", features=["tera_templates"]} -flagsmith = {path="../"} - -flagsmith-flag-engine = "0.1.0" - diff --git a/example/Rocket.toml b/example/Rocket.toml deleted file mode 100644 index b841e7b..0000000 --- a/example/Rocket.toml +++ /dev/null @@ -1,3 +0,0 @@ -[global] -port = 5000 -workers = 1 diff --git a/example/readme.md b/example/readme.md deleted file mode 100644 index 700f71f..0000000 --- a/example/readme.md +++ /dev/null @@ -1,21 +0,0 @@ -# Flagsmith Basic Rust Example - -This directory contains a basic Rocket application which utilises Flagsmith. To run the example application, you'll -need to go through the following steps: - -1. Create an account, organisation and project on [Flagsmith](https://flagsmith.com) -2. Create a feature in the project called "secret_button" -3. Give the feature a value using the json editor as follows: - -```json -{"colour": "#ababab"} -``` - -4. Set the environment variable `FLAGSMITH_ENVIRONMENT_KEY` with the environment key of one of the environments -in flagsmith (This can be found on the 'settings' page accessed from the menu on the left under the chosen environment.) -5. Run the app using `cargo run` -6. Browse to http://localhost:5000 - -Now you can play around with the 'secret_button' feature in flagsmith, turn it on to show it and edit the colour in the -json value to edit the colour of the button. You can also identify as a given user and then update the settings for the -secret button feature for that user in the flagsmith interface to see the affect that has too. diff --git a/example/src/main.rs b/example/src/main.rs deleted file mode 100644 index 8fff4f7..0000000 --- a/example/src/main.rs +++ /dev/null @@ -1,95 +0,0 @@ -#![feature(proc_macro_hygiene, decl_macro)] - -#[macro_use] -extern crate rocket; -#[macro_use] -extern crate serde_derive; -extern crate flagsmith; -extern crate rocket_contrib; -extern crate serde_json; - -use std::env; - -use rocket_contrib::templates::Template; - -use flagsmith::{Flag, Flagsmith, FlagsmithOptions}; -use flagsmith_flag_engine::identities::Trait; -use flagsmith_flag_engine::types::{FlagsmithValue, FlagsmithValueType}; - -#[derive(Serialize)] -struct TemplateContext { - show_button: bool, - button_colour: String, - identifier: String, -} -fn default_flag_handler(feature_name: &str) -> Flag { - let mut flag: Flag = Default::default(); - if feature_name == "secret_button" { - flag.value.value_type = FlagsmithValueType::String; - flag.value.value = serde_json::json!({"colour": "#b8b8b8"}).to_string(); - } - return flag; -} - -#[get("/?&&")] -fn home( - identifier: Option, - trait_key: Option, - trait_value: Option, -) -> Template { - let options = FlagsmithOptions { - default_flag_handler: Some(default_flag_handler), - enable_local_evaluation: true, - ..Default::default() - }; - - let flagsmith = Flagsmith::new( - env::var("FLAGSMITH_ENVIRONMENT_KEY") - .expect("FLAGSMITH_ENVIRONMENT_KEY not found in environment"), - options, - ); - let flags; - if identifier.is_some() { - let traits = match trait_key { - Some(trait_key) if trait_key != "".to_string() => Some(vec![Trait { - trait_key, - trait_value: FlagsmithValue { - value: trait_value.unwrap_or("".to_string()), - value_type: FlagsmithValueType::None, - }, - }]), - Some(_) => None, - None => None, - }; - flags = flagsmith - .get_identity_flags(identifier.as_ref().unwrap(), traits) - .unwrap(); - } else { - // Get the default flags for the current environment - flags = flagsmith.get_environment_flags().unwrap(); - } - - let show_button = flags.is_feature_enabled("secret_button").unwrap(); - let button_data = flags.get_feature_value_as_string("secret_button").unwrap(); - - let button_json: serde_json::Value = serde_json::from_str(&button_data).unwrap(); - let button_colour = button_json["colour"].as_str().unwrap().to_string(); - - let context = TemplateContext { - show_button, - button_colour, - identifier: identifier.unwrap_or("World".to_string()), - }; - - Template::render("home", &context) -} - -fn rocket() -> rocket::Rocket { - rocket::ignite() - .mount("/", routes![home]) - .attach(Template::fairing()) -} - -fn main() { - rocket().launch(); -} diff --git a/example/templates/home.html.tera b/example/templates/home.html.tera deleted file mode 100644 index 669d6a6..0000000 --- a/example/templates/home.html.tera +++ /dev/null @@ -1,25 +0,0 @@ - - - - -Flagsmith Example - -

Hello, {{ identifier }}.

- {% if show_button %} - - {% endif %} - -

- -
-

Identify as a user

-
- -

... with an optional user trait

-
-

- - -
- -