Skip to content

Commit 184ce3b

Browse files
committed
feat: Added ResourceDeleter
1 parent 2095d29 commit 184ce3b

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.twilio.base;
2+
3+
import com.twilio.Twilio;
4+
import com.twilio.http.TwilioRestClient;
5+
6+
import java.util.concurrent.CompletableFuture;
7+
8+
/**
9+
* Executor for deletes of a resource that return a response object.
10+
*
11+
* @param <T> type of the resource
12+
* @param <R> type of the delete response
13+
*/
14+
public abstract class ResourceDeleter<T extends Resource, R extends Resource> {
15+
16+
public CompletableFuture<R> deleteAsync() {
17+
return deleteAsync(Twilio.getRestClient());
18+
}
19+
20+
public CompletableFuture<R> deleteAsync(final TwilioRestClient client) {
21+
return CompletableFuture.supplyAsync(() -> delete(client), Twilio.getExecutorService());
22+
}
23+
24+
public R delete() {
25+
return delete(Twilio.getRestClient());
26+
}
27+
28+
public abstract R delete(final TwilioRestClient client);
29+
30+
public TwilioResponse<R> deleteWithResponse() {
31+
return deleteWithResponse(Twilio.getRestClient());
32+
}
33+
34+
public TwilioResponse<R> deleteWithResponse(final TwilioRestClient client) {
35+
throw new UnsupportedOperationException("deleteWithResponse is not supported for this resource.");
36+
}
37+
}

src/main/java/com/twilio/rest/numbers/v3/HostedNumberOrder.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.io.IOException;
3131
import java.io.IOException;
3232
import java.io.InputStream;
33+
import java.util.Objects;
3334
import lombok.ToString;
3435

3536
@JsonIgnoreProperties(ignoreUnknown = true)
@@ -104,6 +105,47 @@ public int hashCode() {
104105
}
105106
}
106107

108+
@JsonIgnoreProperties(ignoreUnknown = true)
109+
static class DeleteHostedNumberOrderResponse extends Resource {
110+
111+
@JsonCreator
112+
private DeleteHostedNumberOrderResponse() {}
113+
114+
public static DeleteHostedNumberOrderResponse fromJson(
115+
final InputStream json,
116+
final ObjectMapper objectMapper
117+
) {
118+
// Convert all checked exceptions to Runtime
119+
try {
120+
return objectMapper.readValue(
121+
json,
122+
DeleteHostedNumberOrderResponse.class
123+
);
124+
} catch (final JsonMappingException | JsonParseException e) {
125+
throw new ApiException(e.getMessage(), e);
126+
} catch (final IOException e) {
127+
throw new ApiConnectionException(e.getMessage(), e);
128+
}
129+
}
130+
131+
@Override
132+
public boolean equals(final Object o) {
133+
if (this == o) {
134+
return true;
135+
}
136+
137+
if (o == null || getClass() != o.getClass()) {
138+
return false;
139+
}
140+
return true;
141+
}
142+
143+
@Override
144+
public int hashCode() {
145+
return Objects.hash();
146+
}
147+
}
148+
107149
@JsonIgnoreProperties(ignoreUnknown = true)
108150
static class ListHostedNumberOrderResponse extends Resource {
109151

src/main/java/com/twilio/rest/studio/v2/flow/ExecutionReader.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
public class ExecutionReader extends Reader<Execution> {
3838

3939
private String pathFlowSid;
40+
private Execution.Status status;
4041
private ZonedDateTime dateCreatedFrom;
4142
private ZonedDateTime dateCreatedTo;
4243
private Long pageSize;
@@ -45,6 +46,11 @@ public ExecutionReader(final String pathFlowSid) {
4546
this.pathFlowSid = pathFlowSid;
4647
}
4748

49+
public ExecutionReader setStatus(final Execution.Status status) {
50+
this.status = status;
51+
return this;
52+
}
53+
4854
public ExecutionReader setDateCreatedFrom(
4955
final ZonedDateTime dateCreatedFrom
5056
) {
@@ -206,6 +212,10 @@ public Page<Execution> getPage(
206212
}
207213

208214
private void addQueryParams(final Request request) {
215+
if (status != null) {
216+
Serializer.toString(request, "status", status, ParameterType.QUERY);
217+
}
218+
209219
if (dateCreatedFrom != null) {
210220
Serializer.toString(
211221
request,

0 commit comments

Comments
 (0)