Skip to content

Commit

Permalink
Added /pin/add endpoint call
Browse files Browse the repository at this point in the history
  • Loading branch information
icefoxen committed Nov 30, 2017
1 parent f66a1b5 commit 251b04e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ipfs-api/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,19 @@ impl IpfsClient {
self.request(&request::ObjectStat { key }, None)
}

/// Pins a new object.
///
/// Does not yet implement "progress" because reading it is kinda squirrelly.
///
#[inline]
pub fn pin_add(
&self,
key: &str,
recursive: Option<bool>
) -> AsyncResponse<response::PinLsResponse> {
self.request(&request::PinAdd { key, recursive, progress: false }, None)
}

/// Returns a list of pinned objects in local storage.
///
#[inline]
Expand Down
16 changes: 16 additions & 0 deletions ipfs-api/src/request/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@
use request::ApiRequest;


#[derive(Serialize)]
pub struct PinAdd<'a> {
#[serde(rename = "arg")]
pub key: &'a str,
pub recursive: Option<bool>,
pub progress: bool,
}

impl<'a> ApiRequest for PinAdd<'a> {
#[inline]
fn path() -> &'static str {
"/pin/add"
}
}


#[derive(Serialize)]
pub struct PinLs<'a> {
#[serde(rename = "arg")]
Expand Down
2 changes: 2 additions & 0 deletions ipfs-api/src/response/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct PinType {
}



#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct PinLsResponse {
Expand All @@ -47,4 +48,5 @@ pub struct PinRmResponse {
#[cfg(test)]
mod tests {
deserialize_test!(v0_pin_ls_0, PinLsResponse);
deserialize_test!(v0_pin_add_0, PinAddResponse);
}
5 changes: 5 additions & 0 deletions ipfs-api/src/response/tests/v0_pin_add_0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Pins": [
"QmQ5vhrL7uv6tuoN9KeVBwd4PwfQkXdVVmDLUZuTNxqgvm"
]
}

0 comments on commit 251b04e

Please sign in to comment.