Package is.bokun.client

Source Code of is.bokun.client.CountryClient

package is.bokun.client;

import is.bokun.dtos.CountryDto;

import java.util.List;

import com.fasterxml.jackson.core.type.TypeReference;
import com.google.inject.Inject;
import com.ning.http.client.Response;

/**
* Client for the country resource.
*
* @author Olafur Gauti Gudmundsson
*/
public class CountryClient extends AbstractClient {

    private static final String BASE = "/country.json";

    /**
     * @see AbstractClient#()
     *
     * @param config
     */
    @Inject
    public CountryClient(ClientConfiguration config) {
        super(config);
    }

    /**
     * Get a list of all countries the system knows about.
     * @return a List of country objects, each containing the title and the ISO code for that country.
     */
    public List<CountryDto> findAll() {
        try {
            String uri = BASE + "/findAll";
            Response r = prepareGet(uri).execute().get();
            validateResponse(r);

            return json.readValue(r.getResponseBody("UTF-8"), new TypeReference<List<CountryDto>>(){});

        } catch (Exception e) {
            throw wrapException(e);
        }
    }
}
TOP

Related Classes of is.bokun.client.CountryClient

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.