package com.libreecm.consumers;

import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;

import com.libreecm.commonAPI.auxiliars.exceptions.ErrorConsumingRESTException;
import com.libreecm.commonAPI.configuration.Config;



public class ConfigConsumer {
	RestTemplate restTemplate = new RestTemplate();
	
	ConfigConsumer(){ 
		
	}
	
	public Config getConfig(String url){
		Config config = null;
		try {
			config =restTemplate.getForObject(url, Config.class);
		} catch (HttpClientErrorException e){
			throw new ErrorConsumingRESTException(url);
		}
		
		return config;
	}
	

	public Config setConfig(Config config, String url){
		try {
			restTemplate.postForEntity(url, config, Config.class);
		} catch (HttpClientErrorException e){
			throw new ErrorConsumingRESTException(url);
		}
		
		return getConfig(url);
	}
	
}
