pub struct CrossrefBuilder { /* private fields */ }Expand description
A CrossrefBuilder can be used to create Crossref with additional config.
§Example
use crossref_client::Crossref;
let client = Crossref::builder()
.polite("polite@example.com")
.token("your token")
.build()?;Every setter accepts Option, so options that are themselves optional –
a CLI flag, a config field – can be passed straight through:
let client = Crossref::builder().polite(email.as_deref()).build()?;Implementations§
Source§impl CrossrefBuilder
impl CrossrefBuilder
Sourcepub fn new() -> CrossrefBuilder
pub fn new() -> CrossrefBuilder
Constructs a new CrossrefBuilder.
This is the same as Crossref::builder().
Sourcepub fn polite<'a>(self, email: impl Into<Option<&'a str>>) -> Self
pub fn polite<'a>(self, email: impl Into<Option<&'a str>>) -> Self
Be polite: identify yourself by email and get routed to crossref’s polite pool.
Sends a User-Agent in the shape crossref asks for, e.g.
crossref-client/0.2.0 (https://github.com/…; mailto:you@example.com).
Anonymous requests share a rate-limited pool and are the usual cause of
429 responses; check where you landed with
Crossref::api_pool.
Use CrossrefBuilder::user_agent instead if you want to send your own
application’s name; include mailto:<email> in it to stay in the pool.
Sourcepub fn user_agent<'a>(self, user_agent: impl Into<Option<&'a str>>) -> Self
pub fn user_agent<'a>(self, user_agent: impl Into<Option<&'a str>>) -> Self
set the user agent directly
Sourcepub fn token<'a>(self, token: impl Into<Option<&'a str>>) -> Self
pub fn token<'a>(self, token: impl Into<Option<&'a str>>) -> Self
set a crossref plus service API token
Sourcepub fn base_url<'a>(self, base_url: impl Into<Option<&'a str>>) -> Self
pub fn base_url<'a>(self, base_url: impl Into<Option<&'a str>>) -> Self
Send requests somewhere other than https://api.crossref.org.
Routes are appended verbatim, so the url must not end in a /. Mainly
useful for pointing the client at a mock or a proxy in tests.
Sourcepub fn rate_limit(self, rate_limit: impl Into<Option<RateLimit>>) -> Self
pub fn rate_limit(self, rate_limit: impl Into<Option<RateLimit>>) -> Self
The request budget to assume until crossref reports its own.
Defaults to RateLimit::CONSERVATIVE. Crossref sends the real budget
on every response and the client follows it from then on, so this only
paces the first few requests.
Sourcepub fn max_retries(self, max_retries: impl Into<Option<u32>>) -> Self
pub fn max_retries(self, max_retries: impl Into<Option<u32>>) -> Self
How many times a 429 is retried before giving up with
Error::RateLimited. Defaults to 3; 0 disables retrying.