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

com.julienvey.trello.impl.http.RestTemplateHttpClient Maven / Gradle / Ivy

There is a newer version: 0.14
Show newest version
package com.julienvey.trello.impl.http;

import com.julienvey.trello.TrelloHttpClient;
import com.julienvey.trello.exception.TrelloHttpException;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

import java.net.URI;

public class RestTemplateHttpClient implements TrelloHttpClient {

    private RestTemplate restTemplate;

    public RestTemplateHttpClient() {
        restTemplate = new RestTemplate();
    }

    @Override
    public  T postForObject(String url, T object, Class objectClass, String... params) {
        try {
            return restTemplate.postForObject(url, object, objectClass, params);
        } catch (RestClientException e) {
            throw new TrelloHttpException(e);
        }

    }

    @Override
    public URI postForLocation(String url, Object object, String... params) {
        try {
            return restTemplate.postForLocation(url, object, params);
        } catch (RestClientException e) {
            throw new TrelloHttpException(e);
        }
    }

    @Override
    public  T get(String url, Class objectClass, String... params) {
        try {
            return restTemplate.getForObject(url, objectClass, params);
        } catch (RestClientException e) {
            throw new TrelloHttpException(e);
        }
    }

    @Override
    public  T putForObject(String url, T object, Class objectClass, String... params) {
        try {
            return restTemplate.exchange(url, HttpMethod.PUT, new HttpEntity<>(object), objectClass, params).getBody();
        } catch (RestClientException e) {
            throw new TrelloHttpException(e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy