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

com.openrest.v1_1.OpenrestProtocol Maven / Gradle / Ivy

There is a newer version: 1.39.0
Show newest version
package com.openrest.v1_1;

import java.io.IOException;

import com.fasterxml.jackson.core.type.TypeReference;
import com.google.api.client.http.HttpRequestFactory;
import com.wix.restaurants.jsonclient.JsonClient;

public class OpenrestProtocol {
	private final JsonClient jsonClient;
	
	public OpenrestProtocol(HttpRequestFactory requestFactory, Integer connectTimeout, Integer readTimeout,
							Integer numberOfRetries) {
		jsonClient = new JsonClient(requestFactory, connectTimeout, readTimeout, numberOfRetries);
	}
	
    public  T post(String url, Object obj, TypeReference> responseType) throws IOException, OpenrestException {
    	final Response response = jsonClient.post(url, obj, responseType);
    	verifyResponse(response);
    	return response.value;
    }

    public JsonClient getJsonClient() {
    	return jsonClient;
    }
    
    private static  void verifyResponse(Response response) throws OpenrestException {
    	if (response.error != null) {
    		throw new OpenrestException(response.error, response.errorMessage);
    	}
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy