pub struct Crossref { /* private fields */ }Expand description
Struct for Crossref search API methods
Cloning is cheap and shares the connection pool and the rate limiter, so
concurrent callers should clone one client rather than build several – see
Crossref::rate_limit.
Implementations§
Source§impl Crossref
impl Crossref
Sourcepub fn builder() -> CrossrefBuilder
pub fn builder() -> CrossrefBuilder
Constructs a new CrossrefBuilder.
This is the same as Crossref::builder().
Sourcepub fn base_url(&self) -> &str
pub fn base_url(&self) -> &str
The url every route is appended to, https://api.crossref.org unless
CrossrefBuilder::base_url said otherwise.
Sourcepub fn rate_limit(&self) -> RateLimit
pub fn rate_limit(&self) -> RateLimit
The request budget crossref last reported for this client.
Crossref sends the budget on every response and the client paces itself
against it, so before the first request this is the assumed
RateLimit::CONSERVATIVE (or whatever CrossrefBuilder::rate_limit
was given) and afterwards it is what crossref actually granted.
Sourcepub fn api_pool(&self) -> Option<String>
pub fn api_pool(&self) -> Option<String>
The pool crossref sorted the last request into, from x-api-pool.
polite if CrossrefBuilder::polite worked, plus for a Plus token,
otherwise public. None before the first request.
Sourcepub async fn funder_works(&self, ident: WorksIdentQuery) -> Result<WorkList>
pub async fn funder_works(&self, ident: WorksIdentQuery) -> Result<WorkList>
Return one page of the components’s Work that match the query
Sourcepub async fn member_works(&self, ident: WorksIdentQuery) -> Result<WorkList>
pub async fn member_works(&self, ident: WorksIdentQuery) -> Result<WorkList>
Return one page of the components’s Work that match the query
Sourcepub async fn type_works(&self, ident: WorksIdentQuery) -> Result<WorkList>
pub async fn type_works(&self, ident: WorksIdentQuery) -> Result<WorkList>
Return one page of the components’s Work that match the query
Sourcepub async fn journal_works(&self, ident: WorksIdentQuery) -> Result<WorkList>
pub async fn journal_works(&self, ident: WorksIdentQuery) -> Result<WorkList>
Return one page of the components’s Work that match the query
Sourcepub async fn prefix_works(&self, ident: WorksIdentQuery) -> Result<WorkList>
pub async fn prefix_works(&self, ident: WorksIdentQuery) -> Result<WorkList>
Return one page of the components’s Work that match the query
Sourcepub async fn works<T: Into<WorkListQuery>>(&self, query: T) -> Result<WorkList>
pub async fn works<T: Into<WorkListQuery>>(&self, query: T) -> Result<WorkList>
Return the Work items that match a certain query.
To search only by query terms use the convenience query method Crossref::works
§Example
use crossref_client::{Crossref, WorksQuery, WorksFilter, FieldQuery};
let client = Crossref::builder().build()?;
let query = WorksQuery::new("Machine Learning")
.filter(WorksFilter::HasOrcid)
.order(crossref_client::Order::Asc)
.field_query(FieldQuery::author("Some Author"))
.sort(crossref_client::Sort::Score);
let works = client.works(query).await?;
§Errors
This method fails if the works element expands to a bad route ResourceNotFound
Fails if the response body doesn’t have message field MissingMessage.
Fails if anything else than a WorkList is returned as message UnexpectedItem
Sourcepub async fn work(&self, doi: &str) -> Result<Work>
pub async fn work(&self, doi: &str) -> Result<Work>
Return the Work that is identified by the doi.
§Errors
This method fails if the doi could not identified ResourceNotFound
Sourcepub fn deep_page<T: Into<WorkListQuery>>(
&self,
query: T,
) -> WorkListIterator<'_>
pub fn deep_page<T: Into<WorkListQuery>>( &self, query: T, ) -> WorkListIterator<'_>
Deep paging results
Deep paging is supported for all queries, that return a list of Work, WorkList.
This function returns a new iterator over pages of Work, which is returned as bulk of items as a WorkList by crossref.
Usually a single page WorkList contains 20 items.
§Example
Iterate over all Works linked to search term Machine Learning
use crossref_client::{AsyncIterator, Crossref, WorksQuery, Work};
let client = Crossref::builder().build()?;
let mut pages = client.deep_page(WorksQuery::new("Machine Learning"));
let mut all_works: Vec<Work> = Vec::new();
while let Some(page) = pages.next().await {
let page = page?;
all_works.extend(page.items);
}
§Example
Iterate over all the pages (WorkList) of the funder with id funder id by using a combined query.
A single WorkList usually holds 20 Work items.
use crossref_client::{AsyncIterator, Crossref, Funders, WorksQuery, Work, WorkList};
let client = Crossref::builder().build()?;
let mut pages = client.deep_page(WorksQuery::default().into_combined_query::<Funders>("funder id"));
let mut all_funder_work_list: Vec<WorkList> = Vec::new();
while let Some(page) = pages.next().await {
let page = page?;
all_funder_work_list.push(page);
}
§Example
Iterate over all Work items of a specfic funder directly.
use crossref_client::{AsyncIterator, Crossref, Funders, WorksQuery, Work, WorkList};
let client = Crossref::builder().build()?;
let mut works = client.deep_page(WorksQuery::default()
.into_combined_query::<Funders>("funder id"))
.into_work_iter();
let mut all_works: Vec<Work> = Vec::new();
while let Some(work) = works.next().await {
let work = work?;
all_works.push(work);
}
§Example
Alternatively deep page without an iterator by handling the cursor directly
use crossref_client::{Crossref, WorksQuery, WorksFilter};
let client = Crossref::builder().build()?;
// request a next-cursor first
let query = WorksQuery::new("Machine Learning")
.new_cursor();
let works = client.works(query.clone()).await?;
// this continues from where this first response stopped
// if no more work items are available then a empty list will be returned
let deep_works = client.works(
query.next_cursor(&works.next_cursor.unwrap())
).await?;Sourcepub async fn transform(&self, doi: &str, format: &CnFormat) -> Result<String>
pub async fn transform(&self, doi: &str, format: &CnFormat) -> Result<String>
Re-serialize the work identified by doi into another format.
Crossref renders the registered metadata itself, so this never goes
through Work and the body is returned verbatim – BibTeX, RIS, RDF
or a citation formatted in a CSL style.
§Example
use crossref_client::{CnFormat, Crossref};
let bibtex = client
.transform("10.1037/0003-066X.59.1.29", &CnFormat::BibTex)
.await?;
let citation = client
.transform("10.1037/0003-066X.59.1.29", &CnFormat::bibliography("apa"))
.await?;§Errors
Fails with Error::ValidationFailure if crossref cannot serve the
format for this DOI – an unknown CSL style is the usual cause.
Sourcepub async fn styles(&self) -> Result<StyleList>
pub async fn styles(&self) -> Result<StyleList>
Return the CSL styles crossref can render
a citation in, for CnFormat::Bibliography.
Roughly 2 900 of them, in one response.
Sourcepub async fn work_agency(&self, doi: &str) -> Result<WorkAgency>
pub async fn work_agency(&self, doi: &str) -> Result<WorkAgency>
Return the Agency that registers the Work identified by the doi.
§Errors
This method fails if the doi could not identified ResourceNotFound
Sourcepub async fn funders(&self, funders: FundersQuery) -> Result<FunderList>
pub async fn funders(&self, funders: FundersQuery) -> Result<FunderList>
Return the matching Funders items.
Sourcepub async fn members(&self, members: MembersQuery) -> Result<MemberList>
pub async fn members(&self, members: MembersQuery) -> Result<MemberList>
Return the matching Members items.
Sourcepub async fn journals(&self, journals: JournalsQuery) -> Result<JournalList>
pub async fn journals(&self, journals: JournalsQuery) -> Result<JournalList>
Return the matching Journal items.
§Example
use crossref_client::{Crossref, JournalsQuery, ResultControl};
let journals = client
.journals(JournalsQuery::new("Economic Geography").result_control(ResultControl::Rows(10)))
.await?;Sourcepub async fn licenses(&self, licenses: LicensesQuery) -> Result<LicenseList>
pub async fn licenses(&self, licenses: LicensesQuery) -> Result<LicenseList>
Return the licenses works in the crossref metadata are published under, each with the number of works that carry it.
§Example
use crossref_client::{Crossref, LicensesQuery, ResultControl};
let licenses = client
.licenses(LicensesQuery::new("creative commons").result_control(ResultControl::Rows(10)))
.await?;
for license in &licenses.items {
println!("{:>8} {}", license.work_count, license.url);
}Sourcepub async fn type_(&self, id: &Type) -> Result<CrossrefType>
pub async fn type_(&self, id: &Type) -> Result<CrossrefType>
Return the Type for the id