Skip to content

Commit

Permalink
Improve tests and documentation.
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin P. Jung <[email protected]>
  • Loading branch information
headcr4sh committed Sep 1, 2024
1 parent e5e7c8a commit 3e2dcd2
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 76 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
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.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
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"
Expand Down
33 changes: 0 additions & 33 deletions src/avatar/default.rs

This file was deleted.

23 changes: 0 additions & 23 deletions src/avatar/rating.rs

This file was deleted.

31 changes: 24 additions & 7 deletions src/avatars/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
Expand All @@ -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>,
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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>,
}
Expand All @@ -76,7 +77,7 @@ impl AvatarBuilder {
pub fn new(email: &str) -> AvatarBuilder {
AvatarBuilder {
email: email.to_string(),
..Default::default()
..core::default::Default::default()
}
}

Expand All @@ -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
}
Expand All @@ -110,6 +113,7 @@ impl AvatarBuilder {
self
}

/// Builds the Avatar instance.
pub fn build(self) -> Avatar {
Avatar {
email: self.email,
Expand All @@ -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);
}
}
12 changes: 2 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,5 @@ extern crate reqwest;
extern crate sha2;
extern crate url;

#[path = "avatars/mod.rs"]
mod _avatars;

#[path = "common/mod.rs"]
mod _common;

pub use avatars::*;
pub mod avatars {
pub use crate::_avatars::{Avatar, AvatarBuilder, Rating, _Default as Default};
}
pub mod avatars;
mod common;

0 comments on commit 3e2dcd2

Please sign in to comment.