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

Commit c3ddb1d

Browse files
committed
Merge branch 'develop' of https://github.com/Sybit-Education/airtable.java into develop
2 parents ada8b5b + 61445be commit c3ddb1d

8 files changed

Lines changed: 242 additions & 30 deletions

File tree

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ Table<Actor> actorTable = base.table("Actors", Actor.class);
8787
Actor actor = actorTable.find("rec514228ed76ced1");
8888
```
8989

90+
## Destroy
91+
Use Destroy to delete a specific records of table:
92+
93+
+ `table(name).destroy(String id)`: delete record with `id` of table `name`
94+
95+
### Example
96+
```Java
97+
// detailed Example see TableDestroyTest.java
98+
Base base = airtable.base(AIRTABLE_BASE);
99+
Table<Actor> actorTable = base.table("Actors", Actor.class);
100+
actorTable.destroy("recapJ3Js8AEwt0Bf");
101+
```
102+
90103
## Annotations
91104

92105
Use the Gson Annotation @SerializedName to annotate Names which contain - or an emtpy Charakter.
@@ -116,7 +129,7 @@ Use the Gson Annotation @SerializedName to annotate Names which contain - or an
116129

117130
+ [ ] Create Record
118131
+ [ ] Update Record
119-
+ [ ] Delete Record
132+
+ [x] Delete Record
120133
+ [ ] Replace Record
121134
+ General requirements
122135
+ [ ] Automatic ObjectMapping

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

Lines changed: 31 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;
@@ -316,10 +317,38 @@ public T replace(T item) {
316317

317318
throw new UnsupportedOperationException("not yet implemented");
318319
}
320+
321+
/**
322+
* Delete Record by given id
323+
*
324+
* @param id
325+
* @throws AirtableException
326+
*/
319327

320-
public T destroy(T item) {
328+
public void destroy(String id) throws AirtableException {
329+
330+
Delete body = null;
321331

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+
}
323352
}
324353

325354
/**
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)