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

Commit 662d4b0

Browse files
authored
Develop (#39)
* Added handling of 429 error code("Rate limit exceeded") * bump versions of used libs (cherry picked from commit 0984aed) * upgrade to gradle wrapper to v5.5.1 * use openjdk 11 on travis build * update codacy-coverage-reporter to v. 6.0.0 * update gradle task for codacy
1 parent 0984aed commit 662d4b0

File tree

6 files changed

+46
-14
lines changed

6 files changed

+46
-14
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: java
22
jdk:
3-
- oraclejdk8
3+
- openjdk11
44
before_install:
55
- chmod +x ./gradlew
66
script:

build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ dependencies {
102102
testCompile group: 'com.github.tomakehurst', name: 'wiremock', version:'2.23.2'
103103
testCompile group: 'org.slf4j', name: 'slf4j-jdk14', version:'1.7.26'
104104

105-
codacy group: 'com.codacy', name: 'codacy-coverage-reporter', version: '1.0.13'
105+
codacy 'com.github.codacy:codacy-coverage-reporter:-SNAPSHOT'
106106
}
107107

108108
// custom tasks for creating source jar
@@ -126,6 +126,7 @@ task sendCoverageToCodacy(type: JavaExec, dependsOn: jacocoTestReport) {
126126
main = "com.codacy.CodacyCoverageReporter"
127127
classpath = configurations.codacy
128128
args = [
129+
"report",
129130
"-l",
130131
"Java",
131132
"-r",
@@ -134,7 +135,7 @@ task sendCoverageToCodacy(type: JavaExec, dependsOn: jacocoTestReport) {
134135
}
135136

136137
task integrationTest(type: Test) {
137-
testClassesDir = sourceSets.integrationTest.output.classesDir
138+
testClassesDirs = project.sourceSets.integrationTest.output.classesDirs
138139
classpath = sourceSets.integrationTest.runtimeClasspath
139140
// This is not needed, but I like to see which tests have run
140141
testLogging {
@@ -194,5 +195,5 @@ bintray {
194195
}
195196
}
196197

197-
integrationTest.mustRunAfter test
198+
integrationTest.mustRunAfter test
198199

gradle/wrapper/gradle-wrapper.jar

1.81 KB
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Thu Apr 13 17:03:46 CEST 2017
1+
#Thu Jul 11 10:56:19 CEST 2019
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip

gradlew

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/usr/bin/env sh
22

33
##############################################################################
44
##
@@ -154,16 +154,19 @@ if $cygwin ; then
154154
esac
155155
fi
156156

157-
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158-
function splitJvmOpts() {
159-
JVM_OPTS=("$@")
157+
# Escape application args
158+
save ( ) {
159+
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160+
echo " "
160161
}
161-
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162-
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
162+
APP_ARGS=$(save "$@")
163+
164+
# Collect all arguments for the java command, following the shell quoting and substitution rules
165+
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
163166

164167
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
165-
if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then
168+
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
166169
cd "$(dirname "$0")"
167170
fi
168171

169-
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
172+
exec "$JAVACMD" "$@"

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.util.ArrayList;
2727
import java.util.List;
2828
import java.util.Map;
29+
import java.util.concurrent.ThreadLocalRandom;
30+
import java.util.concurrent.TimeUnit;
2931

3032
/**
3133
* Representation Class of Airtable Tables.
@@ -197,6 +199,9 @@ public List<T> select(final Query query) throws AirtableException {
197199
if (offset != null) {
198200
list.addAll(this.select(query, offset));
199201
}
202+
} else if (429 == code) {
203+
randomWait();
204+
return select(query);
200205
} else {
201206
HttpResponseExceptionHandler.onResponse(response);
202207
list = null;
@@ -205,6 +210,17 @@ public List<T> select(final Query query) throws AirtableException {
205210
return list;
206211
}
207212

213+
/**
214+
* Performs a sleep for random time period between 30 and 35 seconds
215+
*/
216+
private void randomWait() {
217+
try {
218+
TimeUnit.SECONDS.sleep(ThreadLocalRandom.current().nextInt(30, 36));
219+
} catch (InterruptedException e) {
220+
Thread.currentThread().interrupt();
221+
}
222+
}
223+
208224
/**
209225
* Get <code>List</code> by given offset.
210226
*
@@ -491,6 +507,9 @@ public T find(final String id) throws AirtableException {
491507

492508
if (200 == code) {
493509
body = response.getBody();
510+
} else if (429 == code) {
511+
randomWait();
512+
return find(id);
494513
} else {
495514
HttpResponseExceptionHandler.onResponse(response);
496515
body = null;
@@ -538,6 +557,9 @@ public T create(final T item) throws AirtableException, IllegalAccessException,
538557

539558
if (200 == code) {
540559
responseBody = response.getBody();
560+
} else if (429 == code) {
561+
randomWait();
562+
return create(item);
541563
} else {
542564
HttpResponseExceptionHandler.onResponse(response);
543565
}
@@ -586,6 +608,9 @@ public T update(final T item) throws AirtableException, IllegalAccessException,
586608

587609
if (200 == code) {
588610
responseBody = response.getBody();
611+
} else if (429 == code) {
612+
randomWait();
613+
return update(item);
589614
} else {
590615
HttpResponseExceptionHandler.onResponse(response);
591616
}
@@ -638,6 +663,9 @@ public boolean destroy(String id) throws AirtableException {
638663
if (200 == code) {
639664
Delete body = response.getBody();
640665
isDeleted = body.isDeleted();
666+
} else if (429 == code) {
667+
randomWait();
668+
return destroy(id);
641669
} else {
642670
isDeleted = false;
643671
HttpResponseExceptionHandler.onResponse(response);

0 commit comments

Comments
 (0)