Add the rating parameter.
This commit is contained in:
parent
cb01416a1c
commit
48434fe8d3
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue