Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/java/cloud/dnation/hetznerclient/HetznerApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
* For full version, check <a href="https://docs.hetzner.cloud/">official documentation</a>
*/
public interface HetznerApi {

/**
* Get/poll the status of an asynchronous API on the Hetzner Cloud.
* <p>Normally, the rate limit of this API is higher and separate from the other API calls,
* as it is preferred to poll the /actions endpoint to wait for an asynchronous action to complete.</p>
* @param actionId the ID of the action whose status you want to poll
* @return the full Action object, including its current status
*/
@GET("/v1/actions/{id}")
Call<ActionResponse> getActionById(@Path("id") Long actionId);

/**
* Get all images that matches given label expression.
*
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/cloud/dnation/hetznerclient/BasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ public static void tearDownAfterClass() throws IOException {
ws.close();
}

@Test
public void testGetActionById() throws IOException {
ws.enqueue(new MockResponse()
.setBody(resourceAsString("get-action-by-id.json"))
);
Call<ActionResponse> call = api.getActionById(603984077612933L);
ActionResponse result = call.execute().body();
assertEquals("delete_server", result.getAction().getCommand());
assertEquals(100, result.getAction().getProgress().intValue());
assertEquals("success", result.getAction().getStatus());
assertNull(result.getAction().getError());
List<IdentifiableResource> relatedResources = result.getAction().getResources();
assertEquals(1, relatedResources.size());
assertEquals(117017457L, relatedResources.get(0).getId().longValue());
}

@Test
public void testGetNetworkById() throws IOException {
ws.enqueue(new MockResponse()
Expand Down
17 changes: 17 additions & 0 deletions src/test/resources/get-action-by-id.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"action": {
"id": 603984077612933,
"command": "delete_server",
"started": "2026-01-08T17:33:08Z",
"finished": "2026-01-08T17:33:13Z",
"progress": 100,
"status": "success",
"resources": [
{
"id": 117017457,
"type": "server"
}
],
"error": null
}
}