com.heroku.api.request.dynos.DynoRestart Maven / Gradle / Ivy
package com.heroku.api.request.dynos;
import com.heroku.api.Heroku;
import com.heroku.api.exception.RequestFailedException;
import com.heroku.api.http.Http;
import com.heroku.api.http.HttpUtil;
import com.heroku.api.request.Request;
import com.heroku.api.response.Unit;
import java.util.Collections;
import java.util.Map;
import static com.heroku.api.http.HttpUtil.noBody;
/**
* @author Joe Kutner on 8/2/17.
* Twitter: @codefinger
*/
public class DynoRestart implements Request {
private final String appName;
private final String dynoId;
public DynoRestart(String appName, String dynoId) {
this.appName = appName;
this.dynoId = dynoId;
}
@Override
public Http.Method getHttpMethod() {
return Http.Method.DELETE;
}
@Override
public String getEndpoint() {
return Heroku.Resource.Dyno.format(this.appName, this.dynoId);
}
@Override
public boolean hasBody() {
return false;
}
@Override
public String getBody() {
throw HttpUtil.noBody();
}
@Override
public Map getBodyAsMap() {
throw noBody();
}
@Override
public Http.Accept getResponseType() {
return Http.Accept.JSON;
}
@Override
public Map getHeaders() {
return Collections.emptyMap();
}
@Override
public Unit getResponse(byte[] in, int code, Map responseHeaders) {
if (code == Http.Status.ACCEPTED.statusCode)
return Unit.unit;
else
throw new RequestFailedException("Dyno restart failed", code, in);
}
}