Add the force default parameter.
This commit is contained in:
parent
a5496fc1f2
commit
cb01416a1c
|
@ -27,6 +27,7 @@
|
|||
pub struct Generator {
|
||||
pub base_url: String,
|
||||
pub default_image: Option<String>,
|
||||
pub force_default: bool,
|
||||
pub image_size: Option<i32>,
|
||||
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=<image size>` in the URL.
|
||||
///
|
||||
/// ```rust
|
||||
|
|
Loading…
Reference in New Issue