-
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
0 parents
commit de456aa
Showing
13 changed files
with
530 additions
and
0 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,21 @@ | ||
name: Build | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
branches: ["main"] | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build | ||
run: cargo build --verbose | ||
- name: Run tests | ||
run: cargo test --verbose |
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 @@ | ||
/target |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "gravatar_api" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
sha2 = "0.9.1" | ||
url = "2" |
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,19 @@ | ||
# Gravatar API Client for Rust | ||
|
||
## Example Usage | ||
|
||
```rust | ||
use gravatar_api::avatars; | ||
|
||
fn main() { | ||
println!( | ||
"{}", | ||
avatars::Avatar::builder("[email protected]") | ||
.size(512) | ||
.default(avatars::Default::RoboHash) | ||
.rating(avatars::Rating::G) | ||
.build() | ||
.image_url() | ||
); | ||
} | ||
`` |
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,33 @@ | ||
/// The default image to display if the user's email does not have a Gravatar. | ||
/// | ||
/// See <https://en.gravatar.com/site/implement/images/#default-image>. | ||
#[derive(Clone, Debug)] | ||
pub enum Default { | ||
/// The URL of an image file to display as the default. | ||
ImageUrl(String), | ||
|
||
/// Instead of loading an image, the Gravatar URL will return an HTTP 404 (File Not Found) | ||
/// response if the email is not found. | ||
Http404, | ||
|
||
/// A transparent PNG image. | ||
Blank, | ||
|
||
/// A simple, cartoon-style silhouetted outline of a person that does not vary by email hash. | ||
MysteryPerson, | ||
|
||
/// A geometric pattern based on the email hash. | ||
Identicon, | ||
|
||
/// A "monster" with different colors, faces, etc. that are generated by the email hash. | ||
MonsterId, | ||
|
||
/// A face with different features and backgrounds, generated by the email hash. | ||
Wavatar, | ||
|
||
/// An 8-bit arcade-style pixelated face that is generated by the email hash. | ||
Retro, | ||
|
||
/// A generated robot with different colors, faces, etc. | ||
RoboHash, | ||
} |
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,23 @@ | ||
/// The maximum rating level for which Gravatar will show the user's image instead of the specified | ||
/// default. | ||
/// | ||
/// See <https://en.gravatar.com/site/implement/images/#rating>. | ||
#[derive(Clone, Debug)] | ||
pub enum Rating { | ||
/// Show "G"-rated images only, | ||
/// suitable for display on all websites with any audience type. | ||
G, | ||
|
||
/// Show "PG"-rated images or lower only, | ||
/// may contain rude gestures, provocatively dressed individuals, the lesser swear words, | ||
/// or mild violence. | ||
Pg, | ||
|
||
/// Show "R"-rated images or lower only, | ||
/// may contain such things as harsh profanity, intense violence, nudity, or hard drug use. | ||
R, | ||
|
||
/// Show all images, up to and including "X"-rated ones, | ||
/// may contain sexual imagery or extremely disturbing violence. | ||
X, | ||
} |
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,76 @@ | ||
use std::fmt; | ||
use url; | ||
|
||
/// The default image to display if the user's email does not have a Gravatar. | ||
/// | ||
/// See <https://en.gravatar.com/site/implement/images/#default-image>. | ||
#[derive(Clone, Debug)] | ||
pub enum Default { | ||
/// The URL of an image file to display as the default. | ||
ImageUrl(String), | ||
|
||
/// Instead of loading an image, the Gravatar URL will return an HTTP 404 (File Not Found) | ||
/// response if the email is not found. | ||
Http404, | ||
|
||
/// A transparent PNG image. | ||
Blank, | ||
|
||
/// A simple, cartoon-style silhouetted outline of a person that does not vary by email hash. | ||
MysteryPerson, | ||
|
||
/// A geometric pattern based on the email hash. | ||
Identicon, | ||
|
||
/// A "monster" with different colors, faces, etc. that are generated by the email hash. | ||
MonsterId, | ||
|
||
/// A face with different features and backgrounds, generated by the email hash. | ||
Wavatar, | ||
|
||
/// An 8-bit arcade-style pixelated face that is generated by the email hash. | ||
Retro, | ||
|
||
/// A generated robot with different colors, faces, etc. | ||
RoboHash, | ||
} | ||
|
||
impl std::fmt::Display for Default { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let val = match self { | ||
Default::Http404 => "404", | ||
Default::MysteryPerson => "mp", | ||
Default::Identicon => "identicon", | ||
Default::MonsterId => "monsterid", | ||
Default::Wavatar => "wavatar", | ||
Default::Retro => "retro", | ||
Default::RoboHash => "robohash", | ||
Default::Blank => "blank", | ||
Default::ImageUrl(ref u) => { | ||
&url::form_urlencoded::byte_serialize(u.as_bytes()).collect::<String>() | ||
} | ||
}; | ||
f.write_str(val) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_to_string() { | ||
assert_eq!(Default::Http404.to_string(), "404"); | ||
assert_eq!(Default::MysteryPerson.to_string(), "mp"); | ||
assert_eq!(Default::Identicon.to_string(), "identicon"); | ||
assert_eq!(Default::MonsterId.to_string(), "monsterid"); | ||
assert_eq!(Default::Wavatar.to_string(), "wavatar"); | ||
assert_eq!(Default::Retro.to_string(), "retro"); | ||
assert_eq!(Default::RoboHash.to_string(), "robohash"); | ||
assert_eq!(Default::Blank.to_string(), "blank"); | ||
assert_eq!( | ||
Default::ImageUrl("[email protected]".to_string()).to_string(), | ||
"anonymous%40example.com" | ||
); | ||
} | ||
} |
Oops, something went wrong.