com.heroku.api.request.ps.ProcessList Maven / Gradle / Ivy
package com.heroku.api.request.ps;
import com.heroku.api.Heroku;
import com.heroku.api.Proc;
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.request.RequestConfig;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static com.heroku.api.parser.Json.parse;
/**
* TODO: Javadoc
*
* @author Naaman Newbold
*/
public class ProcessList implements Request> {
private final RequestConfig config;
public ProcessList(String appName) {
config = new RequestConfig().app(appName);
}
@Override
public Http.Method getHttpMethod() {
return Http.Method.GET;
}
@Override
public String getEndpoint() {
return Heroku.Resource.Process.format(config.get(Heroku.RequestKey.AppName));
}
@Override
public boolean hasBody() {
return false;
}
@Override
public String getBody() {
throw HttpUtil.noBody();
}
@Override
public Http.Accept getResponseType() {
return Http.Accept.JSON;
}
@Override
public Map getHeaders() {
return Collections.emptyMap();
}
@Override
public List getResponse(byte[] bytes, int status) {
if (status == Http.Status.OK.statusCode) {
return parse(bytes, getClass());
} else {
throw new RequestFailedException("Process request failed.", status, bytes);
}
}
}