@@ -201,16 +201,46 @@ public List<Multihash> local() throws IOException {
201201 /* Pinning an object ensures a local copy of it is kept.
202202 */
203203 public class Pin {
204+ public final Remote remote = new Remote ();
205+
206+ public class Remote {
207+ public Map add (String service , Multihash hash , Optional <String > name , boolean background ) throws IOException {
208+ String nameArg = name .isPresent () ? "&name=" + name .get () : "" ;
209+ return retrieveMap ("pin/remote/add?arg=" + hash + "&service=" + service + nameArg + "&background=" + background );
210+ }
211+ public Map ls (String service , Optional <String > name , Optional <List <PinStatus >> statusList ) throws IOException {
212+ String nameArg = name .isPresent () ? "&name=" + name .get () : "" ;
213+ String statusArg = statusList .isPresent () ? statusList .get ().stream ().
214+ map (p -> "&status=" + p ).collect (Collectors .joining ()) : "" ;
215+ return retrieveMap ("pin/remote/ls?service=" + service + nameArg + statusArg );
216+ }
217+ public String rm (String service , Optional <String > name , Optional <List <PinStatus >> statusList , Optional <List <Multihash >> cidList ) throws IOException {
218+ String nameArg = name .isPresent () ? "&name=" + name .get () : "" ;
219+ String statusArg = statusList .isPresent () ? statusList .get ().stream ().
220+ map (p -> "&status=" + p ).collect (Collectors .joining ()) : "" ;
221+ String cidArg = cidList .isPresent () ? cidList .get ().stream ().
222+ map (p -> "&cid=" + p .toBase58 ()).collect (Collectors .joining ()) : "" ;
223+ return retrieveString ("pin/remote/rm?service=" + service + nameArg + statusArg + cidArg );
224+ }
225+ public String addService (String service , String endPoint , String key ) throws IOException {
226+ return retrieveString ("pin/remote/service/add?arg=" + service + "&arg=" + endPoint + "&arg=" + key );
227+ }
228+
229+ public Map lsService (boolean stat ) throws IOException {
230+ return retrieveMap ("pin/remote/service/ls?stat=" + stat );
231+ }
232+
233+ public String rmService (String service ) throws IOException {
234+ return retrieveString ("pin/remote/service/rm?arg=" + service );
235+ }
236+ }
204237 public List <Multihash > add (Multihash hash ) throws IOException {
205238 return ((List <Object >)((Map )retrieveAndParse ("pin/add?stream-channels=true&arg=" + hash )).get ("Pins" ))
206239 .stream ()
207240 .map (x -> Cid .decode ((String ) x ))
208241 .collect (Collectors .toList ());
209242 }
210- public Map addRemote (String service , Multihash hash , Optional <String > name , boolean background ) throws IOException {
211- String nameArg = name .isPresent () ? "&name=" + name .get () : "" ;
212- return retrieveMap ("pin/remote/add?arg=" + hash + "&service=" + service + nameArg + "&background=" + background );
213- }
243+
214244 public Map <Multihash , Object > ls () throws IOException {
215245 return ls (PinType .direct );
216246 }
@@ -221,13 +251,6 @@ public Map<Multihash, Object> ls(PinType type) throws IOException {
221251 .collect (Collectors .toMap (x -> Cid .decode (x .getKey ()), x -> x .getValue ()));
222252 }
223253
224- public Map lsRemote (String service , Optional <String > name , Optional <List <PinStatus >> statusList ) throws IOException {
225- String nameArg = name .isPresent () ? "&name=" + name .get () : "" ;
226- String statusArg = statusList .isPresent () ? statusList .get ().stream ().
227- map (p -> "&status=" + p ).collect (Collectors .joining ()) : "" ;
228- return retrieveMap ("pin/remote/ls?service=" + service + nameArg + statusArg );
229- }
230-
231254 public List <Multihash > rm (Multihash hash ) throws IOException {
232255 return rm (hash , true );
233256 }
@@ -237,27 +260,6 @@ public List<Multihash> rm(Multihash hash, boolean recursive) throws IOException
237260 return ((List <Object >) json .get ("Pins" )).stream ().map (x -> Cid .decode ((String ) x )).collect (Collectors .toList ());
238261 }
239262
240- public String rmRemote (String service , Optional <String > name , Optional <List <PinStatus >> statusList , Optional <List <Multihash >> cidList ) throws IOException {
241- String nameArg = name .isPresent () ? "&name=" + name .get () : "" ;
242- String statusArg = statusList .isPresent () ? statusList .get ().stream ().
243- map (p -> "&status=" + p ).collect (Collectors .joining ()) : "" ;
244- String cidArg = cidList .isPresent () ? cidList .get ().stream ().
245- map (p -> "&cid=" + p .toBase58 ()).collect (Collectors .joining ()) : "" ;
246- return retrieveString ("pin/remote/rm?service=" + service + nameArg + statusArg + cidArg );
247- }
248-
249- public String addRemoteService (String service , String endPoint , String key ) throws IOException {
250- return retrieveString ("pin/remote/service/add?arg=" + service + "&arg=" + endPoint + "&arg=" + key );
251- }
252-
253- public Map lsRemoteService (boolean stat ) throws IOException {
254- return retrieveMap ("pin/remote/service/ls?stat=" + stat );
255- }
256-
257- public String rmRemoteService (String service ) throws IOException {
258- return retrieveString ("pin/remote/service/rm?arg=" + service );
259- }
260-
261263 public List <Multihash > update (Multihash existing , Multihash modified , boolean unpin ) throws IOException {
262264 return ((List <Object >)((Map )retrieveAndParse ("pin/update?stream-channels=true&arg=" + existing + "&arg=" + modified + "&unpin=" + unpin )).get ("Pins" ))
263265 .stream ()
@@ -839,19 +841,19 @@ public Map disconnect(MultiAddress multiAddr) throws IOException {
839841 public Map filters () throws IOException {
840842 return retrieveMap ("swarm/filters" );
841843 }
842- public Map filtersAdd (String multiAddrFilter ) throws IOException {
844+ public Map addFilter (String multiAddrFilter ) throws IOException {
843845 return retrieveMap ("swarm/filters/add?arg=" +multiAddrFilter );
844846 }
845- public Map filtersRm (String multiAddrFilter ) throws IOException {
847+ public Map rmFilter (String multiAddrFilter ) throws IOException {
846848 return retrieveMap ("swarm/filters/rm?arg=" +multiAddrFilter );
847849 }
848- public Map peeringLs () throws IOException {
850+ public Map lsPeering () throws IOException {
849851 return retrieveMap ("swarm/peering/ls" );
850852 }
851- public Map peeringAdd (MultiAddress multiAddr ) throws IOException {
853+ public Map addPeering (MultiAddress multiAddr ) throws IOException {
852854 return retrieveMap ("swarm/peering/add?arg=" +multiAddr );
853855 }
854- public Map peeringRm (Multihash multiAddr ) throws IOException {
856+ public Map rmPeering (Multihash multiAddr ) throws IOException {
855857 return retrieveMap ("swarm/peering/rm?arg=" +multiAddr );
856858 }
857859 }
0 commit comments