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

Commit 2fc6046

Browse files
authored
Merge pull request #28 from Sybit-Education/develop
Feature enhancements: offset loading, destroy
2 parents 5d0f9da + 002e0a7 commit 2fc6046

File tree

171 files changed

+1967
-4621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+1967
-4621
lines changed

README.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
# Airtable.java
99

10-
Java API for Airtable (http://www.airtable.com). The Airtable API provides a simple way of accessing your data within your Java project.
10+
This is a Java API client for Airtable (http://www.airtable.com).
11+
12+
The Airtable API provides a simple way of accessing data within Java projects.
1113

1214
More information about the Airtable API could be found at [https://airtable.com/api](https://airtable.com/api).
1315
The documentation will provide detailed information about your created base.
@@ -227,7 +229,7 @@ List<Movie> listMovies = movieTable.select(sort);
227229
```
228230
If you set the view parameter, the returned records in that view will be sorted by these fields.
229231

230-
Detailed example see [TableParameterTest](https://github.com/Sybit-Education/airtable.java/blob/develop/src/test/java/com/sybit/airtable/TableParameterTest.java)
232+
Detailed example see [TableParameterTest](https://github.com/Sybit-Education/airtable.java/blob/develop/src/itest/java/com/sybit/airtable/TableParameterTest.java)
231233

232234

233235
## CRUD-Operations on Table Records
@@ -249,7 +251,11 @@ Base base = new Airtable().base("AIRTABLE_BASE");
249251
List<Movie> retval = base.table("Movies", Movie.class).select();
250252
```
251253

252-
Detailed example see [TableSelectTest.java](https://github.com/Sybit-Education/airtable.java/blob/develop/src/test/java/com/sybit/airtable/TableSelectTest.java)
254+
Detailed example see [TableSelectTest.java](https://github.com/Sybit-Education/airtable.java/blob/develop/src/itest/java/com/sybit/airtable/TableSelectTest.java)
255+
256+
### API Result Limitation
257+
The REST-API of Airtable is limited to return max. 100 records. If the select has more than 100 records in result an `offest` is added to
258+
returned data. The Airtable.java client will solve this and tries to load the offset data automatically.
253259

254260
## Find
255261
Use `find` to get specific records of table:
@@ -263,7 +269,7 @@ Table<Actor> actorTable = base.table("Actors", Actor.class);
263269
Actor actor = actorTable.find("rec514228ed76ced1");
264270
```
265271

266-
Detailed example see [TableFindTest.java](https://github.com/Sybit-Education/airtable.java/blob/develop/src/test/java/com/sybit/airtable/TableFindTest.java)
272+
Detailed example see [TableFindTest.java](https://github.com/Sybit-Education/airtable.java/blob/develop/src/itest/java/com/sybit/airtable/TableFindTest.java)
267273

268274
## Destroy
269275
Use `destroy` to delete a specific records of table:
@@ -276,7 +282,7 @@ Base base = airtable.base("AIRTABLE_BASE");
276282
Table<Actor> actorTable = base.table("Actors", Actor.class);
277283
actorTable.destroy("recapJ3Js8AEwt0Bf");
278284
```
279-
Detailed example see [TableDestroyTest.java](https://github.com/Sybit-Education/airtable.java/blob/develop/src/test/java/com/sybit/airtable/TableDestroyTest.java)
285+
Detailed example see [TableDestroyTest.java](https://github.com/Sybit-Education/airtable.java/blob/develop/src/itest/java/com/sybit/airtable/TableDestroyTest.java)
280286

281287
## Create
282288
First build your record. Then use `create` to generate a specific records of table:
@@ -299,7 +305,7 @@ Actor test = actorTable.create(newActor);
299305

300306
```
301307

302-
Detailed example see [TableDestroyTest.java](https://github.com/Sybit-Education/airtable.java/blob/develop/src/test/java/com/sybit/airtable/TableCreateRecordTest.java)
308+
Detailed example see [TableCreateRecordTest.java](https://github.com/Sybit-Education/airtable.java/blob/develop/src/itest/java/com/sybit/airtable/TableCreateRecordTest.java)
303309

304310
## Update
305311
Use `update` to update a record of table:
@@ -318,7 +324,7 @@ marlonBrando.setName("Marlon Brando");
318324
Actor updated = actorTable.update(marlonBrando);
319325
```
320326

321-
Detailed example see [TableUpdateTest](https://github.com/Sybit-Education/airtable.java/blob/develop/src/test/java/com/sybit/airtable/TableUpdateTest.java)
327+
Detailed example see [TableUpdateTest](https://github.com/Sybit-Education/airtable.java/blob/develop/src/itest/java/com/sybit/airtable/TableUpdateTest.java)
322328

323329
# Roadmap
324330

@@ -333,12 +339,13 @@ Short overview of features, which are supported:
333339
+ [x] SelectAll
334340
+ [x] Queries (`maxRecords`, `sort` & `view` )
335341
+ [x] Support of `filterByFormula`
336-
+ [x] Support of Paging
342+
+ [x] Support of `paging`
343+
+ [x] Support of appending `offset` data
337344

338345
+ [x] Find Record
339-
340346
+ [x] Create Record
341347
+ [x] Update Record
348+
+ [ ] Replace Record (could be done by update)
342349
+ [x] Delete/Destroy Record
343350
+ General requirements
344351
+ [x] Automatic ObjectMapping

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ dependencies {
101101

102102
testCompile group: 'junit', name: 'junit', version:'4.12'
103103
testCompile group: 'commons-io', name: 'commons-io', version:'2.5'
104-
testCompile group: 'com.github.tomakehurst', name: 'wiremock', version:'2.5.1'
104+
testCompile group: 'com.github.tomakehurst', name: 'wiremock', version:'2.8.0'
105105
testCompile group: 'org.slf4j', name: 'slf4j-jdk14', version:'1.7.25'
106106

107107
codacy group: 'com.codacy', name: 'codacy-coverage-reporter', version: '1.0.13'

src/itest/java/com/sybit/airtable/AirtableTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/*
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.
2+
* The MIT License (MIT)
3+
* Copyright (c) 2017 Sybit GmbH
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
56
*/
67
package com.sybit.airtable;
78

src/itest/java/com/sybit/airtable/TableConverterTest.java

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
/*
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.
2+
* The MIT License (MIT)
3+
* Copyright (c) 2017 Sybit GmbH
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
56
*/
67
package com.sybit.airtable;
78

89

9-
import com.sybit.airtable.Base;
10-
import com.sybit.airtable.Table;
1110
import com.sybit.airtable.exception.AirtableException;
12-
import com.sybit.airtable.movies.Actor;
1311
import com.sybit.airtable.movies.Movie;
1412
import com.sybit.airtable.mock.WireMockBaseTest;
1513
import com.sybit.airtable.vo.Attachment;
1614
import com.sybit.airtable.vo.Thumbnail;
17-
import java.util.List;
1815
import java.util.Map;
1916
import org.apache.http.client.HttpResponseException;
2017
import static org.junit.Assert.assertEquals;
@@ -32,15 +29,13 @@ public class TableConverterTest extends WireMockBaseTest {
3229
@Test
3330
public void testConvertMovie() throws AirtableException, HttpResponseException {
3431

35-
Base base = airtable.base("appe9941ff07fffcc");
3632

3733
Table<Movie> movieTable = base.table("Movies", Movie.class);
38-
Movie movie = movieTable.find("rec6733da527dd0f1");
34+
Movie movie = movieTable.find("recFj9J78MLtiFFMz");
3935
assertNotNull(movie);
4036

41-
assertEquals(movie.getId(),"rec6733da527dd0f1");
37+
assertEquals(movie.getId(),"recFj9J78MLtiFFMz");
4238
assertEquals(movie.getName(),"The Godfather");
43-
assertEquals(movie.getDescription(),"The Godfather is a 1972 American crime film film directed by Francis Ford Coppola and produced by Albert S. Ruddy and based on Mario Puzo's best-selli...");
4439
assertEquals(movie.getPhotos().size(),2);
4540
assertEquals(movie.getDirector().size(),1);
4641
assertEquals(movie.getActors().size(),2);
@@ -53,10 +48,8 @@ public void testConvertMovie() throws AirtableException, HttpResponseException {
5348
public void testConvertAttachement() throws AirtableException, HttpResponseException {
5449

5550

56-
Base base = airtable.base("appe9941ff07fffcc");
57-
5851
Table<Movie> movieTable = base.table("Movies", Movie.class);
59-
Movie movie = movieTable.find("rec6733da527dd0f1");
52+
Movie movie = movieTable.find("recFj9J78MLtiFFMz");
6053
assertNotNull(movie);
6154

6255
assertEquals(movie.getPhotos().size(),2);
@@ -66,31 +59,29 @@ public void testConvertAttachement() throws AirtableException, HttpResponseExcep
6659
Attachment photo2 = movie.getPhotos().get(0);
6760
assertNotNull(photo2);
6861

69-
assertEquals(photo1.getId(),"att6dba4af5786df1");
70-
assertEquals(photo1.getUrl(),"https://www.filepicker.io/api/file/akW7wUX7QM66a2hjxb9k");
71-
assertEquals(photo1.getFilename(),"220px-TheGodfatherAlPacinoMarlonBrando.jpg");
72-
assertEquals(photo1.getSize(),16420.0,0);
62+
assertEquals(photo1.getId(),"attk3WY5B28GVcFGU");
63+
assertEquals(photo1.getUrl(),"https://dl.airtable.com/9UhUUeAtSym1PzBdA0q0_AlPacinoandMarlonBrando.jpg");
64+
assertEquals(photo1.getFilename(),"AlPacinoandMarlonBrando.jpg");
65+
assertEquals(photo1.getSize(),35698,0);
7366
assertEquals(photo1.getType(),"image/jpeg");
7467
assertEquals(photo1.getThumbnails().size(),2);
7568

7669
}
7770

7871
@Test
7972
public void testConvertThumbnails() throws AirtableException, HttpResponseException {
80-
81-
Base base = airtable.base("appe9941ff07fffcc");
82-
73+
8374
Table<Movie> movieTable = base.table("Movies", Movie.class);
84-
Movie movie = movieTable.find("rec6733da527dd0f1");
75+
Movie movie = movieTable.find("recFj9J78MLtiFFMz");
8576
assertNotNull(movie);
8677

8778
assertEquals(movie.getPhotos().get(0).getThumbnails().size(),2);
8879
assertEquals(movie.getPhotos().get(1).getThumbnails().size(),2);
8980
Map<String, Thumbnail> thumbnails = movie.getPhotos().get(1).getThumbnails();
9081
Thumbnail thumb = thumbnails.get("small");
91-
assertEquals(thumb.getUrl(),"https://dl.airtable.com/MbdRAn4ZQLuNyUqrHONp_small_Lighthouse.jpg");
82+
assertEquals(thumb.getUrl(),"https://dl.airtable.com/rlQ8MyQ4RuqN7rT03ALq_small_The%20Godfather%20poster.jpg");
9283
assertEquals(thumb.getHeight(),36.0, 0);
93-
assertEquals(thumb.getWidth(),48.0, 0);
84+
assertEquals(thumb.getWidth(),24.0, 0);
9485

9586
}
9687

src/itest/java/com/sybit/airtable/TableCreateRecordTest.java

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
/*
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.
2+
* The MIT License (MIT)
3+
* Copyright (c) 2017 Sybit GmbH
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
56
*/
67
package com.sybit.airtable;
78

8-
import com.sybit.airtable.Base;
9-
import com.sybit.airtable.Table;
109
import com.sybit.airtable.exception.AirtableException;
1110
import com.sybit.airtable.movies.Actor;
1211
import com.sybit.airtable.movies.Movie;
@@ -29,7 +28,6 @@ public class TableCreateRecordTest extends WireMockBaseTest {
2928
@Test(expected = AirtableException.class)
3029
public void createMovieWithPhotoIdTest() throws AirtableException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
3130

32-
Base base = airtable.base("appe9941ff07fffcc");
3331

3432
Table<Movie> movieTable = base.table("Movies", Movie.class);
3533
Movie newMovie = new Movie();
@@ -51,9 +49,7 @@ public void createMovieWithPhotoIdTest() throws AirtableException, IllegalAccess
5149

5250
@Test(expected = AirtableException.class)
5351
public void createMovieWithIdTest() throws AirtableException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException, NoSuchFieldException{
54-
55-
Base base = airtable.base("appe9941ff07fffcc");
56-
52+
5753
Table<Movie> movieTable = base.table("Movies", Movie.class);
5854
Movie newMovie = new Movie();
5955
newMovie.setName("Neuer Film");
@@ -64,9 +60,7 @@ public void createMovieWithIdTest() throws AirtableException, IllegalAccessExcep
6460

6561
@Test(expected = AirtableException.class)
6662
public void createMovieWithCreatedTimeTest() throws AirtableException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException, NoSuchFieldException{
67-
68-
Base base = airtable.base("appe9941ff07fffcc");
69-
63+
7064
Table<Movie> movieTable = base.table("Movies", Movie.class);
7165
Movie newMovie = new Movie();
7266
newMovie.setName("Neuer Film");
@@ -77,23 +71,19 @@ public void createMovieWithCreatedTimeTest() throws AirtableException, IllegalAc
7771

7872
@Test
7973
public void createActorTest() throws AirtableException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException, NoSuchFieldException{
80-
81-
Base base = airtable.base("appe9941ff07fffcc");
82-
74+
8375
Table<Actor> actorTable = base.table("Actors", Actor.class);
8476
Actor newActor = new Actor();
8577
newActor.setName("Neuer Actor");
8678
Actor test = actorTable.create(newActor);
8779
assertEquals(test.getName(),newActor.getName());
88-
assertEquals(test.getId(),"rec123456789");
89-
80+
assertNotNull(test.getId());
81+
9082
}
9183

9284
@Test
9385
public void createMovieWithAttachementTest() throws AirtableException, IllegalAccessException, NoSuchMethodException, NoSuchMethodException, InstantiationException, InvocationTargetException, NoSuchFieldException {
94-
95-
Base base = airtable.base("appe9941ff07fffcc");
96-
86+
9787
Table<Movie> movieTable = base.table("Movies", Movie.class);
9888
Movie newMovie = new Movie();
9989

@@ -121,20 +111,18 @@ public void createMovieWithAttachementTest() throws AirtableException, IllegalAc
121111

122112
@Test
123113
public void createMovieTest() throws AirtableException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException, NoSuchFieldException{
124-
125-
Base base = airtable.base("appe9941ff07fffcc");
126-
114+
127115
Table<Movie> movieTable = base.table("Movies", Movie.class);
128116
Movie newMovie = new Movie();
129117

130118
newMovie.setName("Neuer Film");
131119
newMovie.setDescription("Irgendwas");
132120
List<String> director = new ArrayList<>();
133-
director.add("recfaf64fe0db19a9");
121+
director.add("recPxOZblV8yJU4mY");
134122
newMovie.setDirector(director);
135123
List<String> actors = new ArrayList<>();
136-
actors.add("recc8841a14245b0b");
137-
actors.add("rec514228ed76ced1");
124+
actors.add("recEtUIW6FWtbEDKz");
125+
actors.add("recInYFZ1DQpeCuSz");
138126
newMovie.setActors(actors);
139127
List<String> genre = new ArrayList<>();
140128
genre.add("Drama");
@@ -146,7 +134,7 @@ public void createMovieTest() throws AirtableException, IllegalAccessException,
146134
assertEquals(newMovie.getActors(),test.getActors());
147135
assertEquals(newMovie.getGenre(),test.getGenre());
148136
assertEquals(newMovie.getDescription(),test.getDescription());
149-
assertEquals("rec987654321",test.getId());
137+
assertNotNull(test.getId());
150138
assertNotNull(test.getCreatedTime());
151139

152140

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,58 @@
11
/*
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.
2+
* The MIT License (MIT)
3+
* Copyright (c) 2017 Sybit GmbH
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
56
*/
67
package com.sybit.airtable;
78

8-
import com.sybit.airtable.Base;
9-
import com.sybit.airtable.Table;
109
import com.sybit.airtable.exception.AirtableException;
1110
import com.sybit.airtable.movies.Actor;
1211
import com.sybit.airtable.mock.WireMockBaseTest;
13-
import java.util.List;
1412
import org.apache.http.client.HttpResponseException;
15-
import static org.junit.Assert.assertEquals;
13+
import static org.junit.Assert.assertFalse;
14+
import static org.junit.Assert.assertTrue;
15+
import org.junit.Ignore;
1616
import org.junit.Test;
1717

1818
/**
1919
*
2020
* @author fzr
2121
*/
2222
public class TableDestroyTest extends WireMockBaseTest {
23-
24-
25-
23+
2624
@Test
27-
public void testDestroyMovie() throws AirtableException, HttpResponseException{
28-
29-
Base base = airtable.base("appe9941ff07fffcc");
25+
public void testDestroyMovie() throws AirtableException, HttpResponseException {
26+
3027
Table<Actor> actorTable = base.table("Actors", Actor.class);
31-
32-
actorTable.destroy("recapJ3Js8AEwt0Bf");
33-
28+
29+
boolean destroyed = actorTable.destroy("recAt6z10EYD6NtEH");
30+
assertTrue(destroyed);
31+
3432
}
33+
34+
/**
35+
* No Condition found under which Airtable returns false for deleting an Object. Either it doesent find it, which results in a 404 HTTP Exception
36+
* Or something else is wrong with the Syntax, which results in another Exception.
37+
* Therefore this test is Ignored as long as we dont have an Example of a failed delete from Airtable.
38+
* @throws AirtableException
39+
*/
3540

36-
@Test (expected = AirtableException.class)
37-
public void testDestroyMovieException() throws AirtableException{
38-
39-
Base base = airtable.base("appe9941ff07fffcc");
41+
@Ignore
42+
@Test
43+
public void testDestroyMovieFailure() throws AirtableException {
44+
4045
Table<Actor> actorTable = base.table("Actors", Actor.class);
41-
42-
actorTable.destroy("not succesfull");
46+
47+
boolean destroyed = actorTable.destroy("failed");
48+
assertFalse(destroyed);
4349
}
44-
50+
51+
@Test(expected = AirtableException.class)
52+
public void testDestroyMovieException() throws AirtableException {
53+
54+
Table<Actor> actorTable = base.table("Actors", Actor.class);
55+
boolean destroyed = actorTable.destroy("not succesfull");
56+
}
57+
4558
}

0 commit comments

Comments
 (0)