Skip to main content

FigshareClient

Struct FigshareClient 

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

Typed async client for the core Figshare REST API.

Implementations§

Source§

impl FigshareClient

Source

pub fn builder(auth: Auth) -> FigshareClientBuilder

Starts building a new client from authentication settings.

Source

pub fn new(auth: Auth) -> Result<Self, FigshareError>

Builds a client with default endpoint and polling options.

§Errors

Returns an error if the underlying HTTP client cannot be initialized.

Source

pub fn with_token(token: impl Into<String>) -> Result<Self, FigshareError>

Builds a client directly from a raw API token.

§Errors

Returns an error if the underlying HTTP client cannot be initialized.

Source

pub fn anonymous() -> Result<Self, FigshareError>

Builds an anonymous client for public API calls.

§Errors

Returns an error if the underlying HTTP client cannot be initialized.

Source

pub fn from_env() -> Result<Self, FigshareError>

Builds a client from Auth::TOKEN_ENV_VAR.

§Errors

Returns an error if the environment variable is missing or invalid, or if the underlying HTTP client cannot be initialized.

Source

pub fn endpoint(&self) -> &Endpoint

Returns the configured API endpoint.

Source

pub fn poll_options(&self) -> &PollOptions

Returns the configured polling behavior.

Source

pub fn request_timeout(&self) -> Option<Duration>

Returns the configured overall HTTP request timeout.

Source

pub fn connect_timeout(&self) -> Option<Duration>

Returns the configured TCP connect timeout.

Source

pub async fn list_licenses(&self) -> Result<Vec<ArticleLicense>, FigshareError>

Lists public licenses.

§Errors

Returns an error if the request fails or Figshare returns a non-success response.

Source

pub async fn list_categories( &self, ) -> Result<Vec<ArticleCategory>, FigshareError>

Lists public categories.

§Errors

Returns an error if the request fails or Figshare returns a non-success response.

Source

pub async fn list_account_categories( &self, ) -> Result<Vec<ArticleCategory>, FigshareError>

Lists categories available to the authenticated account.

§Errors

Returns an error if authentication is missing, if the request fails, or if Figshare returns a non-success response.

Source

pub async fn list_public_articles( &self, query: &ArticleQuery, ) -> Result<Vec<Article>, FigshareError>

Lists public articles.

§Errors

Returns an error if the request fails or Figshare returns a non-success response.

Source

pub async fn list_public_article_versions( &self, id: ArticleId, ) -> Result<Vec<ArticleVersion>, FigshareError>

Lists public versions for one article.

§Errors

Returns an error if the request fails or Figshare returns a non-success response.

Source

pub async fn get_public_article_version( &self, id: ArticleId, version: u64, ) -> Result<Article, FigshareError>

Reads one specific public article version.

§Errors

Returns an error if the request fails or Figshare returns a non-success response.

Source

pub async fn list_own_articles( &self, query: &ArticleQuery, ) -> Result<Vec<Article>, FigshareError>

Lists the authenticated account’s own articles.

§Errors

Returns an error if authentication is missing, if the request fails, or if Figshare returns a non-success response.

Source

pub async fn search_own_articles( &self, query: &ArticleQuery, ) -> Result<Vec<Article>, FigshareError>

Searches the authenticated account’s own articles.

§Errors

Returns an error if authentication is missing, if the query is invalid, if the request fails, or if Figshare returns a non-success response.

Source

pub async fn get_own_article( &self, id: ArticleId, ) -> Result<Article, FigshareError>

Reads one private article owned by the authenticated account.

§Errors

Returns an error if authentication is missing, if the request fails, or if Figshare returns a non-success response.

Source

pub async fn delete_article(&self, id: ArticleId) -> Result<(), FigshareError>

Deletes a private article.

§Errors

Returns an error if authentication is missing, if the request fails, or if Figshare returns a non-success response.

Source

pub async fn reserve_doi(&self, id: ArticleId) -> Result<Doi, FigshareError>

Reserves a DOI for a private article.

§Errors

Returns an error if authentication is missing, if the request fails, or if Figshare returns a non-success response.

Source

pub async fn list_files( &self, id: ArticleId, ) -> Result<Vec<ArticleFile>, FigshareError>

Lists files attached to a private article.

§Errors

Returns an error if authentication is missing, if the request fails, or if Figshare returns a non-success response.

Source

pub async fn list_public_article_version_files( &self, article_id: ArticleId, version: u64, ) -> Result<Vec<ArticleFile>, FigshareError>

Lists files attached to one public article version.

§Errors

Returns an error if the request fails or if Figshare returns a non-success response.

Source

pub async fn get_file( &self, article_id: ArticleId, file_id: FileId, ) -> Result<ArticleFile, FigshareError>

Reads one file attached to a private article.

§Errors

Returns an error if authentication is missing, if the request fails, or if Figshare returns a non-success response.

Source

pub async fn delete_file( &self, article_id: ArticleId, file_id: FileId, ) -> Result<(), FigshareError>

Deletes a file from a private article.

§Errors

Returns an error if authentication is missing, if the request fails, or if Figshare returns a non-success response.

Source

pub async fn initiate_file_upload( &self, article_id: ArticleId, name: &str, size: u64, md5: &str, ) -> Result<ArticleFile, FigshareError>

Initiates a hosted file upload for a private article.

§Errors

Returns an error if authentication is missing, if the request fails, or if Figshare returns a non-success response.

Initiates a link-only file attachment for a private article.

§Errors

Returns an error if authentication is missing, if the request fails, or if Figshare returns a non-success response.

Source

pub async fn get_upload_session( &self, upload_url: &Url, ) -> Result<UploadSession, FigshareError>

Reads one upload session from the upload service.

§Errors

Returns an error if authentication is missing, if the request fails, or if Figshare returns a non-success response.

Source

pub async fn upload_part( &self, upload_url: &Url, part_no: u64, bytes: Vec<u8>, ) -> Result<(), FigshareError>

Uploads one part to the upload service.

§Errors

Returns an error if authentication is missing, if the request fails, or if Figshare returns a non-success response.

Source

pub async fn reset_upload_part( &self, upload_url: &Url, part_no: u64, ) -> Result<(), FigshareError>

Resets one uploaded part.

§Errors

Returns an error if authentication is missing, if the request fails, or if Figshare returns a non-success response.

Source

pub async fn complete_file_upload( &self, article_id: ArticleId, file_id: FileId, ) -> Result<(), FigshareError>

Marks an uploaded file as complete.

§Errors

Returns an error if authentication is missing, if the request fails, or if Figshare returns a non-success response.

Source

pub async fn upload_path( &self, article_id: ArticleId, path: &Path, ) -> Result<ArticleFile, FigshareError>

Uploads a local file path to a private article.

§Errors

Returns an error if authentication is missing, if the local file cannot be read, if the request fails, or if Figshare returns a non-success response.

Source

pub async fn upload_reader<R>( &self, article_id: ArticleId, filename: &str, reader: R, content_length: u64, ) -> Result<ArticleFile, FigshareError>
where R: Read + Send + 'static,

Uploads data from a blocking reader by staging it to a temporary file and performing a standard Figshare hosted upload.

§Errors

Returns an error if authentication is missing, if staging the reader fails, if the request fails, or if Figshare returns a non-success response.

Source§

impl FigshareClient

Source

pub async fn open_public_article_file_by_name( &self, article_id: ArticleId, name: &str, latest: bool, ) -> Result<DownloadStream, FigshareError>

Opens a file from a public article by exact file name.

When latest is true, the latest public article version is resolved before selecting the file.

§Errors

Returns an error if the article or file cannot be resolved, if the request fails, or if Figshare returns a non-success response.

Source

pub async fn open_article_file_by_doi( &self, doi: &Doi, name: &str, latest: bool, ) -> Result<DownloadStream, FigshareError>

Opens a file from a public article selected by DOI.

When latest is true, the latest public article version is resolved before selecting the file.

§Errors

Returns an error if the article or file cannot be resolved, if the request fails, or if Figshare returns a non-success response.

Source

pub async fn open_own_article_file_by_name( &self, article_id: ArticleId, name: &str, ) -> Result<DownloadStream, FigshareError>

Opens a file from one of the authenticated account’s own articles by exact file name.

§Errors

Returns an error if authentication is missing, if the article or file cannot be resolved, if the request fails, or if Figshare returns a non-success response.

Source

pub async fn download_public_article_file_by_name_to_path( &self, article_id: ArticleId, name: &str, latest: bool, path: &Path, ) -> Result<ResolvedDownload, FigshareError>

Downloads a file from a public article by exact file name.

§Errors

Returns an error if the article or file cannot be resolved, if the request fails, or if writing the destination path fails.

Source

pub async fn download_article_file_by_doi_to_path( &self, doi: &Doi, name: &str, latest: bool, path: &Path, ) -> Result<ResolvedDownload, FigshareError>

Downloads a file from a public article resolved by DOI.

§Errors

Returns an error if the article or file cannot be resolved, if the request fails, or if writing the destination path fails.

Source

pub async fn download_own_article_file_by_name_to_path( &self, article_id: ArticleId, name: &str, path: &Path, ) -> Result<ResolvedDownload, FigshareError>

Downloads a file from one of the authenticated account’s own articles by exact file name.

§Errors

Returns an error if authentication is missing, if the article or file cannot be resolved, if the request fails, or if writing the destination path fails.

Trait Implementations§

Source§

impl ClientContext for FigshareClient

Source§

type Endpoint = Endpoint

Service-specific endpoint configuration type.
Source§

type PollOptions = PollOptions

Service-specific polling configuration type.
Source§

type Error = FigshareError

Service-specific error type.
Source§

fn endpoint(&self) -> &Self::Endpoint

Returns the configured endpoint roots.
Source§

fn poll_options(&self) -> &Self::PollOptions

Returns the configured polling behavior.
Source§

fn request_timeout(&self) -> Option<Duration>

Returns the overall request timeout, when configured.
Source§

fn connect_timeout(&self) -> Option<Duration>

Returns the TCP connect timeout, when configured.
Source§

impl Clone for FigshareClient

Source§

fn clone(&self) -> FigshareClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl CreatePublication for FigshareClient

Source§

type CreateTarget = NoCreateTarget

Caller-supplied creation target type.
Source§

type Metadata = ArticleMetadata

Service-specific metadata type.
Source§

type Upload = UploadSpec

Service-specific upload specification type.
Source§

type Output = PublishedArticle

Service-specific workflow result type.
Source§

async fn create_publication( &self, request: CreatePublicationRequest<Self::CreateTarget, Self::Metadata, Self::Upload>, ) -> Result<Self::Output, Self::Error>

Runs the service’s “create a new published resource” workflow.
Source§

impl Debug for FigshareClient

Source§

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

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

impl DownloadNamedPublicFile for FigshareClient

Source§

type ResourceId = ArticleId

Service-specific resource identifier type.
Source§

type Download = ResolvedDownload

Service-specific download result metadata.
Source§

async fn download_named_public_file_to_path( &self, id: &Self::ResourceId, name: &str, path: &Path, ) -> Result<Self::Download, Self::Error>

Downloads one named file from a public resource.
Source§

impl DraftWorkflow for FigshareClient

Source§

type Draft = Article

Service-specific mutable draft type.
Source§

type Metadata = ArticleMetadata

Service-specific metadata type.
Source§

type Upload = UploadSpec

Service-specific upload specification type.
Source§

type FilePolicy = FileReplacePolicy

Service-specific draft file policy.
Source§

type UploadResult = ArticleFile

Service-specific upload result type.
Source§

type Published = Article

Result returned by the publish step.
Source§

async fn create_draft( &self, metadata: &Self::Metadata, ) -> Result<Self::Draft, Self::Error>

Creates a new mutable draft-like resource with the supplied metadata.
Source§

async fn update_draft_metadata( &self, draft_id: &<Self::Draft as DraftResource>::Id, metadata: &Self::Metadata, ) -> Result<Self::Draft, Self::Error>

Replaces or merges the draft metadata.
Source§

async fn reconcile_draft_files( &self, draft: &Self::Draft, policy: Self::FilePolicy, uploads: Vec<Self::Upload>, ) -> Result<Vec<Self::UploadResult>, Self::Error>

Reconciles the draft file set under the requested policy.
Source§

async fn publish_draft( &self, draft_id: &<Self::Draft as DraftResource>::Id, ) -> Result<Self::Published, Self::Error>

Publishes the draft-like resource.
Source§

impl ListResourceFiles for FigshareClient

Source§

type ResourceId = ArticleId

Service-specific resource identifier type.
Source§

type File = ArticleFile

Service-specific file entry type.
Source§

async fn list_resource_files( &self, id: &Self::ResourceId, ) -> Result<Vec<Self::File>, Self::Error>

Returns the complete visible file list for the resource.
Source§

impl LookupByDoi for FigshareClient

Source§

type Doi = Doi

Service-specific DOI type.
Source§

type Resource = Article

Returned public resource payload.
Source§

async fn get_public_resource_by_doi( &self, doi: &Self::Doi, ) -> Result<Self::Resource, Self::Error>

Fetches one public resource by DOI.
Source§

impl MaybeAuthenticatedClient for FigshareClient

Source§

fn has_auth(&self) -> bool

Returns whether the client currently has credentials available for authenticated calls.
Source§

impl ReadPublicResource for FigshareClient

Source§

type ResourceId = ArticleId

Service-specific resource identifier type.
Source§

type Resource = Article

Returned public resource payload.
Source§

async fn get_public_resource( &self, id: &Self::ResourceId, ) -> Result<Self::Resource, Self::Error>

Fetches one public resource.
Source§

impl ResolveLatestPublicResource for FigshareClient

Source§

type ResourceId = ArticleId

Service-specific resource identifier type.
Source§

type Resource = Article

Returned public resource payload.
Source§

async fn resolve_latest_public_resource( &self, id: &Self::ResourceId, ) -> Result<Self::Resource, Self::Error>

Resolves the latest public version in the resource family.
Source§

impl ResolveLatestPublicResourceByDoi for FigshareClient

Source§

type Doi = Doi

Service-specific DOI type.
Source§

type Resource = Article

Returned public resource payload.
Source§

async fn resolve_latest_public_resource_by_doi( &self, doi: &Self::Doi, ) -> Result<Self::Resource, Self::Error>

Resolves the latest public version in the DOI-backed resource family.
Source§

impl SearchPublicResources for FigshareClient

Source§

type Query = ArticleQuery

Service-specific query type.
Source§

type SearchResults = Vec<Article>

Service-specific search result shape.
Source§

async fn search_public_resources( &self, query: &Self::Query, ) -> Result<Self::SearchResults, Self::Error>

Executes a public search request.
Source§

impl UpdatePublication for FigshareClient

Source§

type ResourceId = ArticleId

Service-specific resource identifier type.
Source§

type Metadata = ArticleMetadata

Service-specific metadata type.
Source§

type FilePolicy = FileReplacePolicy

Service-specific upload-policy type.
Source§

type Upload = UploadSpec

Service-specific upload specification type.
Source§

type Output = PublishedArticle

Service-specific workflow result type.
Source§

async fn update_publication( &self, request: UpdatePublicationRequest<Self::ResourceId, Self::Metadata, Self::FilePolicy, Self::Upload>, ) -> Result<Self::Output, Self::Error>

Runs the service’s “update or upsert an existing resource” workflow.

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> CoreRepositoryClient for T

Source§

impl<T> DoiVersionedRepositoryClient for T

Source§

impl<T> DraftPublishingRepositoryClient for T