use of pers.lizechao.android_lib.net.params.BaseParams in project lzc_app_lib by httplzc.
the class OkHttpCallFactory method transToRequest.
private Request transToRequest(RequestData requestData) {
String url = requestData.url;
BaseParams params = requestData.params;
HttpMethod method = requestData.method;
HttpUrl httpUrl = HttpUrl.parse(url);
Objects.requireNonNull(httpUrl);
Request.Builder requestBuilder = new Request.Builder();
requestBuilder.headers(Headers.of(params.getHeads()));
RequestBody body = null;
if (method == HttpMethod.GET || method == HttpMethod.HEAD) {
if (!(params instanceof FormParams))
throw new IllegalArgumentException(method.name() + "只能为表单数据");
httpUrl = paramsToHttpUrl(httpUrl, (FormParams) params);
} else {
if (params instanceof RawParams) {
body = transToBody(((RawParams) params).getBinaryData());
} else if (params instanceof MultipartFormParams) {
body = transToBody((MultipartFormParams) params);
} else if (params instanceof FormParams) {
body = transToBody((FormParams) params);
}
}
if (body != null)
body = new ProxyRequestBody(body, requestData.uploadProgress);
return requestBuilder.url(httpUrl).method(method.name(), body).build();
}
use of pers.lizechao.android_lib.net.params.BaseParams in project lzc_app_lib by httplzc.
the class ApiRequestCreater method createBaseParams.
private BaseParams createBaseParams(Object[] args, Params[] params, ParamsType paramsType) {
BaseParams.Builder builder = createParamsByType(paramsType);
FormParams comment = Optional.ofNullable(paramsBuilderFactory).map(ComParamsBuilderFactory::createBuilder).orElse(new FormParams.Builder().build());
if (paramsType != ParamsType.Raw) {
builder.putParams(comment);
}
builder.putBeanByData(args, params, new String[args.length]);
return builder.build();
}
use of pers.lizechao.android_lib.net.params.BaseParams in project lzc_app_lib by httplzc.
the class ApiRequestCreater method createReturnData.
private Object createReturnData(RequestParams requestParams, Type returnType, Params[] params, Object[] args) {
String path = requestParams.path();
HttpMethod httpMethod = requestParams.method();
BaseParams baseParams = createBaseParams(args, params, requestParams.paramsType());
boolean cacheEnable = requestParams.cacheEnable();
// 返回值为Single
if (Single.class.isAssignableFrom(JavaUtils.getRawType(returnType))) {
ParameterizedType parameterizedType = (ParameterizedType) returnType;
Type realType = parameterizedType.getActualTypeArguments()[0];
return createFinalSingle(new ApiRequest<>(realType, path, baseParams, httpMethod, cacheEnable));
} else // 返回值为Completable
if (Completable.class.isAssignableFrom(JavaUtils.getRawType(returnType))) {
return createFinalCompletable(new ApiRequest(Object.class, path, baseParams, httpMethod, cacheEnable));
} else if (ApiRequest.class.isAssignableFrom(JavaUtils.getRawType(returnType))) {
ParameterizedType parameterizedType = (ParameterizedType) returnType;
Type realType = parameterizedType.getActualTypeArguments()[0];
return new ApiRequest(realType, path, baseParams, httpMethod, cacheEnable);
} else
throw new IllegalArgumentException("必须返回值为Single 或Completable");
}
Aggregations