Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add id_with_options method #141

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion ipfs-api-prelude/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,41 @@ pub trait IpfsApi: Backend {
/// ```
///
async fn id(&self, peer: Option<&str>) -> Result<response::IdResponse, Self::Error> {
self.request(request::Id { peer }, None).await
self.request(
request::Id {
peer,
format: None,
peerid_base: None,
},
None,
)
.await
}

/// Returns information about a peer.
///
/// If `peer` is `None`, returns information about you.
///
/// ```no_run
/// use ipfs_api::{IpfsApi, IpfsClient};
///
/// let client = IpfsClient::default();
/// #[cfg(feature = "with-builder")]
/// let req = ipfs_api::request::Id::builder()
/// .peer("QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM")
/// .build();
/// #[cfg(not(feature = "with-builder"))]
/// let req = ipfs_api::request::Id {
/// peer: "QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
/// .. Default::default()
/// };
/// let res = client.id_with_options(req);
///
async fn id_with_options(
&self,
options: request::Id<'_>,
) -> Result<response::IdResponse, Self::Error> {
self.request(options, None).await
}

/// Create a new keypair.
Expand Down
17 changes: 16 additions & 1 deletion ipfs-api-prelude/src/request/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,27 @@
use crate::request::ApiRequest;
use serde::Serialize;

#[derive(Serialize)]
#[cfg_attr(feature = "with-builder", derive(TypedBuilder))]
#[derive(Default, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct Id<'a> {
/// Peer.ID of node to look up.
#[serde(rename = "arg")]
#[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
pub peer: Option<&'a str>,

/// Ignored by go-ipfs in it's REST API. Always returns in JSON. Retained for compatibility.
#[serde(skip)]
#[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
pub format: Option<IdFormat>,

/// Encoding used for peer IDs: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}. Default: b58mh.
#[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
pub peerid_base: Option<&'a str>,
}

impl<'a> ApiRequest for Id<'a> {
const PATH: &'static str = "/id";
}

pub enum IdFormat {}