All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.smartystreets.api.us_reverse_geo.Client Maven / Gradle / Ivy

There is a newer version: 3.18.3
Show newest version
package com.smartystreets.api.us_reverse_geo;

import com.smartystreets.api.Request;
import com.smartystreets.api.Response;
import com.smartystreets.api.Sender;
import com.smartystreets.api.Serializer;
import com.smartystreets.api.exceptions.SmartyException;

import java.io.IOException;
import java.text.DecimalFormat;

public class Client {
    private final Sender sender;
    private final Serializer serializer;

    public Client(Sender sender, Serializer serializer) {
        this.sender = sender;
        this.serializer = serializer;
    }

    public void send(Lookup lookup) throws SmartyException, IOException, InterruptedException {
        Request request = new Request();

        DecimalFormat decimalFormat = new DecimalFormat("#.########");
        request.putParameter("latitude", decimalFormat.format(lookup.getLatitude()));
        request.putParameter("longitude", decimalFormat.format(lookup.getLongitude()));
        request.putParameter("source", lookup.getSource());

        Response httpResponse = this.sender.send(request);

        SmartyResponse response = this.serializer.deserialize(httpResponse.getPayload(), SmartyResponse.class);
        lookup.setResponse(response);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy