Skip to content

Commit 3e2dcd2

Browse files
committed
Improve tests and documentation.
Signed-off-by: Benjamin P. Jung <[email protected]>
1 parent e5e7c8a commit 3e2dcd2

File tree

7 files changed

+51
-76
lines changed

7 files changed

+51
-76
lines changed

CHANGELOG.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [0.3.0] - 2024-09-01
9+
10+
### Changed
11+
12+
- Unnecessary 'public' package has been removed.
13+
14+
## [0.2.0] - 2024-08-29
15+
16+
### Added
17+
18+
- New functions to load avatar images synchronously and asynchronously have been added.
19+
20+
## [0.1.0] - 2024-08-29
21+
22+
Initial release.

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[package]
22
name = "gravatar_api"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
authors = ["Benjamin P. Jung <[email protected]>"]
55
description = "Access to the public Gravatar API"
66
edition = "2021"
77
license = "MIT"
8-
repository = "https://github.com/cathive/rust-gravatar-api"
8+
repository = "https://github.com/cathive/gravatar-api-rs"
99

1010
[dependencies]
1111
bytes = "1.7"

src/avatar/default.rs

-33
This file was deleted.

src/avatar/rating.rs

-23
This file was deleted.

src/avatars/mod.rs

+24-7
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
use reqwest;
44
use url::Url;
55

6-
use crate::_common::email_hash;
6+
use crate::common::email_hash;
77

88
mod default;
99
mod rating;
1010

11-
pub use default::Default as _Default;
11+
pub use default::Default;
1212
pub use rating::Rating;
1313

1414
const BASE_URL: &str = "https://www.gravatar.com/";
@@ -18,7 +18,7 @@ const BASE_URL: &str = "https://www.gravatar.com/";
1818
pub struct Avatar {
1919
email: String,
2020
pub size: Option<u16>,
21-
pub default: Option<_Default>,
21+
pub default: Option<Default>,
2222
pub force_default: Option<bool>,
2323
pub rating: Option<Rating>,
2424
}
@@ -28,6 +28,7 @@ impl Avatar {
2828
AvatarBuilder::new(email)
2929
}
3030

31+
/// Returns the URL of the Gravatar image.
3132
pub fn image_url(self: &Self) -> Url {
3233
let mut str = format!("{}avatar/{}", BASE_URL, email_hash(&self.email));
3334
if let Some(size) = self.size {
@@ -63,11 +64,11 @@ impl Avatar {
6364
}
6465

6566
// Builder for Avatar instances.
66-
#[derive(Default)]
67+
#[derive(core::default::Default)]
6768
pub struct AvatarBuilder {
6869
email: String,
6970
size: Option<u16>,
70-
default: Option<_Default>,
71+
default: Option<Default>,
7172
force_default: Option<bool>,
7273
rating: Option<Rating>,
7374
}
@@ -76,7 +77,7 @@ impl AvatarBuilder {
7677
pub fn new(email: &str) -> AvatarBuilder {
7778
AvatarBuilder {
7879
email: email.to_string(),
79-
..Default::default()
80+
..core::default::Default::default()
8081
}
8182
}
8283

@@ -98,7 +99,9 @@ impl AvatarBuilder {
9899
self
99100
}
100101

101-
pub fn default(mut self, default: _Default) -> AvatarBuilder {
102+
/// Sets the default / fallback image to be used if no Gravatar image
103+
/// for the given email address can be found.
104+
pub fn default(mut self, default: Default) -> AvatarBuilder {
102105
self.default = Some(default);
103106
self
104107
}
@@ -110,6 +113,7 @@ impl AvatarBuilder {
110113
self
111114
}
112115

116+
/// Builds the Avatar instance.
113117
pub fn build(self) -> Avatar {
114118
Avatar {
115119
email: self.email,
@@ -120,3 +124,16 @@ impl AvatarBuilder {
120124
}
121125
}
122126
}
127+
128+
#[cfg(test)]
129+
mod tests {
130+
use super::*;
131+
132+
#[test]
133+
fn test_avatar_builder() {
134+
let email = "[email protected]";
135+
136+
let builder = Avatar::builder(email);
137+
assert_eq!(email, builder.build().email);
138+
}
139+
}

src/lib.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,5 @@ extern crate reqwest;
33
extern crate sha2;
44
extern crate url;
55

6-
#[path = "avatars/mod.rs"]
7-
mod _avatars;
8-
9-
#[path = "common/mod.rs"]
10-
mod _common;
11-
12-
pub use avatars::*;
13-
pub mod avatars {
14-
pub use crate::_avatars::{Avatar, AvatarBuilder, Rating, _Default as Default};
15-
}
6+
pub mod avatars;
7+
mod common;

0 commit comments

Comments
 (0)