Skip to content

Commit

Permalink
Merge pull request #28 from Sybit-Education/develop
Browse files Browse the repository at this point in the history
Feature enhancements: offset loading, destroy
  • Loading branch information
stritti authored Sep 18, 2017
2 parents 5d0f9da + 002e0a7 commit 2fc6046
Show file tree
Hide file tree
Showing 171 changed files with 1,967 additions and 4,621 deletions.
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

# Airtable.java

Java API for Airtable (http://www.airtable.com). The Airtable API provides a simple way of accessing your data within your Java project.
This is a Java API client for Airtable (http://www.airtable.com).

The Airtable API provides a simple way of accessing data within Java projects.

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

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


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

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

### API Result Limitation
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
returned data. The Airtable.java client will solve this and tries to load the offset data automatically.

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

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

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

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

```

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

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

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

# Roadmap

Expand All @@ -333,12 +339,13 @@ Short overview of features, which are supported:
+ [x] SelectAll
+ [x] Queries (`maxRecords`, `sort` & `view` )
+ [x] Support of `filterByFormula`
+ [x] Support of Paging
+ [x] Support of `paging`
+ [x] Support of appending `offset` data

+ [x] Find Record

+ [x] Create Record
+ [x] Update Record
+ [ ] Replace Record (could be done by update)
+ [x] Delete/Destroy Record
+ General requirements
+ [x] Automatic ObjectMapping
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ dependencies {

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

codacy group: 'com.codacy', name: 'codacy-coverage-reporter', version: '1.0.13'
Expand Down
7 changes: 4 additions & 3 deletions src/itest/java/com/sybit/airtable/AirtableTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
* The MIT License (MIT)
* Copyright (c) 2017 Sybit GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
*/
package com.sybit.airtable;

Expand Down
39 changes: 15 additions & 24 deletions src/itest/java/com/sybit/airtable/TableConverterTest.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
* The MIT License (MIT)
* Copyright (c) 2017 Sybit GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
*/
package com.sybit.airtable;


import com.sybit.airtable.Base;
import com.sybit.airtable.Table;
import com.sybit.airtable.exception.AirtableException;
import com.sybit.airtable.movies.Actor;
import com.sybit.airtable.movies.Movie;
import com.sybit.airtable.mock.WireMockBaseTest;
import com.sybit.airtable.vo.Attachment;
import com.sybit.airtable.vo.Thumbnail;
import java.util.List;
import java.util.Map;
import org.apache.http.client.HttpResponseException;
import static org.junit.Assert.assertEquals;
Expand All @@ -32,15 +29,13 @@ public class TableConverterTest extends WireMockBaseTest {
@Test
public void testConvertMovie() throws AirtableException, HttpResponseException {

Base base = airtable.base("appe9941ff07fffcc");

Table<Movie> movieTable = base.table("Movies", Movie.class);
Movie movie = movieTable.find("rec6733da527dd0f1");
Movie movie = movieTable.find("recFj9J78MLtiFFMz");
assertNotNull(movie);

assertEquals(movie.getId(),"rec6733da527dd0f1");
assertEquals(movie.getId(),"recFj9J78MLtiFFMz");
assertEquals(movie.getName(),"The Godfather");
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...");
assertEquals(movie.getPhotos().size(),2);
assertEquals(movie.getDirector().size(),1);
assertEquals(movie.getActors().size(),2);
Expand All @@ -53,10 +48,8 @@ public void testConvertMovie() throws AirtableException, HttpResponseException {
public void testConvertAttachement() throws AirtableException, HttpResponseException {


Base base = airtable.base("appe9941ff07fffcc");

Table<Movie> movieTable = base.table("Movies", Movie.class);
Movie movie = movieTable.find("rec6733da527dd0f1");
Movie movie = movieTable.find("recFj9J78MLtiFFMz");
assertNotNull(movie);

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

assertEquals(photo1.getId(),"att6dba4af5786df1");
assertEquals(photo1.getUrl(),"https://www.filepicker.io/api/file/akW7wUX7QM66a2hjxb9k");
assertEquals(photo1.getFilename(),"220px-TheGodfatherAlPacinoMarlonBrando.jpg");
assertEquals(photo1.getSize(),16420.0,0);
assertEquals(photo1.getId(),"attk3WY5B28GVcFGU");
assertEquals(photo1.getUrl(),"https://dl.airtable.com/9UhUUeAtSym1PzBdA0q0_AlPacinoandMarlonBrando.jpg");
assertEquals(photo1.getFilename(),"AlPacinoandMarlonBrando.jpg");
assertEquals(photo1.getSize(),35698,0);
assertEquals(photo1.getType(),"image/jpeg");
assertEquals(photo1.getThumbnails().size(),2);

}

@Test
public void testConvertThumbnails() throws AirtableException, HttpResponseException {

Base base = airtable.base("appe9941ff07fffcc");


Table<Movie> movieTable = base.table("Movies", Movie.class);
Movie movie = movieTable.find("rec6733da527dd0f1");
Movie movie = movieTable.find("recFj9J78MLtiFFMz");
assertNotNull(movie);

assertEquals(movie.getPhotos().get(0).getThumbnails().size(),2);
assertEquals(movie.getPhotos().get(1).getThumbnails().size(),2);
Map<String, Thumbnail> thumbnails = movie.getPhotos().get(1).getThumbnails();
Thumbnail thumb = thumbnails.get("small");
assertEquals(thumb.getUrl(),"https://dl.airtable.com/MbdRAn4ZQLuNyUqrHONp_small_Lighthouse.jpg");
assertEquals(thumb.getUrl(),"https://dl.airtable.com/rlQ8MyQ4RuqN7rT03ALq_small_The%20Godfather%20poster.jpg");
assertEquals(thumb.getHeight(),36.0, 0);
assertEquals(thumb.getWidth(),48.0, 0);
assertEquals(thumb.getWidth(),24.0, 0);

}

Expand Down
42 changes: 15 additions & 27 deletions src/itest/java/com/sybit/airtable/TableCreateRecordTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
* The MIT License (MIT)
* Copyright (c) 2017 Sybit GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
*/
package com.sybit.airtable;

import com.sybit.airtable.Base;
import com.sybit.airtable.Table;
import com.sybit.airtable.exception.AirtableException;
import com.sybit.airtable.movies.Actor;
import com.sybit.airtable.movies.Movie;
Expand All @@ -29,7 +28,6 @@ public class TableCreateRecordTest extends WireMockBaseTest {
@Test(expected = AirtableException.class)
public void createMovieWithPhotoIdTest() throws AirtableException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {

Base base = airtable.base("appe9941ff07fffcc");

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

@Test(expected = AirtableException.class)
public void createMovieWithIdTest() throws AirtableException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException, NoSuchFieldException{

Base base = airtable.base("appe9941ff07fffcc");


Table<Movie> movieTable = base.table("Movies", Movie.class);
Movie newMovie = new Movie();
newMovie.setName("Neuer Film");
Expand All @@ -64,9 +60,7 @@ public void createMovieWithIdTest() throws AirtableException, IllegalAccessExcep

@Test(expected = AirtableException.class)
public void createMovieWithCreatedTimeTest() throws AirtableException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException, NoSuchFieldException{

Base base = airtable.base("appe9941ff07fffcc");


Table<Movie> movieTable = base.table("Movies", Movie.class);
Movie newMovie = new Movie();
newMovie.setName("Neuer Film");
Expand All @@ -77,23 +71,19 @@ public void createMovieWithCreatedTimeTest() throws AirtableException, IllegalAc

@Test
public void createActorTest() throws AirtableException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException, NoSuchFieldException{

Base base = airtable.base("appe9941ff07fffcc");


Table<Actor> actorTable = base.table("Actors", Actor.class);
Actor newActor = new Actor();
newActor.setName("Neuer Actor");
Actor test = actorTable.create(newActor);
assertEquals(test.getName(),newActor.getName());
assertEquals(test.getId(),"rec123456789");

assertNotNull(test.getId());
}

@Test
public void createMovieWithAttachementTest() throws AirtableException, IllegalAccessException, NoSuchMethodException, NoSuchMethodException, InstantiationException, InvocationTargetException, NoSuchFieldException {

Base base = airtable.base("appe9941ff07fffcc");


Table<Movie> movieTable = base.table("Movies", Movie.class);
Movie newMovie = new Movie();

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

@Test
public void createMovieTest() throws AirtableException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException, NoSuchFieldException{

Base base = airtable.base("appe9941ff07fffcc");


Table<Movie> movieTable = base.table("Movies", Movie.class);
Movie newMovie = new Movie();

newMovie.setName("Neuer Film");
newMovie.setDescription("Irgendwas");
List<String> director = new ArrayList<>();
director.add("recfaf64fe0db19a9");
director.add("recPxOZblV8yJU4mY");
newMovie.setDirector(director);
List<String> actors = new ArrayList<>();
actors.add("recc8841a14245b0b");
actors.add("rec514228ed76ced1");
actors.add("recEtUIW6FWtbEDKz");
actors.add("recInYFZ1DQpeCuSz");
newMovie.setActors(actors);
List<String> genre = new ArrayList<>();
genre.add("Drama");
Expand All @@ -146,7 +134,7 @@ public void createMovieTest() throws AirtableException, IllegalAccessException,
assertEquals(newMovie.getActors(),test.getActors());
assertEquals(newMovie.getGenre(),test.getGenre());
assertEquals(newMovie.getDescription(),test.getDescription());
assertEquals("rec987654321",test.getId());
assertNotNull(test.getId());
assertNotNull(test.getCreatedTime());


Expand Down
59 changes: 36 additions & 23 deletions src/itest/java/com/sybit/airtable/TableDestroyTest.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,58 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
* The MIT License (MIT)
* Copyright (c) 2017 Sybit GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
*/
package com.sybit.airtable;

import com.sybit.airtable.Base;
import com.sybit.airtable.Table;
import com.sybit.airtable.exception.AirtableException;
import com.sybit.airtable.movies.Actor;
import com.sybit.airtable.mock.WireMockBaseTest;
import java.util.List;
import org.apache.http.client.HttpResponseException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Ignore;
import org.junit.Test;

/**
*
* @author fzr
*/
public class TableDestroyTest extends WireMockBaseTest {




@Test
public void testDestroyMovie() throws AirtableException, HttpResponseException{

Base base = airtable.base("appe9941ff07fffcc");
public void testDestroyMovie() throws AirtableException, HttpResponseException {

Table<Actor> actorTable = base.table("Actors", Actor.class);

actorTable.destroy("recapJ3Js8AEwt0Bf");


boolean destroyed = actorTable.destroy("recAt6z10EYD6NtEH");
assertTrue(destroyed);

}

/**
* No Condition found under which Airtable returns false for deleting an Object. Either it doesent find it, which results in a 404 HTTP Exception
* Or something else is wrong with the Syntax, which results in another Exception.
* Therefore this test is Ignored as long as we dont have an Example of a failed delete from Airtable.
* @throws AirtableException
*/

@Test (expected = AirtableException.class)
public void testDestroyMovieException() throws AirtableException{
Base base = airtable.base("appe9941ff07fffcc");
@Ignore
@Test
public void testDestroyMovieFailure() throws AirtableException {

Table<Actor> actorTable = base.table("Actors", Actor.class);

actorTable.destroy("not succesfull");

boolean destroyed = actorTable.destroy("failed");
assertFalse(destroyed);
}


@Test(expected = AirtableException.class)
public void testDestroyMovieException() throws AirtableException {

Table<Actor> actorTable = base.table("Actors", Actor.class);
boolean destroyed = actorTable.destroy("not succesfull");
}

}
Loading

0 comments on commit 2fc6046

Please sign in to comment.