Struct Api

Source
pub struct Api { /* private fields */ }
Expand description

Main API struct. API holds your key you acquire from CORE. Lastly it holds a refernce to a blocking Client it uses to execute queries to the CORE API. The Api struct provides a set of methods to interact with a specific API service. It includes methods to search for works, data providers, journals, and outputs based on various queries. The struct uses an API key and an HTTP client for requests, and optionally logs the request target and raw response.

Key methods include:

  • get_output: Get a single Output based on CORE id.
  • get_journal: Get a single journal based on its identifier in CORE
  • discover: Allows you to find links to full texts based on a DOI. The system will search through the CORE data and other external sources to provide you the best match.
  • search_works: Executes a search for research works.
  • search_data_providers: Executes a search for data providers.
  • search_journals: Executes a search for journal titles.
  • search_outputs: Executes a search for work outputs.
  • paged_search: Initiates a paginated search. (SearchQuery builder)
  • log_target: Enables/disables logging of the target URI.
  • log_raw_response: Enables/disables logging of the raw response.

An instance of Api can be created using an API key and provides an easy way to interact with the API service.

Implementations§

Source§

impl Api

Source

pub fn discover<T>(&self, doi: T) -> Result<ApiResponse<Discovery>, Error>
where T: ToString + Clone,

allows you to find links to full texts based on a DOI. The system will search through the CORE data and other external sources to provide you the best match.

§Parameters
  • ‘doi’ - Doi of the target discover resource
§Examples
use core_api_client::Api;
 
let api = Api::from("API_KEY");
api.discover("10.1016/0370-2693(96)00910-0");
Source

pub fn get_journal<T>(&self, id: T) -> Result<ApiResponse<Journal>, Error>
where T: ToString + Clone,

Fetches a single output from CORE using the provided output id.

§Parameters
  • id - The Journal id in CORE. Use issn:ISSN to search by ISSN instead of the CORE identifier.
§Examples
use core_api_client::Api;
 
let api = Api::from("API_KEY");
api.get_journal("issn:1179-1497");
Source

pub fn get_output<T>(&self, id: T) -> Result<ApiResponse<Work>, Error>
where T: ToString + Clone,

Fetches a single output from CORE using the provided output id.

§Parameters
  • id - The CORE ID of the output to be fetched.
§Examples
use core_api_client::FilterOperator;
use core_api_client::Api;
 
let api = Api::from("API_KEY");
api.get_output(0);
Source

pub fn get_data_provider<T>( &self, id: T, ) -> Result<ApiResponse<DataProvider>, Error>
where T: ToString + Clone,

Fetches a specific data provider from CORE using the provided data provider identifier.

The function makes use of the CORE API’s capability to fetch data provider details using their identifiers. The identifiers can be either:

  1. CORE’s data provider identifier.
  2. OpenDOAR’s identifier, prefixed by “opendoar:” (e.g., “opendoar:123”).

A call to this function executes a query against the CORE API and returns the results wrapped in an ApiResponse.

§Parameters
  • id: Identifier of the data provider. Can be a CORE data provider identifier (integer) or an OpenDOAR identifier prefixed with “opendoar:”.
§Examples
use core_api_client::FilterOperator;
use core_api_client::Api;
 
let api = Api::from("API_KEY");
api.get_data_provider(86);
api.get_data_provider("opendoar:300");
 
Source

pub fn search_works<T1, T2>( &self, query: SearchQuery<T1, T2>, ) -> Result<ApiResponse<SearchResponse<Work>>, Error>
where T1: ToString + Clone, T2: ToString + Clone,

Executes a search on the API for works based on the query. These are the entities that represent a piece of research, .e.g research articles, theses, etc. In total, it is a deduplicated and enriched version of records.

use core_api_client::FilterOperator;
use core_api_client::Api;
 
let api = Api::from("API_KEY");
 
let query = api.paged_search(10, 0)
   .and(FilterOperator::Exists("doi"))
   .and(FilterOperator::Bigger("citationCount", 20));
 
let resp = api.search_works(query);
Source

pub fn search_data_providers<T1, T2>( &self, query: SearchQuery<T1, T2>, ) -> Result<ApiResponse<SearchResponse<DataProvider>>, Error>
where T1: ToString + Clone, T2: ToString + Clone,

Executes a search on the API for works based on the query. It gives you access to the collection of entities that offer data to CORE. It contains repositories (institutional and disciplinary), preprint servers, journals and publishers.

use core_api_client::FilterOperator;
use core_api_client::Api;
 
let api = Api::from("API_KEY");
 
let query = api.paged_search(10, 0)
   .and(FilterOperator::Exists("software"))
   .and(FilterOperator::HasValue("type", "JOURNAL"));
let resp = api.search_data_providers(query);
Source

pub fn search_journals<T1, T2>( &self, query: SearchQuery<T1, T2>, ) -> Result<ApiResponse<SearchResponse<Journal>>, Error>
where T1: ToString + Clone, T2: ToString + Clone,

Executes a search on the API for journals based on the query. This dataset contains all journal titles included in the CORE collection. Moreover, you can search and retrieve any journal even if it is not a CORE data provider.

use core_api_client::FilterOperator;
use core_api_client::Api;
 
let api = Api::from("API_KEY");
 
let query = api.paged_search(10, 0)
    .and(FilterOperator::Eq("publisher", "OJS"));
let resp = api.search_journals(query);
Source

pub fn search_outputs<T1, T2>( &self, query: SearchQuery<T1, T2>, ) -> Result<ApiResponse<SearchResponse<Work>>, Error>
where T1: ToString + Clone, T2: ToString + Clone,

Executes a search on the API for otuputs (works) based on the query. Outputs are a representation of a Work in a data provider. The data is not enriched and it mirrors exactly the content harvested from the data provider.

use core_api_client::FilterOperator;
use core_api_client::Api;
 
let api = Api::from("API_KEY");
 
let query = api.paged_search(10, 0)
    .and(FilterOperator::Eq("publisher", "OJS"));
let resp = api.search_outputs(query);

The paged_search method initiates a paginated search on the API. It takes a limit and an offset as arguments, representing the number of results to return per page and the starting point for the results respectively. This method returns a SearchQuery object that can be further manipulated to define the search criteria.

Due to generic implementation the search requres 2 types. In case you do not use any filters the types can not be infered and therefore requre you to use any generic type that implements ToString.

Example:

use core_api_client::Api;
use core_api_client::FilterOperator;
 
let api = Api::from("API_KEY");
let query1 = api.paged_search::<String, String>(10, 0); // Initiates a paginated search for 10 items starting from the first result
let query2 = api.paged_search::<_, String>(10, 0)
    .and(FilterOperator::Exists("software"));
let query3 = api.paged_search(10, 0)
    .and(FilterOperator::HasValue("type", "JOURNAL"));
Source

pub fn log_target(self, log_target: bool) -> Self

Method allows the user to override the default (false) logging of the target URI that is being fetched for data retrieval from the api

use core_api_client::Api;
let api = Api::from("API_KEY").log_target(true);
Source

pub fn log_raw_response(self, log_raw_response: bool) -> Self

Method allows the user to override the default (false) logging of the raw responses that are returned from the API.

use core_api_client::Api;
let api = Api::from("API_KEY").log_raw_response(true);

Trait Implementations§

Source§

impl Debug for Api

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Into<String>> From<T> for Api

Source§

fn from(key: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Api

§

impl !RefUnwindSafe for Api

§

impl Send for Api

§

impl Sync for Api

§

impl Unpin for Api

§

impl !UnwindSafe for Api

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,