package top.octopusyan.http;

import okhttp3.OkHttpClient;
import top.octopusyan.http.api.NotParamApi;
import top.octopusyan.http.api.ParamApi;
import top.octopusyan.http.config.HttpConstant;
import top.octopusyan.http.config.LogStrategy;
import top.octopusyan.http.listener.OnHttpListener;
import top.octopusyan.http.model.ResponseClass;
import top.octopusyan.http.request.RequestHandler;

/**
 * @author : octopus yan
 * @email : octopus_yan@foxmail.com
 * @description :
 * @create : 2022-4-3 22:24
 */
public class Demo {
   public static void main(String[] args) {
      // 网络请求设置
      HttpConfig.with(new OkHttpClient())
              // 请求服务地址
              .serverPath("https://server.example.com")
              // 是否打印日志
              .setLogEnabled(false)
              // 设置日志打印策略
              .setLogStrategy(new LogStrategy())
              // 设置请求处理策略
              .setHandler(new RequestHandler())
              // 设置请求重试次数
              .setRetryCount(3)
              // 启用配置
              .into();

      EasyHttp.builder()
              // 自定义接口
              .api(new ParamApi<String,String>("/business/api", HttpConstant.Method.POST))
              // 动态参数
              .param("param")
              // 异步请求
              .request(new OnHttpListener<String>() {
                 @Override
                 public void onSucceed(String result) {

                 }

                  @Override
                  public void onFail(Exception e) {

                  }
              });

      try {
         Integer num = EasyHttp.builder()
                 .api(new NotParamApi<Integer>("/business/getnum", HttpConstant.Method.GET))
                 .execute(new ResponseClass<Integer>() {
                 });
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}
