Skip to content

Commit 6deee24

Browse files
author
Kevin Burke
committed
Adds ability to delete a transcription
Also adds a test
1 parent 7428342 commit 6deee24

File tree

3 files changed

+49
-19
lines changed

3 files changed

+49
-19
lines changed

src/main/java/com/twilio/sdk/TwilioRestResponse.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ public class TwilioRestResponse {
4444

4545
/** The response text. */
4646
private String responseText;
47-
47+
4848
/** The http status. */
4949
private int httpStatus;
50-
50+
5151
/** The url. */
5252
private String url;
53-
53+
5454
/** The query string. */
5555
private String queryString;
56-
56+
5757
/** The error. */
5858
private boolean error;
59-
59+
6060
/** The content type. */
6161
private String contentType;
6262

@@ -81,7 +81,7 @@ public TwilioRestResponse(String url, String text, int status) {
8181

8282
/**
8383
* Get the raw response body as a String
84-
*
84+
*
8585
* @return the response body
8686
*/
8787
public String getResponseText() {
@@ -100,7 +100,7 @@ public void setResponseText(String responseText) {
100100
/**
101101
102102
* Get the http status code associated with this response.
103-
*
103+
*
104104
* @return the int value of the response status
105105
*/
106106
public int getHttpStatus() {
@@ -118,7 +118,7 @@ public void setHttpStatus(int httpStatus) {
118118

119119
/**
120120
* Get the url that resulted in this response
121-
*
121+
*
122122
* @return the url
123123
*/
124124
public String getUrl() {
@@ -136,7 +136,7 @@ public void setUrl(String url) {
136136

137137
/**
138138
* Get the query string that resulted in this response
139-
*
139+
*
140140
*/
141141
public String getQueryString() {
142142
return queryString;
@@ -153,7 +153,7 @@ public void setQueryString(String queryString) {
153153

154154
/**
155155
* Determine if this request resulted in any kind of error
156-
*
156+
*
157157
* @return true if an error occured
158158
*/
159159
public boolean isError() {
@@ -171,7 +171,7 @@ public void setError(boolean error) {
171171

172172
/**
173173
* Determines if the response was a client side error (HTTP 4XX status)
174-
*
174+
*
175175
* @return true if this was a client error
176176
*/
177177
public boolean isClientError() {
@@ -180,7 +180,7 @@ public boolean isClientError() {
180180

181181
/**
182182
* Determines if the response was a server side error (HTTP 5XX status)
183-
*
183+
*
184184
* @return true if this was a server error
185185
*/
186186
public boolean isServerError() {
@@ -198,7 +198,7 @@ public void setContentType(String contentType) {
198198

199199
/**
200200
* Method to determine if the response content type was a JSON type
201-
*
201+
*
202202
* @return true if this looks like a JSON response
203203
*/
204204
public boolean isJson() {
@@ -207,7 +207,7 @@ public boolean isJson() {
207207

208208
/**
209209
* Method to determine if the response content type was an XML type
210-
*
210+
*
211211
* @return true if this looks like an XML response
212212
*/
213213
public boolean isXml() {
@@ -217,7 +217,7 @@ public boolean isXml() {
217217

218218
/**
219219
* Get an appropriate response parser for this response type
220-
*
220+
*
221221
* @return a response parser capable of parsing this response body.
222222
*/
223223
public ResponseParser getParser() {
@@ -235,7 +235,7 @@ public ResponseParser getParser() {
235235
* Helper method to convert the response to a canonical object map. This
236236
* method will use the appropriate parser to map the response body to a Map
237237
* of elements.
238-
*
238+
*
239239
* @return a normalized Map of objects. Repeated elements are List values,
240240
* sub-objects are Map values. All other types are String values.
241241
*/

src/main/java/com/twilio/sdk/resource/instance/Transcription.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
55
import java.util.Date;
66
import java.util.Map;
77

8+
import com.twilio.sdk.TwilioRestException;
89
import com.twilio.sdk.TwilioRestClient;
10+
import com.twilio.sdk.TwilioRestResponse;
911
import com.twilio.sdk.resource.InstanceResource;
1012

1113
/**
1214
* The Class Transcription.
13-
*
15+
*
1416
* For more information see <a href="http://www.twilio.com/docs/api/rest/transcription">http://www.twilio.com/docs/api/rest/transcription</a>
1517
*/
1618
public class Transcription extends InstanceResource {
17-
19+
1820
/** The Constant SID_PROPERTY. */
1921
private static final String SID_PROPERTY = "sid";
2022

@@ -35,7 +37,7 @@ public Transcription(TwilioRestClient client) {
3537
*/
3638
public Transcription(TwilioRestClient client, String sid) {
3739
super(client);
38-
if (sid == null) {
40+
if (sid == null) {
3941
throw new IllegalStateException("The Sid for a Transcription can not be null");
4042
}
4143
this.setProperty(SID_PROPERTY, sid);
@@ -156,4 +158,17 @@ public String getPrice() {
156158
public String getTranscriptionText() {
157159
return this.getProperty("transcription_text");
158160
}
161+
162+
/**
163+
* Delete this Transcription
164+
*
165+
* @return true, if successful
166+
* @throws TwilioRestException the twilio rest exception
167+
*/
168+
public boolean delete() throws TwilioRestException {
169+
TwilioRestResponse response = this.getClient().safeRequest(
170+
this.getResourceLocation(), "DELETE", null);
171+
172+
return !response.isError();
173+
}
159174
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.twilio.sdk.resource.instance;
2+
3+
import com.twilio.sdk.resource.instance.Transcription;
4+
import org.junit.Test;
5+
import static org.junit.Assert.assertTrue;
6+
public class TranscriptionTest extends BasicRequestTester {
7+
8+
@Test
9+
public void testDeleteTranscription() throws Exception {
10+
setExpectedServerAnswer(null);
11+
setExpectedServerReturnCode(204);
12+
Transcription tr = new Transcription(client, "TR5f539674e9b84c2ba39a4156f264a347");
13+
assertTrue(tr.delete());
14+
}
15+
}

0 commit comments

Comments
 (0)