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

ipfs: Fix for latest IPFS API language #14

Open
wants to merge 1 commit 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
5 changes: 3 additions & 2 deletions src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ impl IpfsApi {
url.query_pairs_mut()
.append_pair("arg", hash);

let resp = reqwest::get(url)?;
let client = reqwest::Client::new();
let resp = client.post(url).send()?;
Ok(resp.bytes().filter(|x|x.is_ok()).map(|x|x.unwrap()))
}
}
Expand Down Expand Up @@ -63,4 +64,4 @@ mod tests {

assert_eq!(block, content);
}
}
}
4 changes: 3 additions & 1 deletion src/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ impl IpfsApi {
url.set_path("api/v0/cat");
url.query_pairs_mut()
.append_pair("arg", hash);
let resp = reqwest::get(url)?;

let client = reqwest::Client::new();
let resp = client.post(url).send()?;
Ok(resp.bytes().filter(|x|x.is_ok()).map(|x|x.unwrap()))
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/ipns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ impl IpfsApi {
/// ```
pub fn name_resolve(&self, name: &str) -> Result<String, Error> {
let url = format!("http://{}:{}/api/v0/name/resolve?arg={}", self.server, self.port, name);
let resp = reqwest::get(&url)?;
let client = reqwest::Client::new();
let resp = client.post(&url).send()?;
let resp: Value = serde_json::from_reader(resp)?;

if resp["Path"].is_string() {
Expand All @@ -31,7 +32,8 @@ impl IpfsApi {
/// Publish an IPFS hash in IPNS.
pub fn name_publish(&self, hash: &str) -> Result<(), Error> {
let url = format!("http://{}:{}/api/v0/name/publish?arg={}", self.server, self.port, hash);
let _resp = reqwest::get(&url)?;
let client = reqwest::Client::new();
let _resp = client.post(&url).send()?;
Ok(())
}
}
3 changes: 2 additions & 1 deletion src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ impl IpfsApi {
pub fn log_tail(&self) -> Result<impl Iterator<Item=Value>, Error> {
let mut url = self.get_url()?;
url.set_path("api/v0/log/tail");
let resp = reqwest::get(url)?;
let client = reqwest::Client::new();
let resp = client.post(url).send()?;

let messages = BufReader::new(resp).lines()
.filter(|x|x.is_ok())
Expand Down
3 changes: 2 additions & 1 deletion src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ impl IpfsApi {
/// of a hash.
pub fn object_stats(&self, hash: &str) -> Result<ObjectStats, Error> {
let url = format!("http://{}:{}/api/v0/object/stat?arg={}", self.server, self.port, hash);
let resp = reqwest::get(&url)?;
let client = reqwest::Client::new();
let resp = client.post(&url).send()?;
Ok(serde_json::from_reader(resp)?)
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ impl IpfsApi {
.append_pair("arg", hash)
.append_pair("recursive", &recursive.to_string())
.append_pair("progress", "false");
let resp = reqwest::get(url)?;
let client = reqwest::Client::new();
let resp = client.post(url).send()?;
Ok(serde_json::from_reader(resp)?)
}

Expand All @@ -46,7 +47,8 @@ impl IpfsApi {
url.query_pairs_mut()
.append_pair("arg", hash)
.append_pair("recursive", &recursive.to_string());
let resp = reqwest::get(url)?;
let client = reqwest::Client::new();
let resp = client.post(url).send()?;
Ok(serde_json::from_reader(resp)?)
}

Expand All @@ -55,7 +57,8 @@ impl IpfsApi {
pub fn pin_list(&self) -> Result<Vec<PinnedHash>, Error> {
let mut url = self.get_url()?;
url.set_path("api/v0/pin/ls");
let resp = reqwest::get(url)?;
let client = reqwest::Client::new();
let resp = client.post(url).send()?;
let json_resp: serde_json::Value = serde_json::from_reader(resp)?;

let mut hashes = Vec::new();
Expand Down
6 changes: 4 additions & 2 deletions src/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ impl IpfsApi {
url.query_pairs_mut()
.append_pair("arg", channel)
.append_pair("discover", "true");
let resp = reqwest::get(url)?;
let client = reqwest::Client::new();
let resp = client.post(url).send()?;

let messages = BufReader::new(resp).lines()
.filter(|x|x.is_ok())
Expand Down Expand Up @@ -82,7 +83,8 @@ impl IpfsApi {
url.query_pairs_mut()
.append_pair("arg", channel)
.append_pair("arg", data);
let _resp = reqwest::get(url)?;
let client = reqwest::Client::new();
let _resp = client.post(url).send()?;
Ok(())
}
}
3 changes: 2 additions & 1 deletion src/shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ impl IpfsApi {
pub fn shutdown(&self) -> Result<(), Error> {
let mut url = self.get_url()?;
url.set_path("api/v0/shutdown");
let _resp = reqwest::get(url)?;
let client = reqwest::Client::new();
let _resp = client.post(url).send()?;
Ok(())
}
}
3 changes: 2 additions & 1 deletion src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ impl IpfsApi {
/// Get the version from the IPFS daemon.
pub fn version(&self) -> Result<IpfsVersion, Error> {
let url = format!("http://{}:{}/api/v0/version", self.server, self.port);
let resp = reqwest::get(&url)?;
let client = reqwest::Client::new();
let resp = client.post(&url).send()?;
Ok(serde_json::from_reader(resp)?)
}
}