Skip to content

Commit e1fefe6

Browse files
committed
#61 added support for delete droplet by tag name api
1 parent 4f8d2f8 commit e1fefe6

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

src/main/java/com/myjeeva/digitalocean/DigitalOcean.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,20 @@ Droplets createDroplets(Droplet droplet)
276276
Delete deleteDroplet(Integer dropletId)
277277
throws DigitalOceanException, RequestUnsuccessfulException;
278278

279+
/**
280+
* Method destroys one or more of your droplet by given tag name; this is irreversible.
281+
*
282+
* @param tagName the associated tag name with droplet
283+
* @return {@link Delete}
284+
* @throws DigitalOceanException if request had interruption [
285+
* <code>HTTP status code &gt;= 400 &amp;&amp; &lt; 510</code>]
286+
* @throws RequestUnsuccessfulException if any RESTful request unsuccessful from wrapper method
287+
*
288+
* @since v2.9
289+
*/
290+
Delete deleteDropletByTagName(String tagName)
291+
throws DigitalOceanException, RequestUnsuccessfulException;
292+
279293
/**
280294
* For an individual droplet; Method retrieves a list of droplets that are running on the same
281295
* physical server (any other droplets that share the same physical hardware).

src/main/java/com/myjeeva/digitalocean/common/ApiAction.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public enum ApiAction {
6969
CREATE_DROPLET("/droplets", "droplet", RequestMethod.POST, Droplet.class),
7070
CREATE_DROPLETS("/droplets", "droplets", RequestMethod.POST, Droplets.class),
7171
DELETE_DROPLET("/droplets/%s", "response", RequestMethod.DELETE, Delete.class),
72+
DELETE_DROPLET_BY_TAG_NAME("/droplets", "response", RequestMethod.DELETE, Delete.class),
7273
REBOOT_DROPLET("/droplets/%s/actions", "action", RequestMethod.POST, Action.class),
7374
POWER_CYCLE_DROPLET("/droplets/%s/actions", "action", RequestMethod.POST, Action.class),
7475
SHUTDOWN_DROPLET("/droplets/%s/actions", "action", RequestMethod.POST, Action.class),

src/main/java/com/myjeeva/digitalocean/impl/DigitalOceanClient.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,16 @@ public Delete deleteDroplet(Integer dropletId) throws DigitalOceanException,
331331
return (Delete) perform(new ApiRequest(ApiAction.DELETE_DROPLET, params)).getData();
332332
}
333333

334+
@Override
335+
public Delete deleteDropletByTagName(String tagName)
336+
throws DigitalOceanException, RequestUnsuccessfulException {
337+
checkEmptyAndThrowError(tagName, "Missing required parameter - tagName.");
338+
339+
Map<String, String> queryParams = new HashMap<String, String>();
340+
queryParams.put("tag_name", tagName);
341+
return (Delete) perform(new ApiRequest(ApiAction.DELETE_DROPLET_BY_TAG_NAME, null, queryParams, null)).getData();
342+
}
343+
334344
@Override
335345
public Droplets getDropletNeighbors(Integer dropletId, Integer pageNo)
336346
throws DigitalOceanException, RequestUnsuccessfulException {

src/test/java/com/myjeeva/digitalocean/DigitalOceanIntegrationTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,16 @@ public void testDeleteDroplet() throws DigitalOceanException, RequestUnsuccessfu
263263
LOG.info("Delete Request Object: " + result);
264264
}
265265

266+
@Test
267+
public void testDeleteDropletByTagName()
268+
throws DigitalOceanException, RequestUnsuccessfulException {
269+
270+
Delete result = apiClient.deleteDropletByTagName("delete-me");
271+
272+
assertNotNull(result);
273+
LOG.info("Delete by tag name Request Object: " + result);
274+
}
275+
266276
@Test
267277
public void testGetDropletNeighbors() throws DigitalOceanException, RequestUnsuccessfulException {
268278

0 commit comments

Comments
 (0)