Crates.io | megamind |
lib.rs | megamind |
version | 0.13.0 |
source | src |
created_at | 2023-10-08 00:43:27.127514 |
updated_at | 2024-11-09 05:05:39.95667 |
description | A library for interacting with the Genius API. |
homepage | |
repository | https://github.com/bobertoyin/megamind |
max_upload_size | |
id | 996733 |
size | 63,593 |
megamind
A library for interacting with the Genius API.
This library revolves around providing two things:
Idiomatic Rust structures (a.k.a "data models" or whatever else you like to call them) that represent API endpoint data.
A simple HTTP client for interacting with the API.
megamind = "*"
# enable the "catchall" feature
megamind = { version = "*", features = ["catchall"] }
use std::{env::var, error::Error};
use megamind::{ClientBuilder, models::Response};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let client = ClientBuilder::new().auth_token(var("GENIUS_TOKEN")?).build()?;
let response = client.account().await?;
if let Response::Success { meta, response } = response {
assert_eq!(meta.status, 200);
println!("Howdy, {}!", response.account.user.core.name);
}
Ok(())
}
These are endpoints that can be found on docs.genius.com and accessed anytime.
These are endpoints that cannot be found publicly, but can still be accessed.
Do not rely on always having access to these endpoints, as Genius likely has the agency to revoke access whenever they please.
These are endpoints that clearly existed at some point (likely found in some nested data model), but is not accessible.
There are a few general areas in which the library can be improved:
enum
s instead of String
s, but they lack the documentation necessary to be confidently converted()
or Vec<()>
because no endpoints have been found to hold data in themresponse.account.user.core.name
isn't as intuitive as response.account.name
)Eq
, Hash
, etc.)Reqwest
isn't always helpfulIssues and pull requests are welcome, but please be respectful. It's also generally a good idea to include an endpoint with values if the issue or pull request aims to resolve an issue with parsing a particular endpoint response, or a simple explanation of how the issue or pull request improves efforts in documentation, ergonomics, and/or testing.
What makes this library different from libraries like
genius_rs
andgenius_rust
?
The big difference is that genius_rs
and genius_rust
both make use of large, general models for multiple endpoints, resulting in many fields being Option<...>
. This could be avoided by simply omitting the field in certain endpoints and including it in others. To achieve this, megamind
makes use of highly nested structures that are flattened during serialization and deserialization. This means fewer unwrap
s for you, the API consumer!
What is the
catchall
feature, and why is it a thing?
catchall
enables an extra field on most of the data models that catches all missing JSON fields. This is useful for two reasons:
It's also unfortunately just a consequence of the web API itself being a bit unwieldy and underdocumented.
Why is the crate called
megamind
?
Genius... Big-Brained Person... Megamind.