summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSionoiS <SionoiS@users.noreply.github.com>2020-08-24 10:06:31 -0400
committerSionoiS <SionoiS@users.noreply.github.com>2020-08-24 10:06:31 -0400
commit2ac3eb4eacdf29cea546c722c00a44aff2d6edf9 (patch)
tree03fe95254c3ecf8feebe82c6bc69d1d226284c1b
parent6af9cfd1664edf4ad78277d4079700ec53f2206e (diff)
function split
-rw-r--r--ipfs-api/examples/config.rs34
-rw-r--r--ipfs-api/src/client/internal.rs139
2 files changed, 159 insertions, 14 deletions
diff --git a/ipfs-api/examples/config.rs b/ipfs-api/examples/config.rs
index d2eb8ca..0d22ace 100644
--- a/ipfs-api/examples/config.rs
+++ b/ipfs-api/examples/config.rs
@@ -18,25 +18,49 @@ async fn main() {
let client = IpfsClient::default();
- //read a value
+ //read a string
let response = client
- .config("Identity.PeerID", None, None, None)
+ .config_get_string("Identity.PeerID")
.await
.expect("Config read failed");
println!("Config: {}={}", response.key, response.value);
+ //read a bool
+ let response = client
+ .config_get_bool("Datastore.HashOnRead")
+ .await
+ .expect("Config read failed");
+
+ println!("Config: {}={}", response.key, response.value);
+
+ //read a stringified json
+ let response = client
+ .config_get_json("Mounts")
+ .await
+ .expect("Config read failed");
+
+ println!("Config: {}={}", response.key, response.value);
+
+ //set a string value
+ let response = client
+ .config_set_string("Routing.Type", "dht")
+ .await
+ .expect("Config write failed");
+
+ println!("Config: {}={}", response.key, response.value);
+
//set a boolean value
let response = client
- .config("Pubsub.DisableSigning", Some("false"), Some(true), None)
+ .config_set_bool("Pubsub.DisableSigning", "false")
.await
.expect("Config write failed");
println!("Config: {}={}", response.key, response.value);
- //set a integer value
+ //set a json value
let response = client
- .config("Datastore.StorageGCWatermark", Some("90"), None, Some(true))
+ .config_set_json("Discovery", r#"{"MDNS":{"Enabled":true,"Interval":10}}"#)
.await
.expect("Config write failed");
diff --git a/ipfs-api/src/client/internal.rs b/ipfs-api/src/client/internal.rs
index 60acf2e..6674daa 100644
--- a/ipfs-api/src/client/internal.rs
+++ b/ipfs-api/src/client/internal.rs
@@ -789,29 +789,150 @@ impl IpfsClient {
self.request(request::Commands, None).await
}
- /// Get and set ipfs config values.
+ /// Get ipfs config strings.
///
/// ```no_run
/// use ipfs_api::IpfsClient;
///
/// let client = IpfsClient::default();
- /// let res = client.config("Identity.PeerID", None, None, None);
+ /// let res = client.config_get_string("Identity.PeerID");
/// ```
///
#[inline]
- pub async fn config(
+ pub async fn config_get_string(&self, key: &str) -> Result<response::ConfigResponse, Error> {
+ self.request(
+ request::Config {
+ key,
+ value: None,
+ boolean: None,
+ stringified_json: None,
+ },
+ None,
+ )
+ .await
+ }
+
+ /// Get ipfs config booleans.
+ ///
+ /// ```no_run
+ /// use ipfs_api::IpfsClient;
+ ///
+ /// let client = IpfsClient::default();
+ /// let res = client.config_get_bool("Datastore.HashOnRead");
+ /// ```
+ ///
+ #[inline]
+ pub async fn config_get_bool(&self, key: &str) -> Result<response::ConfigResponse, Error> {
+ self.request(
+ request::Config {
+ key,
+ value: None,
+ boolean: None,
+ stringified_json: None,
+ },
+ None,
+ )
+ .await
+ }
+
+ /// Get ipfs config json.
+ ///
+ /// ```no_run
+ /// use ipfs_api::IpfsClient;
+ ///
+ /// let client = IpfsClient::default();
+ /// let res = client.config_get_json("Mounts");
+ /// ```
+ ///
+ #[inline]
+ pub async fn config_get_json(&self, key: &str) -> Result<response::ConfigResponse, Error> {
+ self.request(
+ request::Config {
+ key,
+ value: None,
+ boolean: None,
+ stringified_json: None,
+ },
+ None,
+ )
+ .await
+ }
+
+ /// Set ipfs config string.
+ ///
+ /// ```no_run
+ /// use ipfs_api::IpfsClient;
+ ///
+ /// let client = IpfsClient::default();
+ /// let res = client.config_set_string("Routing.Type", "dht");
+ /// ```
+ ///
+ #[inline]
+ pub async fn config_set_string(
&self,
key: &str,
- value: Option<&str>,
- boolean: Option<bool>,
- stringified_json: Option<bool>,
+ value: &str,
+ ) -> Result<response::ConfigResponse, Error> {
+ self.request(
+ request::Config {
+ key,
+ value: Some(value),
+ boolean: None,
+ stringified_json: None,
+ },
+ None,
+ )
+ .await
+ }
+
+ /// Set ipfs config boolean.
+ ///
+ /// ```no_run
+ /// use ipfs_api::IpfsClient;
+ ///
+ /// let client = IpfsClient::default();
+ /// let res = client.config_set_bool("Pubsub.DisableSigning", "false");
+ /// ```
+ ///
+ #[inline]
+ pub async fn config_set_bool(
+ &self,
+ key: &str,
+ value: &str,
+ ) -> Result<response::ConfigResponse, Error> {
+ self.request(
+ request::Config {
+ key,
+ value: Some(value),
+ boolean: Some(true),
+ stringified_json: None,
+ },
+ None,
+ )
+ .await
+ }
+
+ /// Set ipfs config json.
+ ///
+ /// ```no_run
+ /// use ipfs_api::IpfsClient;
+ ///
+ /// let client = IpfsClient::default();
+ /// let res = config_set_json("Discovery", r#"{"MDNS":{"Enabled":true,"Interval":10}}"#);
+ /// ```
+ ///
+ #[inline]
+ pub async fn config_set_json(
+ &self,
+ key: &str,
+ value: &str,
) -> Result<response::ConfigResponse, Error> {
self.request(
request::Config {
key,
- value,
- boolean,
- stringified_json,
+ value: Some(value),
+ boolean: None,
+ stringified_json: Some(true),
},
None,
)