Skip to main content

OcsClient

Struct OcsClient 

Source
pub struct OcsClient<T, A> { /* private fields */ }
Expand description

Executes OCS calls and unwraps their envelope.

Generic over the Transport that carries bytes and the AuthProvider that applies credentials, so a client is built from any transport implementation without virtual dispatch. The transport already knows the instance URL and turns an ApiPath into an absolute URL, so the client holds no base URL of its own.

All OCS calls follow the Nextcloud Open Collaboration Services (OCS) specification (https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/):

  • Every request sets OCS-APIRequest: true and Accept: application/json.
  • Mutation requests (POST, PUT) serialize request bodies as JSON and set Content-Type: application/json.
  • Responses are wrapped in an OcsEnvelope carrying a meta.statuscode verdict (100 or 200 for success; failure codes such as 101, 102, 997, 998, or 999 map to Error::Status).
  • Calling endpoints with unit response () succeeds on valid envelopes even when the response payload is empty (e.g. [] or {}), or when the caller only cares about verdict success.

Implementations§

Source§

impl<T: Transport, A: AuthProvider> OcsClient<T, A>

Source

pub const fn new(transport: T, auth: A) -> Self

Pairs a transport with the credentials applied to every call.

Source

pub const fn transport(&self) -> &T

The transport this client sends through.

Source

pub const fn auth(&self) -> &A

The credential provider applied to every call.

Source

pub async fn get<Res: DeserializeOwned>( &self, path: ApiPath, query: Query, ) -> Result<Res, Error>

Performs a GET against an OCS path and returns the envelope payload.

The call sets Accept: application/json and OCS-APIRequest: true and applies credentials. Three cases fail: a path outside /ocs/v2.php, a response status or an OCS verdict the caller cannot accept, and a body that is not an envelope of the requested type. A failure keeps the raw body, so the OCS code (997 app not installed, 998 not allowed, 999 invalid) and its message stay reachable through Error::body.

See Nextcloud OCS API documentation: https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/

Source

pub async fn post<Req: Serialize, Res: DeserializeOwned>( &self, path: ApiPath, body: &Req, ) -> Result<Res, Error>

Performs a POST against an OCS path with a serialised request body.

The call sets Accept: application/json, Content-Type: application/json, and OCS-APIRequest: true, and applies credentials.

When Res is (), calls succeed if the server returns an OCS envelope reporting success (statuscode 100 or 200), ignoring empty or present payload data.

See Nextcloud OCS API documentation: https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/

Source

pub async fn post_with_query<Req: Serialize, Res: DeserializeOwned>( &self, path: ApiPath, query: Query, body: &Req, ) -> Result<Res, Error>

Performs a POST against an OCS path with query parameters and a serialised request body.

The call sets Accept: application/json, Content-Type: application/json, and OCS-APIRequest: true, and applies credentials.

When Res is (), calls succeed if the server returns an OCS envelope reporting success (statuscode 100 or 200), ignoring empty or present payload data.

See Nextcloud OCS API documentation: https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/

Source

pub async fn put<Req: Serialize, Res: DeserializeOwned>( &self, path: ApiPath, body: &Req, ) -> Result<Res, Error>

Performs a PUT against an OCS path with a serialised request body.

The call sets Accept: application/json, Content-Type: application/json, and OCS-APIRequest: true, and applies credentials.

When Res is (), calls succeed if the server returns an OCS envelope reporting success (statuscode 100 or 200), ignoring empty or present payload data.

See Nextcloud OCS API documentation: https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/

Source

pub async fn put_with_query<Req: Serialize, Res: DeserializeOwned>( &self, path: ApiPath, query: Query, body: &Req, ) -> Result<Res, Error>

Performs a PUT against an OCS path with query parameters and a serialised request body.

The call sets Accept: application/json, Content-Type: application/json, and OCS-APIRequest: true, and applies credentials.

When Res is (), calls succeed if the server returns an OCS envelope reporting success (statuscode 100 or 200), ignoring empty or present payload data.

See Nextcloud OCS API documentation: https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/

Source

pub async fn delete<Res: DeserializeOwned>( &self, path: ApiPath, ) -> Result<Res, Error>

Performs a DELETE against an OCS path.

The call sets Accept: application/json and OCS-APIRequest: true and applies credentials.

When Res is (), calls succeed if the server returns an OCS envelope reporting success (statuscode 100 or 200), ignoring empty or present payload data.

See Nextcloud OCS API documentation: https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/

Source

pub async fn delete_with_query<Res: DeserializeOwned>( &self, path: ApiPath, query: Query, ) -> Result<Res, Error>

Performs a DELETE against an OCS path with query parameters.

The call sets Accept: application/json and OCS-APIRequest: true and applies credentials.

When Res is (), calls succeed if the server returns an OCS envelope reporting success (statuscode 100 or 200), ignoring empty or present payload data.

See Nextcloud OCS API documentation: https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/

Trait Implementations§

Source§

impl<T: Clone, A: Clone> Clone for OcsClient<T, A>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, A: Debug> Debug for OcsClient<T, A>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, A> Freeze for OcsClient<T, A>
where T: Freeze, A: Freeze,

§

impl<T, A> RefUnwindSafe for OcsClient<T, A>

§

impl<T, A> Send for OcsClient<T, A>
where T: Send, A: Send,

§

impl<T, A> Sync for OcsClient<T, A>
where T: Sync, A: Sync,

§

impl<T, A> Unpin for OcsClient<T, A>
where T: Unpin, A: Unpin,

§

impl<T, A> UnsafeUnpin for OcsClient<T, A>
where T: UnsafeUnpin, A: UnsafeUnpin,

§

impl<T, A> UnwindSafe for OcsClient<T, A>
where T: UnwindSafe, A: UnwindSafe,

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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