Skip to content
This repository was archived by the owner on Mar 31, 2025. It is now read-only.

Commit ceb8199

Browse files
fzrfzr
authored andcommitted
Implemented Destroy Method with Tests
Added Test Specific Files, New Class Delete to handle Delete Responses, Implemented Method in Table, Added Attributes to Actor Class
1 parent 95db26f commit ceb8199

7 files changed

Lines changed: 221 additions & 29 deletions

File tree

src/main/java/com/sybit/airtable/Table.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.mashape.unirest.request.GetRequest;
1414
import com.sybit.airtable.exception.AirtableException;
1515
import com.sybit.airtable.exception.HttpResponseExceptionHandler;
16+
import com.sybit.airtable.vo.Delete;
1617
import com.sybit.airtable.vo.RecordItem;
1718
import com.sybit.airtable.vo.Records;
1819
import org.apache.commons.beanutils.BeanUtils;
@@ -317,9 +318,30 @@ public T replace(T item) {
317318
throw new UnsupportedOperationException("not yet implemented");
318319
}
319320

320-
public T destroy(T item) {
321+
public void destroy(String id) throws AirtableException {
322+
323+
Delete body = null;
321324

322-
throw new UnsupportedOperationException("not yet implemented");
325+
HttpResponse<Delete> response;
326+
try {
327+
response = Unirest.delete(getTableEndpointUrl() + "/" + id)
328+
.header("accept", "application/json")
329+
.header("Authorization", getBearerToken())
330+
.asObject(Delete.class);
331+
} catch (UnirestException e) {
332+
throw new AirtableException(e);
333+
}
334+
int code = response.getStatus();
335+
336+
if(200 == code) {
337+
body = response.getBody();
338+
} else {
339+
HttpResponseExceptionHandler.onResponse(response);
340+
}
341+
342+
if(!body.isDeleted()){
343+
throw new AirtableException("Record id: "+body.getId()+" could not be deleted.");
344+
}
323345
}
324346

325347
/**
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.sybit.airtable.vo;
7+
8+
/**
9+
*
10+
* @author fzr
11+
*/
12+
public class Delete {
13+
14+
private boolean deleted;
15+
private String id;
16+
17+
/**
18+
* @return the deleted
19+
*/
20+
public boolean isDeleted() {
21+
return deleted;
22+
}
23+
24+
/**
25+
* @param deleted the deleted to set
26+
*/
27+
public void setDeleted(boolean deleted) {
28+
this.deleted = deleted;
29+
}
30+
31+
/**
32+
* @return the id
33+
*/
34+
public String getId() {
35+
return id;
36+
}
37+
38+
/**
39+
* @param id the id to set
40+
*/
41+
public void setId(String id) {
42+
this.id = id;
43+
}
44+
45+
46+
47+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.sybit.airtable;
7+
8+
import com.sybit.airtable.exception.AirtableException;
9+
import com.sybit.airtable.movies.Actor;
10+
import com.sybit.airtable.test.WireMockBaseTest;
11+
import java.util.List;
12+
import org.apache.http.client.HttpResponseException;
13+
import static org.junit.Assert.assertEquals;
14+
import org.junit.Test;
15+
16+
/**
17+
*
18+
* @author fzr
19+
*/
20+
public class TableDestroyTest extends WireMockBaseTest {
21+
22+
23+
24+
@Test
25+
public void testDestroyMovie() throws AirtableException, HttpResponseException{
26+
27+
Base base = airtable.base("appe9941ff07fffcc");
28+
Table<Actor> actorTable = base.table("Actors", Actor.class);
29+
30+
actorTable.destroy("recapJ3Js8AEwt0Bf");
31+
32+
}
33+
34+
@Test (expected = AirtableException.class)
35+
public void testDestroyMovieException() throws AirtableException{
36+
37+
Base base = airtable.base("appe9941ff07fffcc");
38+
Table<Actor> actorTable = base.table("Actors", Actor.class);
39+
40+
actorTable.destroy("not succesfull");
41+
}
42+
43+
}

src/test/java/com/sybit/airtable/movies/Actor.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@
66
*/
77
package com.sybit.airtable.movies;
88

9-
import com.google.gson.annotations.SerializedName;
9+
10+
import com.sybit.airtable.vo.Attachment;
11+
import java.util.List;
1012

1113
public class Actor {
1214

1315
private String id;
14-
@SerializedName("Name")
1516
private String name;
17+
private List<Attachment> Photo;
18+
private String Biography;
19+
private String[] Filmography;
20+
21+
1622

1723
public String getId() {
1824
return id;
@@ -29,4 +35,30 @@ public String getName() {
2935
public void setName(String name) {
3036
this.name = name;
3137
}
38+
39+
public String[] getFilmography() {
40+
return Filmography;
41+
}
42+
43+
public void setFilmography(String[] Filmography) {
44+
this.Filmography = Filmography;
45+
}
46+
47+
public List<Attachment> getPhoto() {
48+
return Photo;
49+
}
50+
51+
public void setPhoto(List<Attachment> Photo) {
52+
this.Photo = Photo;
53+
}
54+
55+
public String getBiography() {
56+
return Biography;
57+
}
58+
59+
public void setBiography(String Biography) {
60+
this.Biography = Biography;
61+
}
62+
63+
3264
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"deleted": true,
3+
"id": "recapJ3Js8AEwt0Bf"
4+
}
Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,62 @@
11
{
2-
"id": "rec514228ed76ced1",
3-
"fields": {
4-
"Name": "Marlon Brando",
5-
"Filmography": [
6-
"rec6733da527dd0f1"
7-
],
8-
"Photo": [
9-
{
10-
"id": "att1b7c05d697c0c1",
11-
"url": "https://www.filepicker.io/api/file/xlhctgHEQiSGNc0ieMec",
12-
"filename": "220px-Marlon_Brando_-_The_Wild_One.jpg",
13-
"size": 13845,
14-
"type": "image/jpeg",
15-
"thumbnails": {
16-
"small": {
17-
"url": "https://www.filepicker.io/api/file/Rh3L1DL7QAe8nleanQVV"
18-
},
19-
"large": {
20-
"url": "https://www.filepicker.io/api/file/hcrLCStVRX6LNVEHqtXA"
21-
}
2+
"records": [
3+
{
4+
"id": "rec514228ed76ced1",
5+
"fields": {
6+
"Name": "Marlon Brando",
7+
"Filmography": [
8+
"rec6733da527dd0f1"
9+
],
10+
"Photo": [
11+
{
12+
"id": "att1b7c05d697c0c1",
13+
"url": "https://www.filepicker.io/api/file/xlhctgHEQiSGNc0ieMec",
14+
"filename": "220px-Marlon_Brando_-_The_Wild_One.jpg",
15+
"size": 13845,
16+
"type": "image/jpeg",
17+
"thumbnails": {
18+
"small": {
19+
"url": "https://www.filepicker.io/api/file/Rh3L1DL7QAe8nleanQVV"
20+
},
21+
"large": {
22+
"url": "https://www.filepicker.io/api/file/hcrLCStVRX6LNVEHqtXA"
23+
}
24+
}
25+
}
26+
],
27+
"Biography": "Marlon Brando, Jr. (April 3, 1924 – July 1, 2004) was an American actor. He is hailed for bringing a gripping realism to film acting, and is widely co..."
28+
},
29+
"createdTime": "2014-07-18T04:48:25.000Z"
30+
},
31+
{
32+
"id":"recapJ3Js8AEwt0Bf",
33+
"fields": {
34+
"Name":"Test Actor",
35+
"Photo": [
36+
{
37+
"id":"attfbHPN3hRjTYk3U",
38+
"url":"https://dl.airtable.com/eJd6UGPPTmGPvoTjpP57_Penguins.jpg",
39+
"filename":"Penguins.jpg","size":777835,"type":"image/jpeg",
40+
"thumbnails": {
41+
"small": {
42+
"url":"https://dl.airtable.com/mzOeWfo7RkiX8ueW14gi_small_Penguins.jpg",
43+
"width":48,
44+
"height":36
45+
},
46+
"large": {
47+
"url":"https://dl.airtable.com/dMgnXtMrSDKSAQTQqYHa_large_Penguins.jpg",
48+
"width":512,
49+
"height":512
50+
}
51+
}
52+
}
53+
],
54+
"Biography":"Test Bio",
55+
"Filmography": [
56+
"rec6733da527dd0f1"
57+
]
58+
},
59+
"createdTime":"2017-03-30T06:47:38.520Z"
2260
}
23-
}
24-
],
25-
"Biography": "Marlon Brando, Jr. (April 3, 1924 – July 1, 2004) was an American actor. He is hailed for bringing a gripping realism to film acting, and is widely co..."
26-
},
27-
"createdTime": "2014-07-18T04:48:25.000Z"
61+
]
2862
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"request" : {
3+
"url" : "/v0/appe9941ff07fffcc/Actors/recapJ3Js8AEwt0Bf",
4+
"method" : "DELETE"
5+
},
6+
"response" : {
7+
"status" : 200,
8+
"bodyFileName" : "/body-ActorDelete.json"
9+
}
10+
}

0 commit comments

Comments
 (0)