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

Commit ada8b5b

Browse files
committed
- Adding configuration class.
- timeout could be set now
1 parent 95db26f commit ada8b5b

2 files changed

Lines changed: 98 additions & 15 deletions

File tree

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

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,11 @@
4444
public class Airtable {
4545

4646
private static final Logger LOG = LoggerFactory.getLogger( Airtable.class );
47-
private static final String ENDPOINT_URL = "https://api.airtable.com/v0";
47+
4848
private static final String AIRTABLE_API_KEY = "AIRTABLE_API_KEY";
4949
private static final String AIRTABLE_BASE = "AIRTABLE_BASE";
5050

51-
private String endpointUrl;
52-
private String apiKey;
51+
private Configuration config;
5352

5453
/**
5554
* Configure, <code>AIRTABLE_API_KEY</code> passed by Java property, enviroment variable
@@ -86,29 +85,32 @@ public Airtable configure() throws AirtableException {
8685
*/
8786
@SuppressWarnings("WeakerAccess")
8887
public Airtable configure(String apiKey) throws AirtableException {
89-
return configure(apiKey, ENDPOINT_URL);
88+
return configure(new Configuration(apiKey, Configuration.ENDPOINT_URL));
9089
}
9190

9291
/**
9392
*
94-
* @param apiKey
95-
* @param endpointUrl
93+
* @param config
9694
* @return
9795
* @throws com.sybit.airtable.exception.AirtableException Missing API-Key or Endpoint
9896
*/
9997
@SuppressWarnings("WeakerAccess")
100-
public Airtable configure(String apiKey, String endpointUrl) throws AirtableException {
101-
if(apiKey == null) {
98+
public Airtable configure(Configuration config) throws AirtableException {
99+
if(config.getApiKey() == null) {
102100
throw new AirtableException("Missing Airtable API-Key");
103101
}
104-
if(endpointUrl == null) {
102+
if(config.getEndpointUrl() == null) {
105103
throw new AirtableException("Missing endpointUrl");
106104
}
107105

108-
this.apiKey = apiKey;
109-
this.endpointUrl = endpointUrl;
106+
this.config = config;
110107

111-
setProxy(endpointUrl);
108+
if(config.getTimeout() != null) {
109+
LOG.info("Set connection timeout to: " + config.getTimeout() + "ms.");
110+
Unirest.setTimeouts(config.getTimeout(), config.getTimeout());
111+
}
112+
113+
setProxy(config.getEndpointUrl());
112114

113115
// Only one time
114116
Unirest.setObjectMapper(new GsonObjectMapper());
@@ -190,20 +192,29 @@ public Base base(String base) throws AirtableException {
190192
return b;
191193
}
192194

195+
public Configuration getConfig() {
196+
return config;
197+
}
198+
199+
public void setConfig(Configuration config) {
200+
this.config = config;
201+
setProxy(config.getEndpointUrl());
202+
}
203+
193204
/**
194205
*
195206
* @return
196207
*/
197208
public String endpointUrl() {
198-
return endpointUrl;
209+
return this.config.getEndpointUrl();
199210
}
200211

201212
/**
202213
*
203214
* @return
204215
*/
205216
public String apiKey() {
206-
return apiKey;
217+
return this.config.getApiKey();
207218
}
208219

209220
/**
@@ -235,7 +246,7 @@ private String getCredentialProperty(String key) {
235246
}
236247

237248
public void setEndpointUrl(String endpointUrl) {
238-
this.endpointUrl = endpointUrl;
249+
this.config.setEndpointUrl(endpointUrl);
239250
setProxy(endpointUrl);
240251
}
241252
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
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
6+
*/
7+
package com.sybit.airtable;
8+
9+
/**
10+
* Configuration settings for Airtable.
11+
* Used by class <code>Airtable</code> to configure basic settings.
12+
*/
13+
public class Configuration {
14+
15+
public static final String ENDPOINT_URL = "https://api.airtable.com/v0";
16+
17+
private String endpointUrl;
18+
private String apiKey;
19+
private Long timeout;
20+
21+
/**
22+
* Configure API using given API Key and default endpoint.
23+
*
24+
* @param apiKey
25+
*/
26+
public Configuration(String apiKey) {
27+
this(apiKey, ENDPOINT_URL);
28+
29+
}
30+
/**
31+
* Configure API using given API Key and default endpointURL.
32+
*
33+
* @param apiKey
34+
* @param endpointUrl
35+
*/
36+
public Configuration(String apiKey, String endpointUrl) {
37+
this.apiKey = apiKey;
38+
this.endpointUrl = endpointUrl;
39+
}
40+
41+
public String getEndpointUrl() {
42+
return endpointUrl;
43+
}
44+
45+
public void setEndpointUrl(String endpointUrl) {
46+
this.endpointUrl = endpointUrl;
47+
}
48+
49+
public String getApiKey() {
50+
return apiKey;
51+
}
52+
53+
public void setApiKey(String apiKey) {
54+
this.apiKey = apiKey;
55+
}
56+
57+
/**
58+
* Get connection timeout.
59+
* @return
60+
*/
61+
public Long getTimeout() {
62+
return timeout;
63+
}
64+
65+
/**
66+
* Set connection timeout.
67+
* @param timeout
68+
*/
69+
public void setTimeout(Long timeout) {
70+
this.timeout = timeout;
71+
}
72+
}

0 commit comments

Comments
 (0)