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

com.heroku.api.request.releases.ReleaseList Maven / Gradle / Ivy

There is a newer version: 0.46
Show newest version
package com.heroku.api.request.releases;

import com.heroku.api.Heroku;
import com.heroku.api.Release;
import com.heroku.api.exception.RequestFailedException;
import com.heroku.api.http.Http;
import com.heroku.api.parser.Json;
import com.heroku.api.request.Request;
import com.heroku.api.request.RequestConfig;
import com.heroku.api.util.Range;

import java.util.HashMap;
import java.util.Map;

import static com.heroku.api.http.HttpUtil.noBody;
import static com.heroku.api.parser.Json.parse;

/**
 * TODO: Javadoc
 *
 * @author Naaman Newbold
 */
public class ReleaseList implements Request> {

    private Map headers = new HashMap<>();

    private final RequestConfig config;

    public ReleaseList(String appName) {
        this.config = new RequestConfig().app(appName);
    }

    public ReleaseList(String appName, String range) {
        this(appName);
        this.headers.put("Range", range);
    }
    
    @Override
    public Http.Method getHttpMethod() {
        return Http.Method.GET;
    }

    @Override
    public String getEndpoint() {
        return Heroku.Resource.Releases.format(config.getAppName());
    }

    @Override
    public boolean hasBody() {
        return false;
    }

    @Override
    public String getBody() {
        throw noBody();
    }

    @Override
    public Map getBodyAsMap() {
        throw noBody();
    }

    @Override
    public Http.Accept getResponseType() {
        return Http.Accept.JSON;
    }

    @Override
    public Map getHeaders() {
        return headers;
    }

    @Override
    public Range getResponse(byte[] bytes, int status, Map responseHeaders) {
        if (status == Http.Status.OK.statusCode) {
            return parse(bytes, getClass());
        } else if (status == 206) {
            Range r = Json.parse(bytes, ReleaseList.class);
            r.setNextRange(responseHeaders.get("Next-Range"));
            return r;
        }
        throw new RequestFailedException("Unable to list releases.", status, bytes);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy