pub struct Crossref {
pub base_url: String,
pub http_client: Client,
}Expand description
Struct for Crossref search API methods
Fields§
§base_url: Stringuse another base url than api.crossref.org
http_client: Clientthe reqwest client that handles the requests
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 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::query_works]
§Example
use crossref::{Crossref, WorksQuery, WorksFilter, FieldQuery};
let client = Crossref::builder().build()?;
let query = WorksQuery::new("Machine Learning")
.filter(WorksFilter::HasOrcid)
.order(crossref::Order::Asc)
.field_query(FieldQuery::author("Some Author"))
.sort(crossref::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 async fn deep_page<T: Into<WorkListQuery>>(&self, query: T) -> Vec<WorkList>
pub async fn deep_page<T: Into<WorkListQuery>>(&self, query: T) -> Vec<WorkList>
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::{Crossref, WorksQuery, Work};
let client = Crossref::builder().build()?;
let all_works: Vec<Work> = client.deep_page(WorksQuery::new("Machine Learning")).await.into_iter().flat_map(|x|x.items).collect();
§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::{Crossref, Funders, WorksQuery, Work, WorkList};
let client = Crossref::builder().build()?;
let all_funder_work_list: Vec<WorkList> = client.deep_page(WorksQuery::default().into_combined_query::<Funders>("funder id")).await;
§Example
Iterate over all Work items of a specific funder directly.
use crossref::{Crossref, Funders, WorksQuery, Work, WorkList};
let client = Crossref::builder().build()?;
let all_works: Vec<Work> = client.deep_page(WorksQuery::default()
.into_combined_query::<Funders>("funder id"))
.await
.into_iter()
.flat_map(|x| x.items)
.collect();
§Example
Alternatively deep page without an iterator by handling the cursor directly
use crossref::{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 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 type_(&self, id: &Type) -> Result<CrossrefType>
pub async fn type_(&self, id: &Type) -> Result<CrossrefType>
Return the Type for the id