-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Benjamin P. Jung <[email protected]>
- Loading branch information
Showing
7 changed files
with
51 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [0.3.0] - 2024-09-01 | ||
|
||
### Changed | ||
|
||
- Unnecessary 'public' package has been removed. | ||
|
||
## [0.2.0] - 2024-08-29 | ||
|
||
### Added | ||
|
||
- New functions to load avatar images synchronously and asynchronously have been added. | ||
|
||
## [0.1.0] - 2024-08-29 | ||
|
||
Initial release. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
[package] | ||
name = "gravatar_api" | ||
version = "0.2.0" | ||
version = "0.3.0" | ||
authors = ["Benjamin P. Jung <[email protected]>"] | ||
description = "Access to the public Gravatar API" | ||
edition = "2021" | ||
license = "MIT" | ||
repository = "https://github.com/cathive/rust-gravatar-api" | ||
repository = "https://github.com/cathive/gravatar-api-rs" | ||
|
||
[dependencies] | ||
bytes = "1.7" | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,12 @@ | |
use reqwest; | ||
use url::Url; | ||
|
||
use crate::_common::email_hash; | ||
use crate::common::email_hash; | ||
|
||
mod default; | ||
mod rating; | ||
|
||
pub use default::Default as _Default; | ||
pub use default::Default; | ||
pub use rating::Rating; | ||
|
||
const BASE_URL: &str = "https://www.gravatar.com/"; | ||
|
@@ -18,7 +18,7 @@ const BASE_URL: &str = "https://www.gravatar.com/"; | |
pub struct Avatar { | ||
email: String, | ||
pub size: Option<u16>, | ||
pub default: Option<_Default>, | ||
pub default: Option<Default>, | ||
pub force_default: Option<bool>, | ||
pub rating: Option<Rating>, | ||
} | ||
|
@@ -28,6 +28,7 @@ impl Avatar { | |
AvatarBuilder::new(email) | ||
} | ||
|
||
/// Returns the URL of the Gravatar image. | ||
pub fn image_url(self: &Self) -> Url { | ||
let mut str = format!("{}avatar/{}", BASE_URL, email_hash(&self.email)); | ||
if let Some(size) = self.size { | ||
|
@@ -63,11 +64,11 @@ impl Avatar { | |
} | ||
|
||
// Builder for Avatar instances. | ||
#[derive(Default)] | ||
#[derive(core::default::Default)] | ||
pub struct AvatarBuilder { | ||
email: String, | ||
size: Option<u16>, | ||
default: Option<_Default>, | ||
default: Option<Default>, | ||
force_default: Option<bool>, | ||
rating: Option<Rating>, | ||
} | ||
|
@@ -76,7 +77,7 @@ impl AvatarBuilder { | |
pub fn new(email: &str) -> AvatarBuilder { | ||
AvatarBuilder { | ||
email: email.to_string(), | ||
..Default::default() | ||
..core::default::Default::default() | ||
} | ||
} | ||
|
||
|
@@ -98,7 +99,9 @@ impl AvatarBuilder { | |
self | ||
} | ||
|
||
pub fn default(mut self, default: _Default) -> AvatarBuilder { | ||
/// Sets the default / fallback image to be used if no Gravatar image | ||
/// for the given email address can be found. | ||
pub fn default(mut self, default: Default) -> AvatarBuilder { | ||
self.default = Some(default); | ||
self | ||
} | ||
|
@@ -110,6 +113,7 @@ impl AvatarBuilder { | |
self | ||
} | ||
|
||
/// Builds the Avatar instance. | ||
pub fn build(self) -> Avatar { | ||
Avatar { | ||
email: self.email, | ||
|
@@ -120,3 +124,16 @@ impl AvatarBuilder { | |
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_avatar_builder() { | ||
let email = "[email protected]"; | ||
|
||
let builder = Avatar::builder(email); | ||
assert_eq!(email, builder.build().email); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters