@@ -201,16 +201,46 @@ public List<Multihash> local() throws IOException {
201
201
/* Pinning an object ensures a local copy of it is kept.
202
202
*/
203
203
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
+ }
204
237
public List <Multihash > add (Multihash hash ) throws IOException {
205
238
return ((List <Object >)((Map )retrieveAndParse ("pin/add?stream-channels=true&arg=" + hash )).get ("Pins" ))
206
239
.stream ()
207
240
.map (x -> Cid .decode ((String ) x ))
208
241
.collect (Collectors .toList ());
209
242
}
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
+
214
244
public Map <Multihash , Object > ls () throws IOException {
215
245
return ls (PinType .direct );
216
246
}
@@ -221,13 +251,6 @@ public Map<Multihash, Object> ls(PinType type) throws IOException {
221
251
.collect (Collectors .toMap (x -> Cid .decode (x .getKey ()), x -> x .getValue ()));
222
252
}
223
253
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
-
231
254
public List <Multihash > rm (Multihash hash ) throws IOException {
232
255
return rm (hash , true );
233
256
}
@@ -237,27 +260,6 @@ public List<Multihash> rm(Multihash hash, boolean recursive) throws IOException
237
260
return ((List <Object >) json .get ("Pins" )).stream ().map (x -> Cid .decode ((String ) x )).collect (Collectors .toList ());
238
261
}
239
262
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
-
261
263
public List <Multihash > update (Multihash existing , Multihash modified , boolean unpin ) throws IOException {
262
264
return ((List <Object >)((Map )retrieveAndParse ("pin/update?stream-channels=true&arg=" + existing + "&arg=" + modified + "&unpin=" + unpin )).get ("Pins" ))
263
265
.stream ()
@@ -839,19 +841,19 @@ public Map disconnect(MultiAddress multiAddr) throws IOException {
839
841
public Map filters () throws IOException {
840
842
return retrieveMap ("swarm/filters" );
841
843
}
842
- public Map filtersAdd (String multiAddrFilter ) throws IOException {
844
+ public Map addFilter (String multiAddrFilter ) throws IOException {
843
845
return retrieveMap ("swarm/filters/add?arg=" +multiAddrFilter );
844
846
}
845
- public Map filtersRm (String multiAddrFilter ) throws IOException {
847
+ public Map rmFilter (String multiAddrFilter ) throws IOException {
846
848
return retrieveMap ("swarm/filters/rm?arg=" +multiAddrFilter );
847
849
}
848
- public Map peeringLs () throws IOException {
850
+ public Map lsPeering () throws IOException {
849
851
return retrieveMap ("swarm/peering/ls" );
850
852
}
851
- public Map peeringAdd (MultiAddress multiAddr ) throws IOException {
853
+ public Map addPeering (MultiAddress multiAddr ) throws IOException {
852
854
return retrieveMap ("swarm/peering/add?arg=" +multiAddr );
853
855
}
854
- public Map peeringRm (Multihash multiAddr ) throws IOException {
856
+ public Map rmPeering (Multihash multiAddr ) throws IOException {
855
857
return retrieveMap ("swarm/peering/rm?arg=" +multiAddr );
856
858
}
857
859
}
0 commit comments