Add an option to include the JPG file extension.
This commit is contained in:
parent
c1a5b2d7dc
commit
2ad90c785c
|
@ -27,6 +27,7 @@
|
||||||
pub struct Generator {
|
pub struct Generator {
|
||||||
pub base_url: String,
|
pub base_url: String,
|
||||||
pub image_size: Option<i32>,
|
pub image_size: Option<i32>,
|
||||||
|
pub include_file_extension: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Generator {
|
impl Default for Generator {
|
||||||
|
@ -34,6 +35,7 @@ impl Default for Generator {
|
||||||
Self {
|
Self {
|
||||||
base_url: "www.gravatar.com".to_string(),
|
base_url: "www.gravatar.com".to_string(),
|
||||||
image_size: None,
|
image_size: None,
|
||||||
|
include_file_extension: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +67,16 @@ impl Generator {
|
||||||
let base_url = &self.base_url;
|
let base_url = &self.base_url;
|
||||||
let hash = Self::hash_email(email);
|
let hash = Self::hash_email(email);
|
||||||
let query_parameters = self.query_parameters();
|
let query_parameters = self.query_parameters();
|
||||||
format!("https://{base_url}/avatar/{hash}{query_parameters}")
|
|
||||||
|
let file_extension = if self.include_file_extension {
|
||||||
|
".jpg"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
};
|
||||||
|
|
||||||
|
format!(
|
||||||
|
"https://{base_url}/avatar/{hash}{file_extension}{query_parameters}"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns all configurable options as a query parameter string.
|
/// Returns all configurable options as a query parameter string.
|
||||||
|
@ -116,4 +127,21 @@ impl Generator {
|
||||||
..self
|
..self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Configures the Generator to add `.jpg` to the end of the hash.
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// use gravatar_rs::Generator;
|
||||||
|
///
|
||||||
|
/// Generator::default().set_include_file_extension(true);
|
||||||
|
/// ```
|
||||||
|
pub fn set_include_file_extension(
|
||||||
|
self,
|
||||||
|
include_file_extension: bool,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
include_file_extension,
|
||||||
|
..self
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue