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

com.github.kubatatami.judonetworking.ProtocolController Maven / Gradle / Ivy

package com.github.kubatatami.judonetworking;

import com.github.kubatatami.judonetworking.exceptions.JudoException;

import java.io.InputStream;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: jbogacki
 * Date: 23.07.2013
 * Time: 22:42
 * To change this template use File | Settings | File Templates.
 */
public abstract class ProtocolController {

    private String apiKey = null;
    private String apiKeyName = null;

    public static class RequestInfo {
        public String url;
        public RequestInputStreamEntity entity;
        public String mimeType;
        public Map customHeaders;
    }

    public void setApiKey(String name, String key) {
        this.apiKeyName = name;
        this.apiKey = key;
    }

    public void setApiKey(String key) {
        this.apiKey = key;
    }

    public int getAutoBatchTime() {
        return 0;
    }

    public abstract RequestInfo createRequest(String url, RequestInterface request) throws JudoException;

    public abstract RequestResult parseResponse(RequestInterface request, InputStream stream, Map> headers);

    public boolean isBatchSupported() {
        return false;
    }

    public RequestInfo createRequests(String url, List requests) throws JudoException {
        throw new UnsupportedOperationException("CreateRequests not implemented.");
    }

    public List parseResponses(List requests, InputStream stream, Map> headers) throws JudoException {
        throw new UnsupportedOperationException("ParseResponses not implemented.");
    }

    public void parseError(int code, String resp) throws JudoException {

    }

    public Serializable getAdditionalRequestData() {
        return new ApiKey(apiKeyName, apiKey);
    }

    public TokenCaller getTokenCaller() {
        return null;
    }

    public static class ApiKey implements Serializable {
        public String apiKeyName = null;
        public String apiKey = null;


        public ApiKey(String apiKeyName, String apiKey) {
            this.apiKeyName = apiKeyName;
            this.apiKey = apiKey;
        }
    }

    protected static String convertStreamToString(InputStream is) {
        Scanner s = new Scanner(is).useDelimiter("\\A");
        return s.hasNext() ? s.next() : "";
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy