diff --git a/ipfs-api-prelude/src/api.rs b/ipfs-api-prelude/src/api.rs index d82ee27..53e4534 100644 --- a/ipfs-api-prelude/src/api.rs +++ b/ipfs-api-prelude/src/api.rs @@ -1603,7 +1603,41 @@ pub trait IpfsApi: Backend { /// ``` /// async fn id(&self, peer: Option<&str>) -> Result { - 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 { + self.request(options, None).await } /// Create a new keypair. diff --git a/ipfs-api-prelude/src/request/id.rs b/ipfs-api-prelude/src/request/id.rs index 5187e97..e96d83f 100644 --- a/ipfs-api-prelude/src/request/id.rs +++ b/ipfs-api-prelude/src/request/id.rs @@ -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, + + /// 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 {}