1
Fork 0

Add the rating parameter.

This commit is contained in:
Bauke 2022-04-02 21:53:33 +02:00
parent cb01416a1c
commit 48434fe8d3
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 25 additions and 0 deletions

View File

@ -30,6 +30,7 @@ pub struct Generator {
pub force_default: bool, pub force_default: bool,
pub image_size: Option<i32>, pub image_size: Option<i32>,
pub include_file_extension: bool, pub include_file_extension: bool,
pub rating: Option<String>,
} }
impl Default for Generator { impl Default for Generator {
@ -40,6 +41,7 @@ impl Default for Generator {
force_default: false, force_default: false,
image_size: None, image_size: None,
include_file_extension: false, include_file_extension: false,
rating: None,
} }
} }
} }
@ -103,6 +105,10 @@ impl Generator {
query_parameters.push(format!("s={}", encode(image_size))); query_parameters.push(format!("s={}", encode(image_size)));
} }
if let Some(rating) = &self.rating {
query_parameters.push(format!("r={}", encode(rating)));
}
if query_parameters.is_empty() { if query_parameters.is_empty() {
String::new() String::new()
} else { } else {
@ -191,4 +197,23 @@ impl Generator {
..self ..self
} }
} }
/// Configures the Generator to include `r=<rating>` in the URL.
///
/// See the [Gravatar documentation] for all the possible ratings.
///
/// [Gravatar documentation]: https://gravatar.com/site/implement/images/#rating
///
/// ```rust
/// use gravatar_rs::Generator;
///
/// // Allow G and PG rated images.
/// Generator::default().set_rating("pg");
/// ```
pub fn set_rating(self, rating: &str) -> Self {
Self {
rating: Some(rating.to_string()),
..self
}
}
} }