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

com.codota.service.client.requests.base.PutRequest Maven / Gradle / Ivy

package com.codota.service.client.requests.base;

import com.codota.service.client.CodotaConnectionException;
import com.codota.service.client.CodotaHttpException;
import com.codota.service.client.CodotaResponse;
import com.codota.service.connector.ServiceConnector;

import java.util.Map;

/**
 * Created by shaia on 28/05/2017.
 */
public abstract class PutRequest extends Request {

    private String bodyJsonString;

    public PutRequest(ServiceConnector connector, String route, String token, Map props) {
        super(connector, route, token);
        this.queryParameters = props;
    }

    public T run() throws CodotaConnectionException, CodotaHttpException {
        T result;
        CodotaResponse response = connector.put(this);
        if (response == null) {
            throw new CodotaConnectionException();
        }
        if (response.isOK()) {
            result = parse(response.content);
        } else {
            throw new CodotaHttpException(response.status, response.content);
        }
        return result;
    }

    public void withBodyJsonString(String bodyJsonString) {
        this.bodyJsonString = bodyJsonString;
    }

    public String getBodyJsonString() {
        return this.bodyJsonString;
    }

    public abstract T parse(String response);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy