Skip to content

Commit

Permalink
Merge pull request gkbrk#4 from icefoxen/pin-add
Browse files Browse the repository at this point in the history
Added /pin/add endpoint call
  • Loading branch information
ferristseng authored Dec 5, 2017
2 parents bd54102 + 2f6025a commit c73d03c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
33 changes: 33 additions & 0 deletions ipfs-api/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,39 @@ impl IpfsClient {
self.request(&request::ObjectStat { key }, None)
}

/// Pins a new object.
///
/// The "recursive" option tells the server whether to
/// pin just the top-level object, or all sub-objects
/// it depends on. For most cases you want it to be `true`.
///
/// Does not yet implement the "progress" agument because
/// reading it is kinda squirrelly.
///
/// # Examples
///
/// ```no_run
/// # extern crate ipfs_api;
/// # extern crate tokio_core;
/// #
/// use ipfs_api::IpfsClient;
/// use tokio_core::reactor::Core;
///
/// # fn main() {
/// let mut core = Core::new().unwrap();
/// let client = IpfsClient::default(&core.handle());
/// let req = client.pin_add("QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", true);
/// # }
/// ```
#[inline]
pub fn pin_add(
&self,
key: &str,
recursive: bool
) -> AsyncResponse<response::PinLsResponse> {
self.request(&request::PinAdd { key, recursive: Some(recursive), progress: false }, None)
}

/// Returns a list of pinned objects in local storage.
///
/// ```no_run
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 c73d03c

Please sign in to comment.