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 COREdiscover
: 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
impl Api
Sourcepub fn discover<T>(&self, doi: T) -> Result<ApiResponse<Discovery>, Error>
pub fn discover<T>(&self, doi: T) -> Result<ApiResponse<Discovery>, Error>
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");
Sourcepub fn get_journal<T>(&self, id: T) -> Result<ApiResponse<Journal>, Error>
pub fn get_journal<T>(&self, id: T) -> Result<ApiResponse<Journal>, Error>
Sourcepub fn get_output<T>(&self, id: T) -> Result<ApiResponse<Work>, Error>
pub fn get_output<T>(&self, id: T) -> Result<ApiResponse<Work>, Error>
Sourcepub fn get_data_provider<T>(
&self,
id: T,
) -> Result<ApiResponse<DataProvider>, Error>
pub fn get_data_provider<T>( &self, id: T, ) -> Result<ApiResponse<DataProvider>, Error>
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:
- CORE’s data provider identifier.
- 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");
Sourcepub fn search_works<T1, T2>(
&self,
query: SearchQuery<T1, T2>,
) -> Result<ApiResponse<SearchResponse<Work>>, Error>
pub fn search_works<T1, T2>( &self, query: SearchQuery<T1, T2>, ) -> Result<ApiResponse<SearchResponse<Work>>, Error>
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);
Sourcepub fn search_data_providers<T1, T2>(
&self,
query: SearchQuery<T1, T2>,
) -> Result<ApiResponse<SearchResponse<DataProvider>>, Error>
pub fn search_data_providers<T1, T2>( &self, query: SearchQuery<T1, T2>, ) -> Result<ApiResponse<SearchResponse<DataProvider>>, Error>
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);
Sourcepub fn search_journals<T1, T2>(
&self,
query: SearchQuery<T1, T2>,
) -> Result<ApiResponse<SearchResponse<Journal>>, Error>
pub fn search_journals<T1, T2>( &self, query: SearchQuery<T1, T2>, ) -> Result<ApiResponse<SearchResponse<Journal>>, Error>
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);
Sourcepub fn search_outputs<T1, T2>(
&self,
query: SearchQuery<T1, T2>,
) -> Result<ApiResponse<SearchResponse<Work>>, Error>
pub fn search_outputs<T1, T2>( &self, query: SearchQuery<T1, T2>, ) -> Result<ApiResponse<SearchResponse<Work>>, Error>
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);
Sourcepub fn paged_search<T1, T2>(
&self,
limit: i32,
offset: i32,
) -> SearchQuery<T1, T2>
pub fn paged_search<T1, T2>( &self, limit: i32, offset: i32, ) -> SearchQuery<T1, T2>
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"));
Sourcepub fn log_target(self, log_target: bool) -> Self
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);
Sourcepub fn log_raw_response(self, log_raw_response: bool) -> Self
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);