1
Fork 0

Add the force default parameter.

This commit is contained in:
Bauke 2022-04-02 21:44:13 +02:00
parent a5496fc1f2
commit cb01416a1c
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 21 additions and 0 deletions

View File

@ -27,6 +27,7 @@
pub struct Generator { pub struct Generator {
pub base_url: String, pub base_url: String,
pub default_image: Option<String>, pub default_image: Option<String>,
pub force_default: bool,
pub image_size: Option<i32>, pub image_size: Option<i32>,
pub include_file_extension: bool, pub include_file_extension: bool,
} }
@ -36,6 +37,7 @@ impl Default for Generator {
Self { Self {
base_url: "www.gravatar.com".to_string(), base_url: "www.gravatar.com".to_string(),
default_image: None, default_image: None,
force_default: false,
image_size: None, image_size: None,
include_file_extension: false, include_file_extension: false,
} }
@ -93,6 +95,10 @@ impl Generator {
query_parameters.push(format!("d={}", encode(default_image))); 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 { if let Some(image_size) = self.image_size {
query_parameters.push(format!("s={}", encode(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=<image size>` in the URL. /// Configures the Generator to include a `s=<image size>` in the URL.
/// ///
/// ```rust /// ```rust