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

cn.jiguang.sdk.api.ReportApi Maven / Gradle / Ivy

There is a newer version: 5.1.11
Show newest version
package cn.jiguang.sdk.api;

import cn.jiguang.sdk.bean.report.*;
import cn.jiguang.sdk.client.ReportClient;
import cn.jiguang.sdk.codec.ApiDecoder;
import cn.jiguang.sdk.codec.ApiEncoder;
import cn.jiguang.sdk.codec.ApiErrorDecoder;
import feign.Client;
import feign.Feign;
import feign.Logger;
import feign.auth.BasicAuthRequestInterceptor;
import feign.okhttp.OkHttpClient;
import feign.slf4j.Slf4jLogger;
import lombok.NonNull;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

public class ReportApi {

    private final ReportClient reportClient;

    protected ReportApi(@NonNull ReportClient reportClient) {
        this.reportClient = reportClient;
    }

    public List getReceivedDetail(@NonNull List msgIds) {
        return reportClient.getReceivedDetail(String.join(",", msgIds));
    }

    public Map getMessageStatus(@NonNull MessageStatusGetParam param) {
        return reportClient.getMessageStatus(param);
    }

    public List getMessageDetail(@NonNull List msgIds) {
        return reportClient.getMessageDetail(String.join(",", msgIds));
    }

    public UserDetailGetResult getUserDetail(@NonNull LocalDate startDate, @NonNull int duration) {
        return reportClient.getUserDetail(startDate, duration);
    }

    public static class Builder {

        private Client client = new OkHttpClient();
        private String host = "https://report.jpush.cn";
        private String appKey;
        private String masterSecret;
        private Logger.Level loggerLevel = Logger.Level.BASIC;

        public Builder setClient(@NonNull Client client) {
            this.client = client;
            return this;
        }

        public Builder setHost(@NonNull String host) {
            this.host = host;
            return this;
        }

        public Builder setAppKey(@NonNull String appKey) {
            this.appKey = appKey;
            return this;
        }

        public Builder setMasterSecret(@NonNull String masterSecret) {
            this.masterSecret = masterSecret;
            return this;
        }

        public Builder setLoggerLevel(@NonNull Logger.Level loggerLevel) {
            this.loggerLevel = loggerLevel;
            return this;
        }

        public ReportApi build() {
            ReportClient reportClient = Feign.builder()
                    .client(client)
                    .requestInterceptor(new BasicAuthRequestInterceptor(appKey, masterSecret))
                    .encoder(new ApiEncoder())
                    .decoder(new ApiDecoder())
                    .errorDecoder(new ApiErrorDecoder())
                    .logger(new Slf4jLogger())
                    .logLevel(loggerLevel)
                    .target(ReportClient.class, host);
            return new ReportApi(reportClient);
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy