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: trueandAccept: application/json. - Mutation requests (
POST,PUT) serialize request bodies as JSON and setContent-Type: application/json. - Responses are wrapped in an
OcsEnvelopecarrying ameta.statuscodeverdict (100or200for success; failure codes such as101,102,997,998, or999map toError::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>
impl<T: Transport, A: AuthProvider> OcsClient<T, A>
Sourcepub const fn new(transport: T, auth: A) -> Self
pub const fn new(transport: T, auth: A) -> Self
Pairs a transport with the credentials applied to every call.
Sourcepub async fn get<Res: DeserializeOwned>(
&self,
path: ApiPath,
query: Query,
) -> Result<Res, Error>
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/
Sourcepub async fn post<Req: Serialize, Res: DeserializeOwned>(
&self,
path: ApiPath,
body: &Req,
) -> Result<Res, Error>
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/
Sourcepub async fn post_with_query<Req: Serialize, Res: DeserializeOwned>(
&self,
path: ApiPath,
query: Query,
body: &Req,
) -> Result<Res, Error>
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/
Sourcepub async fn put<Req: Serialize, Res: DeserializeOwned>(
&self,
path: ApiPath,
body: &Req,
) -> Result<Res, Error>
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/
Sourcepub async fn put_with_query<Req: Serialize, Res: DeserializeOwned>(
&self,
path: ApiPath,
query: Query,
body: &Req,
) -> Result<Res, Error>
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/
Sourcepub async fn delete<Res: DeserializeOwned>(
&self,
path: ApiPath,
) -> Result<Res, Error>
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/
Sourcepub async fn delete_with_query<Res: DeserializeOwned>(
&self,
path: ApiPath,
query: Query,
) -> Result<Res, Error>
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/