|
13 | 13 | import com.mashape.unirest.request.GetRequest; |
14 | 14 | import com.sybit.airtable.exception.AirtableException; |
15 | 15 | import com.sybit.airtable.exception.HttpResponseExceptionHandler; |
| 16 | +import com.sybit.airtable.vo.Delete; |
16 | 17 | import com.sybit.airtable.vo.RecordItem; |
17 | 18 | import com.sybit.airtable.vo.Records; |
18 | 19 | import org.apache.commons.beanutils.BeanUtils; |
@@ -110,7 +111,7 @@ public String filterByFormula() { |
110 | 111 | * @throws HttpResponseException |
111 | 112 | */ |
112 | 113 | @SuppressWarnings("WeakerAccess") |
113 | | - public List<T> select(Query query) throws AirtableException, HttpResponseException { |
| 114 | + public List<T> select(Query query) throws AirtableException { |
114 | 115 | HttpResponse<Records> response; |
115 | 116 | try { |
116 | 117 | GetRequest request = Unirest.get(getTableEndpointUrl()) |
@@ -272,7 +273,7 @@ private List<T> getList(HttpResponse<Records> response) { |
272 | 273 | * @return searched record. |
273 | 274 | * @throws AirtableException |
274 | 275 | */ |
275 | | - public T find(String id) throws AirtableException, HttpResponseException { |
| 276 | + public T find(String id) throws AirtableException { |
276 | 277 |
|
277 | 278 | RecordItem body = null; |
278 | 279 |
|
@@ -316,10 +317,38 @@ public T replace(T item) { |
316 | 317 |
|
317 | 318 | throw new UnsupportedOperationException("not yet implemented"); |
318 | 319 | } |
| 320 | + |
| 321 | + /** |
| 322 | + * Delete Record by given id |
| 323 | + * |
| 324 | + * @param id |
| 325 | + * @throws AirtableException |
| 326 | + */ |
319 | 327 |
|
320 | | - public T destroy(T item) { |
| 328 | + public void destroy(String id) throws AirtableException { |
| 329 | + |
| 330 | + Delete body = null; |
321 | 331 |
|
322 | | - throw new UnsupportedOperationException("not yet implemented"); |
| 332 | + HttpResponse<Delete> response; |
| 333 | + try { |
| 334 | + response = Unirest.delete(getTableEndpointUrl() + "/" + id) |
| 335 | + .header("accept", "application/json") |
| 336 | + .header("Authorization", getBearerToken()) |
| 337 | + .asObject(Delete.class); |
| 338 | + } catch (UnirestException e) { |
| 339 | + throw new AirtableException(e); |
| 340 | + } |
| 341 | + int code = response.getStatus(); |
| 342 | + |
| 343 | + if(200 == code) { |
| 344 | + body = response.getBody(); |
| 345 | + } else { |
| 346 | + HttpResponseExceptionHandler.onResponse(response); |
| 347 | + } |
| 348 | + |
| 349 | + if(!body.isDeleted()){ |
| 350 | + throw new AirtableException("Record id: "+body.getId()+" could not be deleted."); |
| 351 | + } |
323 | 352 | } |
324 | 353 |
|
325 | 354 | /** |
@@ -423,7 +452,7 @@ private void setProperty(T retval, String key, Object value) throws IllegalAcces |
423 | 452 | private String key2property(String key) { |
424 | 453 |
|
425 | 454 | if(key.contains(" ") || key.contains("-") ) { |
426 | | - LOG.warn( "Annotate special characters using @SerializedName for property: [" + key + "]"); |
| 455 | + LOG.warn( "Annotate columns having special characters by using @SerializedName for property: [" + key + "]"); |
427 | 456 | } |
428 | 457 | String property = key.trim(); |
429 | 458 | property = property.substring(0,1).toLowerCase() + property.substring(1, property.length()); |
|
0 commit comments