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

com.chargebee.internal.ListRequest Maven / Gradle / Ivy

There is a newer version: 3.26.0
Show newest version
package com.chargebee.internal;

import com.chargebee.RequestWrap;
import com.chargebee.Environment;
import com.chargebee.ListResult;
import com.chargebee.filters.*;
import java.io.IOException;
import java.util.Date;

public class ListRequest extends RequestBase{

    
    public ListRequest(String uri) {
        this.uri = uri;
    }

    public U limit(int limit) {
        params.addOpt("limit", limit);
        return (U)this;
    }

    public U offset(String offset) {
        params.addOpt("offset", offset);
        return (U)this;
    }
    
    public StringFilter stringFilterParam(String paramName){
        return new StringFilter(paramName, (U)this).supportsPresenceOperator(true).supportsMultiOperators(true);
    }
    
    public BooleanFilter booleanFilterParam(String paramName){
        return new BooleanFilter(paramName, (U)this).supportsPresenceOperator(true);
    }
    
    public NumberFilter longFilterParam(String paramName) {
        return new NumberFilter(paramName, (U) this).supportsPresenceOperator(true);
    }
    
    public TimestampFilter timestampFilterParam(String paramName){
        return new TimestampFilter(paramName, (U)this).supportsPresenceOperator(true);
    }
    
    public DateFilter dateFilterParam(String paramName){
        return new DateFilter(paramName, (U)this).supportsPresenceOperator(true);
    }
    
    public final ListResult request() throws Exception {
        return request(Environment.defaultConfig());
    }

    public final ListResult request(Environment env) throws IOException, Exception {
        RequestWrap c = new RequestWrap(env, this) {

            @Override
            public ListResult call() throws Exception {
                return _request(env, request);
            }
        };
        return (ListResult) (env.reqInterceptor() != null ? env.reqInterceptor().handleRequest(c) : c.call());

    }
    
    private static ListResult _request(Environment env, ListRequest req) throws IOException {
        if (env == null) {
            throw new RuntimeException("Environment cannot be null");
        }
        String url = new StringBuilder(env.apiBaseUrl()).append(req.uri).toString();
        return HttpUtil.getList(url, req.params(), req.headers, env);
    }
    
    @Override
    public Params params() {
        return params;
    }

}