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

com.heroku.api.request.sharing.CollabList Maven / Gradle / Ivy

package com.heroku.api.request.sharing;

import com.heroku.api.Collaborator;
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.parser.XmlParser;
import com.heroku.api.request.Request;
import com.heroku.api.request.RequestConfig;

import javax.xml.bind.annotation.XmlRootElement;
import java.util.Collections;
import java.util.List;
import java.util.Map;

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

    private final RequestConfig config;

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

    @Override
    public Http.Method getHttpMethod() {
        return Http.Method.GET;
    }

    @Override
    public String getEndpoint() {
        return Heroku.Resource.Collaborators.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.XML;
    }

    @Override
    public Map getHeaders() {
        return Collections.emptyMap();
    }

    @Override
    public List getResponse(byte[] bytes, int status) {
        if (status == Http.Status.OK.statusCode) {
            Collaborators collaborators = new XmlParser().parse(bytes, Collaborators.class);
            return collaborators.getCollaborator();
        } else {
            throw new RequestFailedException("List collaborators failed.", status, bytes);
        }
    }

    @XmlRootElement
    static class Collaborators {
        List collaborators;

        public List getCollaborator() {
            return collaborators;
        }

        public void setCollaborator(List collablist) {
            this.collaborators = collablist;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy