Skip to content

Commit 7040c2b

Browse files
authored
Merge pull request #7 from G8XSU/add-delete
Add delete_object fn to client
2 parents 3c2de18 + 6a42ce6 commit 7040c2b

File tree

5 files changed

+199
-79
lines changed

5 files changed

+199
-79
lines changed

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main() {
1414
#[cfg(feature = "genproto")]
1515
fn generate_protos() {
1616
download_file(
17-
"https://raw.githubusercontent.com/lightningdevkit/vss-server/ff4b5fc6a079ed8719eb8be7ec35ca1d01c1cc55/app/src/main/proto/vss.proto",
17+
"https://raw.githubusercontent.com/lightningdevkit/vss-server/ac646dd419bc70db2b79772b1bfa1b2d9a4b8b53/app/src/main/proto/vss.proto",
1818
"src/proto/vss.proto",
1919
).unwrap();
2020

src/client.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ use reqwest::Client;
44

55
use crate::error::VssError;
66
use crate::types::{
7-
GetObjectRequest, GetObjectResponse, ListKeyVersionsRequest, ListKeyVersionsResponse, PutObjectRequest,
8-
PutObjectResponse,
7+
DeleteObjectRequest, DeleteObjectResponse, GetObjectRequest, GetObjectResponse, ListKeyVersionsRequest,
8+
ListKeyVersionsResponse, PutObjectRequest, PutObjectResponse,
99
};
1010

1111
/// Thin-client to access a hosted instance of Versioned Storage Service (VSS).
1212
/// The provided [`VssClient`] API is minimalistic and is congruent to the VSS server-side API.
13+
#[derive(Clone)]
1314
pub struct VssClient {
1415
base_url: String,
1516
client: Client,
@@ -59,6 +60,24 @@ impl VssClient {
5960
}
6061
}
6162

63+
/// Deletes the given `key` and `value` in `request`.
64+
/// Makes a service call to the `DeleteObject` endpoint of the VSS server.
65+
/// For API contract/usage, refer to docs for [`DeleteObjectRequest`] and [`DeleteObjectResponse`].
66+
pub async fn delete_object(&self, request: &DeleteObjectRequest) -> Result<DeleteObjectResponse, VssError> {
67+
let url = format!("{}/deleteObject", self.base_url);
68+
69+
let response_raw = self.client.post(url).body(request.encode_to_vec()).send().await?;
70+
let status = response_raw.status();
71+
let payload = response_raw.bytes().await?;
72+
73+
if status.is_success() {
74+
let response = DeleteObjectResponse::decode(&payload[..])?;
75+
Ok(response)
76+
} else {
77+
Err(VssError::new(status, payload))
78+
}
79+
}
80+
6281
/// Lists keys and their corresponding version for a given [`ListKeyVersionsRequest::store_id`].
6382
/// Makes a service call to the `ListKeyVersions` endpoint of the VSS server.
6483
/// For API contract/usage, refer to docs for [`ListKeyVersionsRequest`] and [`ListKeyVersionsResponse`].

src/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Client-side library to interact with Versioned Storage Service (VSS).
22
//!
33
//! VSS is an open-source project designed to offer a server-side cloud storage solution specifically
4-
//! tailored for non-custodial Lightning supporting mobile wallets. Its primary objective is to
4+
//! tailored for noncustodial Lightning supporting mobile wallets. Its primary objective is to
55
//! simplify the development process for Lightning wallets by providing a secure means to store
66
//! and manage the essential state required for Lightning Network (LN) operations.
77
//!
@@ -10,13 +10,10 @@
1010
#![deny(rustdoc::broken_intra_doc_links)]
1111
#![deny(rustdoc::private_intra_doc_links)]
1212

13-
use crate::client::VssClient;
14-
use crate::error::VssError;
15-
16-
/// Implements a thin-client ([`VssClient`]) to access a hosted instance of Versioned Storage Service (VSS).
13+
/// Implements a thin-client ([`client::VssClient`]) to access a hosted instance of Versioned Storage Service (VSS).
1714
pub mod client;
1815

19-
/// Implements the error type ([`VssError`]) returned on interacting with [`VssClient`]
16+
/// Implements the error type ([`error::VssError`]) returned on interacting with [`client::VssClient`]
2017
pub mod error;
2118

2219
/// Contains request/response types generated from the API definition of VSS.

0 commit comments

Comments
 (0)