Struct ZoteroWebClient

Source
pub struct ZoteroWebClient {
    client: Client,
    api_key: String,
    base_url: String,
}
Expand description

Blocking client for the Zotero Web API v3.

Fields§

§client: Client§api_key: String§base_url: String

Implementations§

Source§

impl ZoteroWebClient

Source

pub fn new(api_key: &str, library_id: &str, library_type: &str) -> Self

Create a new client for a user library.

Source

pub fn with_base_url(api_key: &str, base_url: &str) -> Self

Create a client with a custom base URL (for testing).

Source

fn headers(&self) -> HeaderMap

Common headers for all API requests.

Source

pub fn get_item(&self, key: &str) -> Result<Value>

GET a single item by key.

Source

pub fn children(&self, key: &str) -> Result<Vec<Value>>

GET children of an item (attachments, notes).

Source

pub fn item_template(&self, item_type: &str) -> Result<Value>

GET an item template for a given type.

Note: the template endpoint is global (/items/new), not scoped to a user library. We use the API root, not self.base_url.

Source

pub fn create_items(&self, items: &[Value]) -> Result<Value>

POST new items to the library.

Source

pub fn update_item(&self, key: &str, data: &Value, version: i32) -> Result<()>

PATCH (update) an existing item.

Requires the item’s current version for optimistic concurrency.

Source

pub fn delete_item(&self, key: &str, version: i32) -> Result<()>

DELETE an item permanently.

Source

pub fn get_collections(&self) -> Result<Vec<Value>>

GET all collections.

Source

pub fn create_collections(&self, collections: &[Value]) -> Result<Value>

POST new collections.

Source

pub fn download_file(&self, url: &str, dest: &Path) -> Result<()>

Download a file from a URL to a local path.

Source

pub fn attach_file( &self, parent_key: &str, file_path: &Path, title: &str, ) -> Result<Value>

Upload a file attachment to an item.

Implements the full Zotero file upload protocol:

  1. Create attachment item metadata
  2. Get upload authorization (with file hash)
  3. Upload file bytes to S3
  4. Register the upload with Zotero
Source

fn get_upload_authorization( &self, key: &str, md5: &str, filename: &str, filesize: usize, mtime: u128, ) -> Result<Value>

Step 2: Get upload authorization from Zotero.

Source

fn upload_to_s3( &self, url: &str, content_type: &str, prefix: &str, file_bytes: &[u8], suffix: &str, ) -> Result<()>

Step 3: Upload file bytes to S3 pre-signed URL.

Source

fn register_upload(&self, key: &str, upload_key: &str) -> Result<()>

Step 4: Register a completed upload with Zotero.

Trait Implementations§

Source§

impl Debug for ZoteroWebClient

Source§

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

Formats the value using the given formatter. Read more

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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.

§

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

§

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
§

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, 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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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