From cb01416a1cb482533956a0a49bcdf6acf4934c39 Mon Sep 17 00:00:00 2001 From: Bauke Date: Sat, 2 Apr 2022 21:44:13 +0200 Subject: [PATCH] Add the force default parameter. --- source/lib.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/source/lib.rs b/source/lib.rs index 2499fdd..4533fda 100644 --- a/source/lib.rs +++ b/source/lib.rs @@ -27,6 +27,7 @@ pub struct Generator { pub base_url: String, pub default_image: Option, + pub force_default: bool, pub image_size: Option, pub include_file_extension: bool, } @@ -36,6 +37,7 @@ impl Default for Generator { Self { base_url: "www.gravatar.com".to_string(), default_image: None, + force_default: false, image_size: None, include_file_extension: false, } @@ -93,6 +95,10 @@ impl Generator { query_parameters.push(format!("d={}", encode(default_image))); } + if self.force_default { + query_parameters.push("f=y".to_string()); + } + if let Some(image_size) = self.image_size { query_parameters.push(format!("s={}", encode(image_size))); } @@ -139,6 +145,21 @@ impl Generator { } } + /// When set to true, the Generator will always add `f=y` to the URL. Making + /// Gravatar always return the default image. + /// + /// ```rust + /// use gravatar_rs::Generator; + /// + /// Generator::default().set_force_default(true); + /// ``` + pub fn set_force_default(self, force_default: bool) -> Self { + Self { + force_default, + ..self + } + } + /// Configures the Generator to include a `s=` in the URL. /// /// ```rust