|
44 | 44 | public class Airtable { |
45 | 45 |
|
46 | 46 | private static final Logger LOG = LoggerFactory.getLogger( Airtable.class ); |
47 | | - private static final String ENDPOINT_URL = "https://api.airtable.com/v0"; |
| 47 | + |
48 | 48 | private static final String AIRTABLE_API_KEY = "AIRTABLE_API_KEY"; |
49 | 49 | private static final String AIRTABLE_BASE = "AIRTABLE_BASE"; |
50 | 50 |
|
51 | | - private String endpointUrl; |
52 | | - private String apiKey; |
| 51 | + private Configuration config; |
53 | 52 |
|
54 | 53 | /** |
55 | 54 | * Configure, <code>AIRTABLE_API_KEY</code> passed by Java property, enviroment variable |
@@ -86,29 +85,32 @@ public Airtable configure() throws AirtableException { |
86 | 85 | */ |
87 | 86 | @SuppressWarnings("WeakerAccess") |
88 | 87 | public Airtable configure(String apiKey) throws AirtableException { |
89 | | - return configure(apiKey, ENDPOINT_URL); |
| 88 | + return configure(new Configuration(apiKey, Configuration.ENDPOINT_URL)); |
90 | 89 | } |
91 | 90 |
|
92 | 91 | /** |
93 | 92 | * |
94 | | - * @param apiKey |
95 | | - * @param endpointUrl |
| 93 | + * @param config |
96 | 94 | * @return |
97 | 95 | * @throws com.sybit.airtable.exception.AirtableException Missing API-Key or Endpoint |
98 | 96 | */ |
99 | 97 | @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) { |
102 | 100 | throw new AirtableException("Missing Airtable API-Key"); |
103 | 101 | } |
104 | | - if(endpointUrl == null) { |
| 102 | + if(config.getEndpointUrl() == null) { |
105 | 103 | throw new AirtableException("Missing endpointUrl"); |
106 | 104 | } |
107 | 105 |
|
108 | | - this.apiKey = apiKey; |
109 | | - this.endpointUrl = endpointUrl; |
| 106 | + this.config = config; |
110 | 107 |
|
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()); |
112 | 114 |
|
113 | 115 | // Only one time |
114 | 116 | Unirest.setObjectMapper(new GsonObjectMapper()); |
@@ -190,20 +192,29 @@ public Base base(String base) throws AirtableException { |
190 | 192 | return b; |
191 | 193 | } |
192 | 194 |
|
| 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 | + |
193 | 204 | /** |
194 | 205 | * |
195 | 206 | * @return |
196 | 207 | */ |
197 | 208 | public String endpointUrl() { |
198 | | - return endpointUrl; |
| 209 | + return this.config.getEndpointUrl(); |
199 | 210 | } |
200 | 211 |
|
201 | 212 | /** |
202 | 213 | * |
203 | 214 | * @return |
204 | 215 | */ |
205 | 216 | public String apiKey() { |
206 | | - return apiKey; |
| 217 | + return this.config.getApiKey(); |
207 | 218 | } |
208 | 219 |
|
209 | 220 | /** |
@@ -235,7 +246,7 @@ private String getCredentialProperty(String key) { |
235 | 246 | } |
236 | 247 |
|
237 | 248 | public void setEndpointUrl(String endpointUrl) { |
238 | | - this.endpointUrl = endpointUrl; |
| 249 | + this.config.setEndpointUrl(endpointUrl); |
239 | 250 | setProxy(endpointUrl); |
240 | 251 | } |
241 | 252 | } |
0 commit comments