com.mashape.unirest.http.ObjectMapper Java Examples

The following examples show how to use com.mashape.unirest.http.ObjectMapper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Airtable.java    From airtable.java with MIT License 6 votes vote down vote up
/**
 * Configure, <code>AIRTABLE_API_KEY</code> passed by Java property,
 * enviroment variable or within credentials.properties.
 *
 * @param objectMapper A custom ObjectMapper implementation
 * @return An Airtable instance configured with supplied ObjectMapper
 * @throws com.sybit.airtable.exception.AirtableException Missing API-Key
 */
@SuppressWarnings("UnusedReturnValue")
public Airtable configure(ObjectMapper objectMapper) throws AirtableException {

    LOG.info("System-Property: Using Java property '-D" + AIRTABLE_API_KEY + "' to get apikey.");
    String airtableApi = System.getProperty(AIRTABLE_API_KEY);

    if (airtableApi == null) {
        LOG.info("Environment-Variable: Using OS environment '" + AIRTABLE_API_KEY + "' to get apikey.");
        airtableApi = System.getenv(AIRTABLE_API_KEY);
    }
    if (airtableApi == null) {
        airtableApi = getCredentialProperty(AIRTABLE_API_KEY);
    }

    return this.configure(airtableApi, objectMapper);
}
 
Example #2
Source File: Airtable.java    From airtable.java with MIT License 5 votes vote down vote up
/**
 * Configure the Airtable client by given config.
 * 
 * @param config Configuration of client.
 * @param objectMapper A custom ObjectMapper implementation
 * @return
 * @throws AirtableException Missing API-Key or Endpoint
 */
@SuppressWarnings("WeakerAccess")
public Airtable configure(Configuration config, ObjectMapper objectMapper) throws AirtableException {
    assert config != null : "config was null";
    assert objectMapper != null : "objectMapper was null";

    if (config.getApiKey() == null) {
        throw new AirtableException("Missing Airtable API-Key");
    }
    if (config.getEndpointUrl() == null) {
        throw new AirtableException("Missing endpointUrl");
    }

    this.config = config;

    if (config.getTimeout() != null) {
        LOG.info("Set connection timeout to: " + config.getTimeout() + "ms.");
        Unirest.setTimeouts(config.getTimeout(), config.getTimeout());
    }

    configureProxy(config.getEndpointUrl());

    // Only one time
    Unirest.setObjectMapper(objectMapper);

    // Add specific Converter for Date
    DateTimeConverter dtConverter = new DateConverter();
    dtConverter.setPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    ConvertUtils.register(dtConverter, Date.class);

    ListConverter lConverter = new ListConverter();
    lConverter.setListClass(Attachment.class);
    ConvertUtils.register(lConverter, List.class);

    MapConverter thConverter = new MapConverter();
    thConverter.setMapClass(Thumbnail.class);
    ConvertUtils.register(thConverter, Map.class);

    return this;
}
 
Example #3
Source File: Airtable.java    From airtable.java with MIT License 2 votes vote down vote up
/**
 * Configure Airtable.
 *
 * @param apiKey API-Key of Airtable.
 * @param objectMapper A custom ObjectMapper implementation
 * @return
 * @throws com.sybit.airtable.exception.AirtableException Missing API-Key
 */
@SuppressWarnings("WeakerAccess")
public Airtable configure(String apiKey, ObjectMapper objectMapper) throws AirtableException {
    return configure(new Configuration(apiKey, Configuration.ENDPOINT_URL, null), objectMapper);
}