diff --git a/LICENSE b/LICENSE index 261eeb9e9..6f1e9a45a 100644 --- a/LICENSE +++ b/LICENSE @@ -42,7 +42,7 @@ editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, + separable from, or merely link (or bind by name) to the com.drake.net.interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including diff --git a/README.md b/README.md index e7b4b949d..ea0ed2d4e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,9 @@

不仅仅是网络请求的异步任务库

-

使用文档 | 备用访问

+

使用文档 + +

@@ -18,68 +20,58 @@
-Android上不是最强网络任务库, 创新式的网络请求库(基于Kalle), 支持协程高并发网络请求 +Android上不是最强网络任务库, 基于OkHttp且完美支持其所有函数组件, 支持协程高并发网络请求
Net 1.x 版本为RxJava实现
Net 2.x 版本为协程实现(开发者无需掌握协程也可以使用) +Net 3.x 版本为OkHttp4.x实现 + +
+

欢迎贡献代码/问题

+
-正在进行的任务 +设计哲学 -- OkHttp4.8 重构 +1. 代码优雅 +2. 文档清晰 +3. 扩展性好 +4. 功能全 -
-主要新增特性 -- 代码简洁(最少一行代码发起请求) -- 文档详细 +主要功能 + - Kotlin - 协程(不懂协程也可上手) -- 并发网络请求(马上优化网络速度!) +- 并发网络请求 - 串行网络请求 -- 切换线程 -- DSL编程 -- 全局日志记录器(完美解决日志过长展示不清晰数据加密问题, 比抓包更强大) -- 支持先强制读取缓存后网络请求二次刷新 -- 并发请求返回最快请求结果(可返回不同响应数据) -- 方便的缓存处理 -- 自动错误信息吐司 -- 详细的错误信息 +- 快速切换线程 +- DSL作用域编程 +- 日志记录器(完美解决日志过长展示不清晰数据加密问题, 比抓包更强大) +- 并发请求返回最快请求结果 - 自动异常捕获 -- 自动日志打印异常(任何网络错误可追踪到具体请求接口) -- 自动JSON解析(可解析List) +- 自动错误信息吐司 +- 自动JSON解析 - 自动处理下拉刷新和上拉加载 - 自动处理分页加载 - 自动缺省页 - 自动处理生命周期 - 自动处理加载对话框 +- 支持配合ViewModel +- 异常包含请求信息 +- 数据转换器 +- 请求存储键值对 +- 请求支持Id/Group分组 +- 全局手动取消请求/自动取消请求 - 协程作用域支持错误和结束回调 +- 支持先强制读取缓存后网络请求二次刷新 - 内置超强轮循器(计时器) - 解析JSON数组返回集合 - - - -同时完全不影响Kalle的特性 - -- 九种缓存模式 -- 重试次数拦截器 -- 数据库缓存加密 -- 上传进度监听 -- 下载进度监听 -- 断点续传 -- 下载文件策略 -- 网络连接判断 -- 自定义数据转换器 -- 网络拦截器 -- 重定向 -- 自定义请求体 -- 全局配置 -- Cookie -- SSH证书 +- 监听上传/下载进度 @@ -102,11 +94,11 @@ allprojects { // 协程库(版本自定) implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9' +implementation "com.squareup.okhttp3:okhttp:4.9.1" +implementation 'com.github.liangjingkanji:Net:3.0.0' // 支持自动下拉刷新和缺省页的(可选) implementation 'com.github.liangjingkanji:BRV:1.3.19' - -implementation 'com.github.liangjingkanji:Net:2.3.16' ```
@@ -132,4 +124,4 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -``` +``` \ No newline at end of file diff --git a/build.gradle b/build.gradle index 714f8cb84..6de6b1062 100644 --- a/build.gradle +++ b/build.gradle @@ -18,11 +18,12 @@ buildscript { ext { - kotlin_version = '1.4.32' + kotlin_version = '1.5.0' brv_version = '1.3.19' coroutine_version = '1.4.3' glide_version = '4.11.0' - room_version = "2.2.6" + room_version = "2.3.0" + okhttp_version = "4.9.1" } repositories { @@ -31,8 +32,9 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.3' + classpath 'com.android.tools.build:gradle:4.2.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' classpath 'org.jetbrains.dokka:dokka-gradle-plugin:0.10.1' } diff --git a/docs/api/net/alltypes/index.md b/docs/api/net/alltypes/index.md index 044062d2c..6cbe32cd0 100644 --- a/docs/api/net/alltypes/index.md +++ b/docs/api/net/alltypes/index.md @@ -11,46 +11,51 @@ 异步协程作用域 -| (extensions in package com.drake.net) +| -##### [android.app.Application](../com.drake.net/android.app.-application/index.md) +##### [com.drake.net.request.BaseRequest](../com.drake.net.request/-base-request/index.md) -| (extensions in package com.drake.net) +| -##### [com.yanzhenjie.kalle.KalleConfig.Builder](../com.drake.net/com.yanzhenjie.kalle.-kalle-config.-builder/index.md) +##### [com.drake.net.request.BodyRequest](../com.drake.net.request/-body-request/index.md) -| (extensions in package com.drake.net) +| (extensions in package com.drake.net.request) -##### [android.content.Context](../com.drake.net/android.content.-context/index.md) +##### [okhttp3.Request.Builder](../com.drake.net.request/okhttp3.-request.-builder/index.md) -| (extensions in package com.drake.net) +| (extensions in package com.drake.net.utils) -##### [kotlinx.coroutines.CoroutineScope](../com.drake.net/kotlinx.coroutines.-coroutine-scope/index.md) +##### [okhttp3.OkHttpClient.Builder](../com.drake.net.utils/okhttp3.-ok-http-client.-builder/index.md) -| (extensions in package com.drake.net.error) +| -##### [kotlinx.coroutines.CoroutineScope](../com.drake.net.error/kotlinx.coroutines.-coroutine-scope/index.md) +##### [com.drake.net.cache.Cache](../com.drake.net.cache/-cache/index.md) -| (extensions in package com.drake.net.utils) +| -##### [kotlinx.coroutines.CoroutineScope](../com.drake.net.utils/kotlinx.coroutines.-coroutine-scope/index.md) +##### [com.drake.net.exception.ConvertException](../com.drake.net.exception/-convert-exception/index.md) +转换数据异常 -| (extensions in package com.drake.net.utils) -##### [android.database.Cursor](../com.drake.net.utils/android.database.-cursor/index.md) +| (extensions in package com.drake.net) +##### [kotlinx.coroutines.CoroutineScope](../com.drake.net/kotlinx.coroutines.-coroutine-scope/index.md) -| -##### [com.drake.net.convert.DefaultConvert](../com.drake.net.convert/-default-convert/index.md) +| (extensions in package com.drake.net.exception) -默认的转换器实现, 如果不满足需求建议将该文件复制到项目中修改 +##### [kotlinx.coroutines.CoroutineScope](../com.drake.net.exception/kotlinx.coroutines.-coroutine-scope/index.md) + + +| (extensions in package com.drake.net.utils) + +##### [kotlinx.coroutines.CoroutineScope](../com.drake.net.utils/kotlinx.coroutines.-coroutine-scope/index.md) | (extensions in package com.drake.net.transform) @@ -70,6 +75,23 @@ 自动加载对话框网络请求 +| + +##### [com.drake.net.exception.DownloadFileException](../com.drake.net.exception/-download-file-exception/index.md) + +下载文件异常 + + +| (extensions in package com.drake.net.utils) + +##### [android.widget.EditText](../com.drake.net.utils/android.widget.-edit-text/index.md) + + +| (extensions in package com.drake.net.utils) + +##### [java.io.File](../com.drake.net.utils/java.io.-file/index.md) + + | (extensions in package com.drake.net.utils) ##### [kotlinx.coroutines.flow.Flow](../com.drake.net.utils/kotlinx.coroutines.flow.-flow/index.md) @@ -85,6 +107,13 @@ ##### [androidx.fragment.app.FragmentActivity](../com.drake.net.utils/androidx.fragment.app.-fragment-activity/index.md) +| + +##### [com.drake.net.component.InitContentProvider](../com.drake.net.component/-init-content-provider/index.md) + +用于初始化[NetConfig.app](../com.drake.net/-net-config/app.md) + + | ##### [com.drake.net.time.Interval](../com.drake.net.time/-interval/index.md) @@ -99,14 +128,61 @@ 计时器的状态 -| (extensions in package com.drake.net.utils) +| + +##### [com.drake.net.convert.JSONConvert](../com.drake.net.convert/-j-s-o-n-convert/index.md) + +默认的转换器实现, 如果不满足需求建议将该文件复制到项目中修改 + + +| + +##### [com.drake.net.tag.Label](../com.drake.net.tag/-label/index.md) + + +| + +##### [com.drake.net.log.LogRecorder](../com.drake.net.log/-log-recorder/index.md) -##### [androidx.lifecycle.LifecycleOwner](../com.drake.net.utils/androidx.lifecycle.-lifecycle-owner/index.md) +日志记录器 | -##### [com.drake.net.error.NetCancellationException](../com.drake.net.error/-net-cancellation-exception/index.md) +##### [com.drake.net.interceptor.LogRecordInterceptor](../com.drake.net.interceptor/-log-record-interceptor/index.md) + +网络日志记录器 +可以参考此拦截器为项目中其他网络请求库配置. 本拦截器属于标准的OkHttp拦截器适用于所有OkHttp拦截器内核的网络请求库 + + +| (extensions in package com.drake.net.request) + +##### [okhttp3.MediaType](../com.drake.net.request/okhttp3.-media-type/index.md) + + +| + +##### [com.drake.net.log.MessageType](../com.drake.net.log/-message-type/index.md) + + +| + +##### [com.drake.net.request.Method](../com.drake.net.request/-method/index.md) + + +| + +##### [com.drake.net.Net](../com.drake.net/-net/index.md) + + +| + +##### [com.drake.net.interfaces.NetCallback](../com.drake.net.interfaces/-net-callback/index.md) + + +| + +##### [com.drake.net.exception.NetCancellationException](../com.drake.net.exception/-net-cancellation-exception/index.md) 取消网络任务的异常 @@ -118,6 +194,11 @@ Net的全局配置 +| + +##### [com.drake.net.convert.NetConverter](../com.drake.net.convert/-net-converter/index.md) + + | ##### [com.drake.net.scope.NetCoroutineScope](../com.drake.net.scope/-net-coroutine-scope/index.md) @@ -125,6 +206,43 @@ Net的全局配置 自动显示网络错误信息协程作用域 +| + +##### [com.drake.net.exception.NetException](../com.drake.net.exception/-net-exception/index.md) + +Net网络异常 + + +| + +##### [com.drake.net.body.NetRequestBody](../com.drake.net.body/-net-request-body/index.md) + + +| + +##### [com.drake.net.body.NetResponseBody](../com.drake.net.body/-net-response-body/index.md) + + +| + +##### [com.drake.net.exception.NetSocketTimeoutException](../com.drake.net.exception/-net-socket-timeout-exception/index.md) + + +| + +##### [com.drake.net.exception.NetConnectException](../com.drake.net.exception/-networking-exception/index.md) + + +| + +##### [com.drake.net.exception.NoCacheException](../com.drake.net.exception/-no-cache-exception/index.md) + + +| (extensions in package com.drake.net.utils) + +##### [okhttp3.OkHttpClient](../com.drake.net.utils/okhttp3.-ok-http-client/index.md) + + | ##### [com.drake.net.scope.PageCoroutineScope](../com.drake.net.scope/-page-coroutine-scope/index.md) @@ -137,42 +255,58 @@ Net的全局配置 | -##### [com.drake.net.tag.REQUEST](../com.drake.net.tag/-r-e-q-u-e-s-t.md) - -请求参数打印标签 +##### [com.drake.net.request.Progress](../com.drake.net.request/-progress/index.md) | -##### [com.drake.net.error.RequestParamsException](../com.drake.net.error/-request-params-exception/index.md) +##### [com.drake.net.request.ProgressListener](../com.drake.net.request/-progress-listener/index.md) -404 +进度监听器, 为下载和上传两者 -| +| (extensions in package com.drake.net.request) + +##### [okhttp3.Request](../com.drake.net.request/okhttp3.-request/index.md) + -##### [com.drake.net.tag.RESPONSE](../com.drake.net.tag/-r-e-s-p-o-n-s-e.md) +| (extensions in package com.drake.net.body) -响应体打印标签 +##### [okhttp3.RequestBody](../com.drake.net.body/okhttp3.-request-body/index.md) | -##### [com.drake.net.error.ResponseException](../com.drake.net.error/-response-exception/index.md) +##### [com.drake.net.interceptor.RequestInterceptor](../com.drake.net.interceptor/-request-interceptor/index.md) -对应网络请求后台定义的错误信息 + +| + +##### [com.drake.net.exception.RequestParamsException](../com.drake.net.exception/-request-params-exception/index.md) + +404 + + +| (extensions in package com.drake.net.response) + +##### [okhttp3.Response](../com.drake.net.response/okhttp3.-response/index.md) + + +| (extensions in package com.drake.net.body) + +##### [okhttp3.ResponseBody](../com.drake.net.body/okhttp3.-response-body/index.md) | -##### [com.drake.net.utils.SavedViewModel](../com.drake.net.utils/-saved-view-model/index.md) +##### [com.drake.net.exception.ResponseException](../com.drake.net.exception/-response-exception/index.md) -继承这个类可以快速创建具备saveInstance的ViewModel +对应网络请求后台定义的错误信息 | -##### [com.drake.net.error.ServerResponseException](../com.drake.net.error/-server-response-exception/index.md) +##### [com.drake.net.exception.ServerResponseException](../com.drake.net.exception/-server-response-exception/index.md) 500 @@ -189,13 +323,20 @@ Net的全局配置 ##### [com.drake.statelayout.StateLayout](../com.drake.net.utils/com.drake.statelayout.-state-layout/index.md) +| (extensions in package com.drake.net.utils) + +##### [kotlin.String](../com.drake.net.utils/kotlin.-string/index.md) + + | -##### [com.drake.net.tag.TAG](../com.drake.net.tag/-t-a-g/index.md) +##### [com.drake.net.exception.URLParseException](../com.drake.net.exception/-u-r-l-parse-exception/index.md) +URL地址错误 -| (extensions in package com.drake.net.utils) -##### [androidx.lifecycle.ViewModelStoreOwner](../com.drake.net.utils/androidx.lifecycle.-view-model-store-owner/index.md) +| + +##### [com.drake.net.request.UrlRequest](../com.drake.net.request/-url-request/index.md) diff --git a/docs/api/net/androidx.lifecycle/index.md b/docs/api/net/androidx.lifecycle/index.md new file mode 100644 index 000000000..0e9f0d7ca --- /dev/null +++ b/docs/api/net/androidx.lifecycle/index.md @@ -0,0 +1,10 @@ +[net](../index.md) / [androidx.lifecycle](./index.md) + +## Package androidx.lifecycle + +### Functions + +| Name | Summary | +|---|---| +| [scopeLife](scope-life.md) | 在[ViewModel](#)被销毁时取消协程作用域`fun ViewModel.scopeLife(dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`AndroidScope`](../com.drake.net.scope/-android-scope/index.md) | +| [scopeNetLife](scope-net-life.md) | 在[ViewModel](#)被销毁时取消协程作用域以及其中的网络请求 具备网络错误全局处理功能, 其内部的网络请求会跟随其作用域的生命周期`fun ViewModel.scopeNetLife(dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`NetCoroutineScope`](../com.drake.net.scope/-net-coroutine-scope/index.md) | diff --git a/docs/api/net/androidx.lifecycle/scope-life.md b/docs/api/net/androidx.lifecycle/scope-life.md new file mode 100644 index 000000000..2d012998d --- /dev/null +++ b/docs/api/net/androidx.lifecycle/scope-life.md @@ -0,0 +1,8 @@ +[net](../index.md) / [androidx.lifecycle](index.md) / [scopeLife](./scope-life.md) + +# scopeLife + +`fun ViewModel.scopeLife(dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`AndroidScope`](../com.drake.net.scope/-android-scope/index.md) + +在[ViewModel](#)被销毁时取消协程作用域 + diff --git a/docs/api/net/androidx.lifecycle/scope-net-life.md b/docs/api/net/androidx.lifecycle/scope-net-life.md new file mode 100644 index 000000000..4d1f4df95 --- /dev/null +++ b/docs/api/net/androidx.lifecycle/scope-net-life.md @@ -0,0 +1,9 @@ +[net](../index.md) / [androidx.lifecycle](index.md) / [scopeNetLife](./scope-net-life.md) + +# scopeNetLife + +`fun ViewModel.scopeNetLife(dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`NetCoroutineScope`](../com.drake.net.scope/-net-coroutine-scope/index.md) + +在[ViewModel](#)被销毁时取消协程作用域以及其中的网络请求 +具备网络错误全局处理功能, 其内部的网络请求会跟随其作用域的生命周期 + diff --git a/docs/api/net/com.drake.net.body/-net-request-body/-init-.md b/docs/api/net/com.drake.net.body/-net-request-body/-init-.md new file mode 100644 index 000000000..faae9e45c --- /dev/null +++ b/docs/api/net/com.drake.net.body/-net-request-body/-init-.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.body](../index.md) / [NetRequestBody](index.md) / [<init>](./-init-.md) + +# <init> + +`NetRequestBody(requestBody: RequestBody, progressListeners: `[`ConcurrentLinkedQueue`](https://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html)`<`[`ProgressListener`](../../com.drake.net.request/-progress-listener/index.md)`>? = null)` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.body/-net-request-body/content-length.md b/docs/api/net/com.drake.net.body/-net-request-body/content-length.md new file mode 100644 index 000000000..221d8aa96 --- /dev/null +++ b/docs/api/net/com.drake.net.body/-net-request-body/content-length.md @@ -0,0 +1,6 @@ +[net](../../index.md) / [com.drake.net.body](../index.md) / [NetRequestBody](index.md) / [contentLength](./content-length.md) + +# contentLength + +`var contentLength: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) +`fun contentLength(): `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.body/-net-request-body/content-type.md b/docs/api/net/com.drake.net.body/-net-request-body/content-type.md new file mode 100644 index 000000000..45fd49389 --- /dev/null +++ b/docs/api/net/com.drake.net.body/-net-request-body/content-type.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.body](../index.md) / [NetRequestBody](index.md) / [contentType](./content-type.md) + +# contentType + +`fun contentType(): MediaType?` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.body/-net-request-body/index.md b/docs/api/net/com.drake.net.body/-net-request-body/index.md new file mode 100644 index 000000000..2d906f2a9 --- /dev/null +++ b/docs/api/net/com.drake.net.body/-net-request-body/index.md @@ -0,0 +1,26 @@ +[net](../../index.md) / [com.drake.net.body](../index.md) / [NetRequestBody](./index.md) + +# NetRequestBody + +`class NetRequestBody : RequestBody` + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `NetRequestBody(requestBody: RequestBody, progressListeners: `[`ConcurrentLinkedQueue`](https://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html)`<`[`ProgressListener`](../../com.drake.net.request/-progress-listener/index.md)`>? = null)` | + +### Properties + +| Name | Summary | +|---|---| +| [contentLength](content-length.md) | `var contentLength: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | + +### Functions + +| Name | Summary | +|---|---| +| [contentLength](content-length.md) | `fun contentLength(): `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | +| [contentType](content-type.md) | `fun contentType(): MediaType?` | +| [toString](to-string.md) | `fun toString(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | +| [writeTo](write-to.md) | `fun writeTo(sink: BufferedSink): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | diff --git a/docs/api/net/com.drake.net.body/-net-request-body/to-string.md b/docs/api/net/com.drake.net.body/-net-request-body/to-string.md new file mode 100644 index 000000000..4bcc2f159 --- /dev/null +++ b/docs/api/net/com.drake.net.body/-net-request-body/to-string.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.body](../index.md) / [NetRequestBody](index.md) / [toString](./to-string.md) + +# toString + +`fun toString(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.body/-net-request-body/write-to.md b/docs/api/net/com.drake.net.body/-net-request-body/write-to.md new file mode 100644 index 000000000..c2936e6fd --- /dev/null +++ b/docs/api/net/com.drake.net.body/-net-request-body/write-to.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.body](../index.md) / [NetRequestBody](index.md) / [writeTo](./write-to.md) + +# writeTo + +`fun writeTo(sink: BufferedSink): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.body/-net-response-body/-init-.md b/docs/api/net/com.drake.net.body/-net-response-body/-init-.md new file mode 100644 index 000000000..c5b7e01c0 --- /dev/null +++ b/docs/api/net/com.drake.net.body/-net-response-body/-init-.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.body](../index.md) / [NetResponseBody](index.md) / [<init>](./-init-.md) + +# <init> + +`NetResponseBody(request: Request, responseBody: ResponseBody)` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.body/-net-response-body/content-length.md b/docs/api/net/com.drake.net.body/-net-response-body/content-length.md new file mode 100644 index 000000000..5221cfb5a --- /dev/null +++ b/docs/api/net/com.drake.net.body/-net-response-body/content-length.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.body](../index.md) / [NetResponseBody](index.md) / [contentLength](./content-length.md) + +# contentLength + +`fun contentLength(): `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.body/-net-response-body/content-type.md b/docs/api/net/com.drake.net.body/-net-response-body/content-type.md new file mode 100644 index 000000000..d11cc2795 --- /dev/null +++ b/docs/api/net/com.drake.net.body/-net-response-body/content-type.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.body](../index.md) / [NetResponseBody](index.md) / [contentType](./content-type.md) + +# contentType + +`fun contentType(): MediaType?` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.body/-net-response-body/index.md b/docs/api/net/com.drake.net.body/-net-response-body/index.md new file mode 100644 index 000000000..8140cb683 --- /dev/null +++ b/docs/api/net/com.drake.net.body/-net-response-body/index.md @@ -0,0 +1,19 @@ +[net](../../index.md) / [com.drake.net.body](../index.md) / [NetResponseBody](./index.md) + +# NetResponseBody + +`class NetResponseBody : ResponseBody` + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `NetResponseBody(request: Request, responseBody: ResponseBody)` | + +### Functions + +| Name | Summary | +|---|---| +| [contentLength](content-length.md) | `fun contentLength(): `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | +| [contentType](content-type.md) | `fun contentType(): MediaType?` | +| [source](source.md) | `fun source(): BufferedSource` | diff --git a/docs/api/net/com.drake.net.body/-net-response-body/source.md b/docs/api/net/com.drake.net.body/-net-response-body/source.md new file mode 100644 index 000000000..46ee31fab --- /dev/null +++ b/docs/api/net/com.drake.net.body/-net-response-body/source.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.body](../index.md) / [NetResponseBody](index.md) / [source](./source.md) + +# source + +`fun source(): BufferedSource` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.body/index.md b/docs/api/net/com.drake.net.body/index.md new file mode 100644 index 000000000..5032c4212 --- /dev/null +++ b/docs/api/net/com.drake.net.body/index.md @@ -0,0 +1,17 @@ +[net](../index.md) / [com.drake.net.body](./index.md) + +## Package com.drake.net.body + +### Types + +| Name | Summary | +|---|---| +| [NetRequestBody](-net-request-body/index.md) | `class NetRequestBody : RequestBody` | +| [NetResponseBody](-net-response-body/index.md) | `class NetResponseBody : ResponseBody` | + +### Extensions for External Classes + +| Name | Summary | +|---|---| +| [okhttp3.RequestBody](okhttp3.-request-body/index.md) | | +| [okhttp3.ResponseBody](okhttp3.-response-body/index.md) | | diff --git a/docs/api/net/com.drake.net.body/okhttp3.-request-body/add-listener.md b/docs/api/net/com.drake.net.body/okhttp3.-request-body/add-listener.md new file mode 100644 index 000000000..4e2bfb1d3 --- /dev/null +++ b/docs/api/net/com.drake.net.body/okhttp3.-request-body/add-listener.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.body](../index.md) / [okhttp3.RequestBody](index.md) / [addListener](./add-listener.md) + +# addListener + +`fun RequestBody.addListener(progressListener: `[`ConcurrentLinkedQueue`](https://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html)`<`[`ProgressListener`](../../com.drake.net.request/-progress-listener/index.md)`>?): ` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.body/okhttp3.-request-body/index.md b/docs/api/net/com.drake.net.body/okhttp3.-request-body/index.md new file mode 100644 index 000000000..f3fbc857f --- /dev/null +++ b/docs/api/net/com.drake.net.body/okhttp3.-request-body/index.md @@ -0,0 +1,7 @@ +[net](../../index.md) / [com.drake.net.body](../index.md) / [okhttp3.RequestBody](./index.md) + +### Extensions for okhttp3.RequestBody + +| Name | Summary | +|---|---| +| [addListener](add-listener.md) | `fun RequestBody.addListener(progressListener: `[`ConcurrentLinkedQueue`](https://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html)`<`[`ProgressListener`](../../com.drake.net.request/-progress-listener/index.md)`>?): ` | diff --git a/docs/api/net/com.drake.net.body/okhttp3.-response-body/add-listener.md b/docs/api/net/com.drake.net.body/okhttp3.-response-body/add-listener.md new file mode 100644 index 000000000..2d8bc65b1 --- /dev/null +++ b/docs/api/net/com.drake.net.body/okhttp3.-response-body/add-listener.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.body](../index.md) / [okhttp3.ResponseBody](index.md) / [addListener](./add-listener.md) + +# addListener + +`fun ResponseBody.addListener(request: Request): ` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.body/okhttp3.-response-body/index.md b/docs/api/net/com.drake.net.body/okhttp3.-response-body/index.md new file mode 100644 index 000000000..1c9b16ce2 --- /dev/null +++ b/docs/api/net/com.drake.net.body/okhttp3.-response-body/index.md @@ -0,0 +1,7 @@ +[net](../../index.md) / [com.drake.net.body](../index.md) / [okhttp3.ResponseBody](./index.md) + +### Extensions for okhttp3.ResponseBody + +| Name | Summary | +|---|---| +| [addListener](add-listener.md) | `fun ResponseBody.addListener(request: Request): ` | diff --git a/docs/api/net/com.drake.net.cache/-cache/-c-a-c-h-e.md b/docs/api/net/com.drake.net.cache/-cache/-c-a-c-h-e.md new file mode 100644 index 000000000..53241c742 --- /dev/null +++ b/docs/api/net/com.drake.net.cache/-cache/-c-a-c-h-e.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.cache](../index.md) / [Cache](index.md) / [CACHE](./-c-a-c-h-e.md) + +# CACHE + +`CACHE` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.cache/-cache/-h-e-a-d-e-r.md b/docs/api/net/com.drake.net.cache/-cache/-h-e-a-d-e-r.md new file mode 100644 index 000000000..1e0e50916 --- /dev/null +++ b/docs/api/net/com.drake.net.cache/-cache/-h-e-a-d-e-r.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.cache](../index.md) / [Cache](index.md) / [HEADER](./-h-e-a-d-e-r.md) + +# HEADER + +`HEADER` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.cache/-cache/-n-o-n-e.md b/docs/api/net/com.drake.net.cache/-cache/-n-o-n-e.md new file mode 100644 index 000000000..912da5b14 --- /dev/null +++ b/docs/api/net/com.drake.net.cache/-cache/-n-o-n-e.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.cache](../index.md) / [Cache](index.md) / [NONE](./-n-o-n-e.md) + +# NONE + +`NONE` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.cache/-cache/index.md b/docs/api/net/com.drake.net.cache/-cache/index.md new file mode 100644 index 000000000..0c0ff2b28 --- /dev/null +++ b/docs/api/net/com.drake.net.cache/-cache/index.md @@ -0,0 +1,20 @@ +[net](../../index.md) / [com.drake.net.cache](../index.md) / [Cache](./index.md) + +# Cache + +`enum class Cache` + +### Enum Values + +| Name | Summary | +|---|---| +| [NONE](-n-o-n-e.md) | | +| [CACHE](-c-a-c-h-e.md) | | +| [HEADER](-h-e-a-d-e-r.md) | | + +### Extension Functions + +| Name | Summary | +|---|---| +| [failure](../failure.md) | `infix fun `[`Cache`](./index.md)`.failure(cache: `[`Cache`](./index.md)`): `[`Cache`](./index.md) | +| [success](../success.md) | `infix fun `[`Cache`](./index.md)`.success(cache: `[`Cache`](./index.md)`): `[`Cache`](./index.md) | diff --git a/docs/api/net/com.drake.net.cache/failure.md b/docs/api/net/com.drake.net.cache/failure.md new file mode 100644 index 000000000..0f33e06d4 --- /dev/null +++ b/docs/api/net/com.drake.net.cache/failure.md @@ -0,0 +1,5 @@ +[net](../index.md) / [com.drake.net.cache](index.md) / [failure](./failure.md) + +# failure + +`infix fun `[`Cache`](-cache/index.md)`.failure(cache: `[`Cache`](-cache/index.md)`): `[`Cache`](-cache/index.md) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.cache/index.md b/docs/api/net/com.drake.net.cache/index.md new file mode 100644 index 000000000..0e4d82645 --- /dev/null +++ b/docs/api/net/com.drake.net.cache/index.md @@ -0,0 +1,16 @@ +[net](../index.md) / [com.drake.net.cache](./index.md) + +## Package com.drake.net.cache + +### Types + +| Name | Summary | +|---|---| +| [Cache](-cache/index.md) | `enum class Cache` | + +### Functions + +| Name | Summary | +|---|---| +| [failure](failure.md) | `infix fun `[`Cache`](-cache/index.md)`.failure(cache: `[`Cache`](-cache/index.md)`): `[`Cache`](-cache/index.md) | +| [success](success.md) | `infix fun `[`Cache`](-cache/index.md)`.success(cache: `[`Cache`](-cache/index.md)`): `[`Cache`](-cache/index.md) | diff --git a/docs/api/net/com.drake.net.cache/success.md b/docs/api/net/com.drake.net.cache/success.md new file mode 100644 index 000000000..7e52a7e40 --- /dev/null +++ b/docs/api/net/com.drake.net.cache/success.md @@ -0,0 +1,5 @@ +[net](../index.md) / [com.drake.net.cache](index.md) / [success](./success.md) + +# success + +`infix fun `[`Cache`](-cache/index.md)`.success(cache: `[`Cache`](-cache/index.md)`): `[`Cache`](-cache/index.md) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.component/-init-content-provider/-init-.md b/docs/api/net/com.drake.net.component/-init-content-provider/-init-.md new file mode 100644 index 000000000..67ed991cf --- /dev/null +++ b/docs/api/net/com.drake.net.component/-init-content-provider/-init-.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.component](../index.md) / [InitContentProvider](index.md) / [<init>](./-init-.md) + +# <init> + +`InitContentProvider()` + +用于初始化[NetConfig.app](../../com.drake.net/-net-config/app.md) + diff --git a/docs/api/net/com.drake.net.component/-init-content-provider/delete.md b/docs/api/net/com.drake.net.component/-init-content-provider/delete.md new file mode 100644 index 000000000..4b7a7510e --- /dev/null +++ b/docs/api/net/com.drake.net.component/-init-content-provider/delete.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.component](../index.md) / [InitContentProvider](index.md) / [delete](./delete.md) + +# delete + +`fun delete(uri: `[`Uri`](https://developer.android.com/reference/android/net/Uri.html)`, selection: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?, selectionArgs: `[`Array`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>?): `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.component/-init-content-provider/get-type.md b/docs/api/net/com.drake.net.component/-init-content-provider/get-type.md new file mode 100644 index 000000000..846982cf7 --- /dev/null +++ b/docs/api/net/com.drake.net.component/-init-content-provider/get-type.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.component](../index.md) / [InitContentProvider](index.md) / [getType](./get-type.md) + +# getType + +`fun getType(uri: `[`Uri`](https://developer.android.com/reference/android/net/Uri.html)`): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.component/-init-content-provider/index.md b/docs/api/net/com.drake.net.component/-init-content-provider/index.md new file mode 100644 index 000000000..9e8c42d79 --- /dev/null +++ b/docs/api/net/com.drake.net.component/-init-content-provider/index.md @@ -0,0 +1,24 @@ +[net](../../index.md) / [com.drake.net.component](../index.md) / [InitContentProvider](./index.md) + +# InitContentProvider + +`class InitContentProvider : `[`ContentProvider`](https://developer.android.com/reference/android/content/ContentProvider.html) + +用于初始化[NetConfig.app](../../com.drake.net/-net-config/app.md) + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | 用于初始化[NetConfig.app](../../com.drake.net/-net-config/app.md)`InitContentProvider()` | + +### Functions + +| Name | Summary | +|---|---| +| [delete](delete.md) | `fun delete(uri: `[`Uri`](https://developer.android.com/reference/android/net/Uri.html)`, selection: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?, selectionArgs: `[`Array`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>?): `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | +| [getType](get-type.md) | `fun getType(uri: `[`Uri`](https://developer.android.com/reference/android/net/Uri.html)`): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?` | +| [insert](insert.md) | `fun insert(uri: `[`Uri`](https://developer.android.com/reference/android/net/Uri.html)`, values: `[`ContentValues`](https://developer.android.com/reference/android/content/ContentValues.html)`?): `[`Uri`](https://developer.android.com/reference/android/net/Uri.html)`?` | +| [onCreate](on-create.md) | `fun onCreate(): `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | +| [query](query.md) | `fun query(uri: `[`Uri`](https://developer.android.com/reference/android/net/Uri.html)`, projection: `[`Array`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>?, selection: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?, selectionArgs: `[`Array`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>?, sortOrder: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?): `[`Cursor`](https://developer.android.com/reference/android/database/Cursor.html)`?` | +| [update](update.md) | `fun update(uri: `[`Uri`](https://developer.android.com/reference/android/net/Uri.html)`, values: `[`ContentValues`](https://developer.android.com/reference/android/content/ContentValues.html)`?, selection: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?, selectionArgs: `[`Array`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>?): `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | diff --git a/docs/api/net/com.drake.net.component/-init-content-provider/insert.md b/docs/api/net/com.drake.net.component/-init-content-provider/insert.md new file mode 100644 index 000000000..caa5bd2f4 --- /dev/null +++ b/docs/api/net/com.drake.net.component/-init-content-provider/insert.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.component](../index.md) / [InitContentProvider](index.md) / [insert](./insert.md) + +# insert + +`fun insert(uri: `[`Uri`](https://developer.android.com/reference/android/net/Uri.html)`, values: `[`ContentValues`](https://developer.android.com/reference/android/content/ContentValues.html)`?): `[`Uri`](https://developer.android.com/reference/android/net/Uri.html)`?` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.component/-init-content-provider/on-create.md b/docs/api/net/com.drake.net.component/-init-content-provider/on-create.md new file mode 100644 index 000000000..efd9a1265 --- /dev/null +++ b/docs/api/net/com.drake.net.component/-init-content-provider/on-create.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.component](../index.md) / [InitContentProvider](index.md) / [onCreate](./on-create.md) + +# onCreate + +`fun onCreate(): `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.component/-init-content-provider/query.md b/docs/api/net/com.drake.net.component/-init-content-provider/query.md new file mode 100644 index 000000000..0d7e259bf --- /dev/null +++ b/docs/api/net/com.drake.net.component/-init-content-provider/query.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.component](../index.md) / [InitContentProvider](index.md) / [query](./query.md) + +# query + +`fun query(uri: `[`Uri`](https://developer.android.com/reference/android/net/Uri.html)`, projection: `[`Array`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>?, selection: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?, selectionArgs: `[`Array`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>?, sortOrder: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?): `[`Cursor`](https://developer.android.com/reference/android/database/Cursor.html)`?` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.component/-init-content-provider/update.md b/docs/api/net/com.drake.net.component/-init-content-provider/update.md new file mode 100644 index 000000000..32df1d41f --- /dev/null +++ b/docs/api/net/com.drake.net.component/-init-content-provider/update.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.component](../index.md) / [InitContentProvider](index.md) / [update](./update.md) + +# update + +`fun update(uri: `[`Uri`](https://developer.android.com/reference/android/net/Uri.html)`, values: `[`ContentValues`](https://developer.android.com/reference/android/content/ContentValues.html)`?, selection: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?, selectionArgs: `[`Array`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>?): `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.component/index.md b/docs/api/net/com.drake.net.component/index.md new file mode 100644 index 000000000..5fce47a8f --- /dev/null +++ b/docs/api/net/com.drake.net.component/index.md @@ -0,0 +1,9 @@ +[net](../index.md) / [com.drake.net.component](./index.md) + +## Package com.drake.net.component + +### Types + +| Name | Summary | +|---|---| +| [InitContentProvider](-init-content-provider/index.md) | 用于初始化[NetConfig.app](../com.drake.net/-net-config/app.md)`class InitContentProvider : `[`ContentProvider`](https://developer.android.com/reference/android/content/ContentProvider.html) | diff --git a/docs/api/net/com.drake.net.connect/-ok-http-connect-factory/-builder/build.md b/docs/api/net/com.drake.net.connect/-ok-http-connect-factory/-builder/build.md deleted file mode 100644 index 326456170..000000000 --- a/docs/api/net/com.drake.net.connect/-ok-http-connect-factory/-builder/build.md +++ /dev/null @@ -1,5 +0,0 @@ -[net](../../../index.md) / [com.drake.net.connect](../../index.md) / [OkHttpConnectFactory](../index.md) / [Builder](index.md) / [build](./build.md) - -# build - -`open fun build(): `[`OkHttpConnectFactory`](../index.md)`!` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.connect/-ok-http-connect-factory/-builder/client.md b/docs/api/net/com.drake.net.connect/-ok-http-connect-factory/-builder/client.md deleted file mode 100644 index 6fd2426d3..000000000 --- a/docs/api/net/com.drake.net.connect/-ok-http-connect-factory/-builder/client.md +++ /dev/null @@ -1,5 +0,0 @@ -[net](../../../index.md) / [com.drake.net.connect](../../index.md) / [OkHttpConnectFactory](../index.md) / [Builder](index.md) / [client](./client.md) - -# client - -`open fun client(client: OkHttpClient!): Builder!` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.connect/-ok-http-connect-factory/-builder/index.md b/docs/api/net/com.drake.net.connect/-ok-http-connect-factory/-builder/index.md deleted file mode 100644 index 0cbd63e2d..000000000 --- a/docs/api/net/com.drake.net.connect/-ok-http-connect-factory/-builder/index.md +++ /dev/null @@ -1,12 +0,0 @@ -[net](../../../index.md) / [com.drake.net.connect](../../index.md) / [OkHttpConnectFactory](../index.md) / [Builder](./index.md) - -# Builder - -`open class Builder` - -### Functions - -| Name | Summary | -|---|---| -| [build](build.md) | `open fun build(): `[`OkHttpConnectFactory`](../index.md)`!` | -| [client](client.md) | `open fun client(client: OkHttpClient!): Builder!` | diff --git a/docs/api/net/com.drake.net.connect/-ok-http-connect-factory/connect.md b/docs/api/net/com.drake.net.connect/-ok-http-connect-factory/connect.md deleted file mode 100644 index cacd0c14e..000000000 --- a/docs/api/net/com.drake.net.connect/-ok-http-connect-factory/connect.md +++ /dev/null @@ -1,5 +0,0 @@ -[net](../../index.md) / [com.drake.net.connect](../index.md) / [OkHttpConnectFactory](index.md) / [connect](./connect.md) - -# connect - -`open fun connect(request: Request!): Connection!` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.connect/-ok-http-connect-factory/index.md b/docs/api/net/com.drake.net.connect/-ok-http-connect-factory/index.md deleted file mode 100644 index 1f996aaac..000000000 --- a/docs/api/net/com.drake.net.connect/-ok-http-connect-factory/index.md +++ /dev/null @@ -1,20 +0,0 @@ -[net](../../index.md) / [com.drake.net.connect](../index.md) / [OkHttpConnectFactory](./index.md) - -# OkHttpConnectFactory - -`open class OkHttpConnectFactory : ConnectFactory` - -Created by Zhenjie Yan on 2016/10/15. - -### Types - -| Name | Summary | -|---|---| -| [Builder](-builder/index.md) | `open class Builder` | - -### Functions - -| Name | Summary | -|---|---| -| [connect](connect.md) | `open fun connect(request: Request!): Connection!` | -| [newBuilder](new-builder.md) | `open static fun newBuilder(): Builder!` | diff --git a/docs/api/net/com.drake.net.connect/-ok-http-connect-factory/new-builder.md b/docs/api/net/com.drake.net.connect/-ok-http-connect-factory/new-builder.md deleted file mode 100644 index 0e69977f1..000000000 --- a/docs/api/net/com.drake.net.connect/-ok-http-connect-factory/new-builder.md +++ /dev/null @@ -1,5 +0,0 @@ -[net](../../index.md) / [com.drake.net.connect](../index.md) / [OkHttpConnectFactory](index.md) / [newBuilder](./new-builder.md) - -# newBuilder - -`open static fun newBuilder(): Builder!` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.connect/index.md b/docs/api/net/com.drake.net.connect/index.md deleted file mode 100644 index f1f4cd9ca..000000000 --- a/docs/api/net/com.drake.net.connect/index.md +++ /dev/null @@ -1,9 +0,0 @@ -[net](../index.md) / [com.drake.net.connect](./index.md) - -## Package com.drake.net.connect - -### Types - -| Name | Summary | -|---|---| -| [OkHttpConnectFactory](-ok-http-connect-factory/index.md) | Created by Zhenjie Yan on 2016/10/15.`open class OkHttpConnectFactory : ConnectFactory` | diff --git a/docs/api/net/com.drake.net.convert/-default-convert/-init-.md b/docs/api/net/com.drake.net.convert/-default-convert/-init-.md deleted file mode 100644 index 281026efe..000000000 --- a/docs/api/net/com.drake.net.convert/-default-convert/-init-.md +++ /dev/null @@ -1,15 +0,0 @@ -[net](../../index.md) / [com.drake.net.convert](../index.md) / [DefaultConvert](index.md) / [<init>](./-init-.md) - -# <init> - -`DefaultConvert(success: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "0", code: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "code", message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "msg")` - -默认的转换器实现, 如果不满足需求建议将该文件复制到项目中修改 - -### Parameters - -`success` - 后端定义为成功状态的错误码值 - -`code` - 错误码在JSON中的字段名 - -`message` - 错误信息在JSON中的字段名 \ No newline at end of file diff --git a/docs/api/net/com.drake.net.convert/-default-convert/convert.md b/docs/api/net/com.drake.net.convert/-default-convert/convert.md deleted file mode 100644 index 64ff1615c..000000000 --- a/docs/api/net/com.drake.net.convert/-default-convert/convert.md +++ /dev/null @@ -1,5 +0,0 @@ -[net](../../index.md) / [com.drake.net.convert](../index.md) / [DefaultConvert](index.md) / [convert](./convert.md) - -# convert - -`open fun convert(succeed: `[`Type`](https://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Type.html)`, failed: `[`Type`](https://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Type.html)`, request: Request, response: Response, result: Result): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.convert/-default-convert/index.md b/docs/api/net/com.drake.net.convert/-default-convert/index.md deleted file mode 100644 index 84234ce03..000000000 --- a/docs/api/net/com.drake.net.convert/-default-convert/index.md +++ /dev/null @@ -1,36 +0,0 @@ -[net](../../index.md) / [com.drake.net.convert](../index.md) / [DefaultConvert](./index.md) - -# DefaultConvert - -`abstract class DefaultConvert : Converter` - -默认的转换器实现, 如果不满足需求建议将该文件复制到项目中修改 - -### Parameters - -`success` - 后端定义为成功状态的错误码值 - -`code` - 错误码在JSON中的字段名 - -`message` - 错误信息在JSON中的字段名 - -### Constructors - -| Name | Summary | -|---|---| -| [<init>](-init-.md) | 默认的转换器实现, 如果不满足需求建议将该文件复制到项目中修改`DefaultConvert(success: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "0", code: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "code", message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "msg")` | - -### Properties - -| Name | Summary | -|---|---| -| [code](code.md) | 错误码在JSON中的字段名`val code: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | -| [message](message.md) | 错误信息在JSON中的字段名`val message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | -| [success](success.md) | 后端定义为成功状态的错误码值`val success: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | - -### Functions - -| Name | Summary | -|---|---| -| [convert](convert.md) | `open fun convert(succeed: `[`Type`](https://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Type.html)`, failed: `[`Type`](https://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Type.html)`, request: Request, response: Response, result: Result): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | -| [parseBody](parse-body.md) | 解析字符串数据 一般用于解析JSON`abstract fun `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`.parseBody(succeed: `[`Type`](https://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Type.html)`): S?` | diff --git a/docs/api/net/com.drake.net.convert/-j-s-o-n-convert/-init-.md b/docs/api/net/com.drake.net.convert/-j-s-o-n-convert/-init-.md new file mode 100644 index 000000000..d117692f8 --- /dev/null +++ b/docs/api/net/com.drake.net.convert/-j-s-o-n-convert/-init-.md @@ -0,0 +1,15 @@ +[net](../../index.md) / [com.drake.net.convert](../index.md) / [JSONConvert](index.md) / [<init>](./-init-.md) + +# <init> + +`JSONConvert(success: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "0", code: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "code", message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "msg")` + +默认的转换器实现, 如果不满足需求建议将该文件复制到项目中修改 + +### Parameters + +`success` - 后端定义为成功状态的错误码值 + +`code` - 错误码在JSON中的字段名 + +`message` - 错误信息在JSON中的字段名 \ No newline at end of file diff --git a/docs/api/net/com.drake.net.convert/-default-convert/code.md b/docs/api/net/com.drake.net.convert/-j-s-o-n-convert/code.md similarity index 81% rename from docs/api/net/com.drake.net.convert/-default-convert/code.md rename to docs/api/net/com.drake.net.convert/-j-s-o-n-convert/code.md index 7993e5b3c..905e2792b 100644 --- a/docs/api/net/com.drake.net.convert/-default-convert/code.md +++ b/docs/api/net/com.drake.net.convert/-j-s-o-n-convert/code.md @@ -1,4 +1,4 @@ -[net](../../index.md) / [com.drake.net.convert](../index.md) / [DefaultConvert](index.md) / [code](./code.md) +[net](../../index.md) / [com.drake.net.convert](../index.md) / [JSONConvert](index.md) / [code](./code.md) # code diff --git a/docs/api/net/com.drake.net.convert/-j-s-o-n-convert/index.md b/docs/api/net/com.drake.net.convert/-j-s-o-n-convert/index.md new file mode 100644 index 000000000..19b8b39ff --- /dev/null +++ b/docs/api/net/com.drake.net.convert/-j-s-o-n-convert/index.md @@ -0,0 +1,36 @@ +[net](../../index.md) / [com.drake.net.convert](../index.md) / [JSONConvert](./index.md) + +# JSONConvert + +`abstract class JSONConvert : `[`NetConverter`](../-net-converter/index.md) + +默认的转换器实现, 如果不满足需求建议将该文件复制到项目中修改 + +### Parameters + +`success` - 后端定义为成功状态的错误码值 + +`code` - 错误码在JSON中的字段名 + +`message` - 错误信息在JSON中的字段名 + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | 默认的转换器实现, 如果不满足需求建议将该文件复制到项目中修改`JSONConvert(success: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "0", code: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "code", message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "msg")` | + +### Properties + +| Name | Summary | +|---|---| +| [code](code.md) | 错误码在JSON中的字段名`val code: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | +| [message](message.md) | 错误信息在JSON中的字段名`val message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | +| [success](success.md) | 后端定义为成功状态的错误码值`val success: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | + +### Functions + +| Name | Summary | +|---|---| +| [onConvert](on-convert.md) | `open fun onConvert(succeed: `[`Type`](https://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Type.html)`, response: Response): R?` | +| [parseBody](parse-body.md) | 反序列化JSON`abstract fun `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`.parseBody(succeed: `[`Type`](https://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Type.html)`): S?` | diff --git a/docs/api/net/com.drake.net.convert/-default-convert/message.md b/docs/api/net/com.drake.net.convert/-j-s-o-n-convert/message.md similarity index 80% rename from docs/api/net/com.drake.net.convert/-default-convert/message.md rename to docs/api/net/com.drake.net.convert/-j-s-o-n-convert/message.md index 38b507985..22844dae3 100644 --- a/docs/api/net/com.drake.net.convert/-default-convert/message.md +++ b/docs/api/net/com.drake.net.convert/-j-s-o-n-convert/message.md @@ -1,4 +1,4 @@ -[net](../../index.md) / [com.drake.net.convert](../index.md) / [DefaultConvert](index.md) / [message](./message.md) +[net](../../index.md) / [com.drake.net.convert](../index.md) / [JSONConvert](index.md) / [message](./message.md) # message diff --git a/docs/api/net/com.drake.net.convert/-j-s-o-n-convert/on-convert.md b/docs/api/net/com.drake.net.convert/-j-s-o-n-convert/on-convert.md new file mode 100644 index 000000000..ac44663d8 --- /dev/null +++ b/docs/api/net/com.drake.net.convert/-j-s-o-n-convert/on-convert.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.convert](../index.md) / [JSONConvert](index.md) / [onConvert](./on-convert.md) + +# onConvert + +`open fun onConvert(succeed: `[`Type`](https://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Type.html)`, response: Response): R?` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.convert/-default-convert/parse-body.md b/docs/api/net/com.drake.net.convert/-j-s-o-n-convert/parse-body.md similarity index 63% rename from docs/api/net/com.drake.net.convert/-default-convert/parse-body.md rename to docs/api/net/com.drake.net.convert/-j-s-o-n-convert/parse-body.md index a60dff64a..ec55f49c8 100644 --- a/docs/api/net/com.drake.net.convert/-default-convert/parse-body.md +++ b/docs/api/net/com.drake.net.convert/-j-s-o-n-convert/parse-body.md @@ -1,15 +1,14 @@ -[net](../../index.md) / [com.drake.net.convert](../index.md) / [DefaultConvert](index.md) / [parseBody](./parse-body.md) +[net](../../index.md) / [com.drake.net.convert](../index.md) / [JSONConvert](index.md) / [parseBody](./parse-body.md) # parseBody `abstract fun `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`.parseBody(succeed: `[`Type`](https://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Type.html)`): S?` -解析字符串数据 -一般用于解析JSON +反序列化JSON ### Parameters -`succeed` - 请求函数定义的泛型, 例如一般的Moshi/Gson解析数据需要使用 +`succeed` - JSON对象的类型 **Receiver** 原始字符串 diff --git a/docs/api/net/com.drake.net.convert/-default-convert/success.md b/docs/api/net/com.drake.net.convert/-j-s-o-n-convert/success.md similarity index 80% rename from docs/api/net/com.drake.net.convert/-default-convert/success.md rename to docs/api/net/com.drake.net.convert/-j-s-o-n-convert/success.md index b25de9bc0..95be122ba 100644 --- a/docs/api/net/com.drake.net.convert/-default-convert/success.md +++ b/docs/api/net/com.drake.net.convert/-j-s-o-n-convert/success.md @@ -1,4 +1,4 @@ -[net](../../index.md) / [com.drake.net.convert](../index.md) / [DefaultConvert](index.md) / [success](./success.md) +[net](../../index.md) / [com.drake.net.convert](../index.md) / [JSONConvert](index.md) / [success](./success.md) # success diff --git a/docs/api/net/com.drake.net.convert/-net-converter/-d-e-f-a-u-l-t.md b/docs/api/net/com.drake.net.convert/-net-converter/-d-e-f-a-u-l-t.md new file mode 100644 index 000000000..576b63eae --- /dev/null +++ b/docs/api/net/com.drake.net.convert/-net-converter/-d-e-f-a-u-l-t.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.convert](../index.md) / [NetConverter](index.md) / [DEFAULT](./-d-e-f-a-u-l-t.md) + +# DEFAULT + +`val DEFAULT: `[`NetConverter`](index.md) + +返回数据为字符串内容 + diff --git a/docs/api/net/com.drake.net.convert/-net-converter/index.md b/docs/api/net/com.drake.net.convert/-net-converter/index.md new file mode 100644 index 000000000..292d6b2bc --- /dev/null +++ b/docs/api/net/com.drake.net.convert/-net-converter/index.md @@ -0,0 +1,23 @@ +[net](../../index.md) / [com.drake.net.convert](../index.md) / [NetConverter](./index.md) + +# NetConverter + +`interface NetConverter` + +### Functions + +| Name | Summary | +|---|---| +| [onConvert](on-convert.md) | `abstract fun onConvert(succeed: `[`Type`](https://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Type.html)`, response: Response): R?` | + +### Companion Object Properties + +| Name | Summary | +|---|---| +| [DEFAULT](-d-e-f-a-u-l-t.md) | 返回数据为字符串内容`val DEFAULT: `[`NetConverter`](./index.md) | + +### Inheritors + +| Name | Summary | +|---|---| +| [JSONConvert](../-j-s-o-n-convert/index.md) | 默认的转换器实现, 如果不满足需求建议将该文件复制到项目中修改`abstract class JSONConvert : `[`NetConverter`](./index.md) | diff --git a/docs/api/net/com.drake.net.convert/-net-converter/on-convert.md b/docs/api/net/com.drake.net.convert/-net-converter/on-convert.md new file mode 100644 index 000000000..faa8e4a6f --- /dev/null +++ b/docs/api/net/com.drake.net.convert/-net-converter/on-convert.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.convert](../index.md) / [NetConverter](index.md) / [onConvert](./on-convert.md) + +# onConvert + +`abstract fun onConvert(succeed: `[`Type`](https://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Type.html)`, response: Response): R?` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.convert/index.md b/docs/api/net/com.drake.net.convert/index.md index 11a9879a3..a8c965f1d 100644 --- a/docs/api/net/com.drake.net.convert/index.md +++ b/docs/api/net/com.drake.net.convert/index.md @@ -6,4 +6,5 @@ | Name | Summary | |---|---| -| [DefaultConvert](-default-convert/index.md) | 默认的转换器实现, 如果不满足需求建议将该文件复制到项目中修改`abstract class DefaultConvert : Converter` | +| [JSONConvert](-j-s-o-n-convert/index.md) | 默认的转换器实现, 如果不满足需求建议将该文件复制到项目中修改`abstract class JSONConvert : `[`NetConverter`](-net-converter/index.md) | +| [NetConverter](-net-converter/index.md) | `interface NetConverter` | diff --git a/docs/api/net/com.drake.net.error/-request-params-exception/-init-.md b/docs/api/net/com.drake.net.error/-request-params-exception/-init-.md deleted file mode 100644 index 895f40f05..000000000 --- a/docs/api/net/com.drake.net.error/-request-params-exception/-init-.md +++ /dev/null @@ -1,8 +0,0 @@ -[net](../../index.md) / [com.drake.net.error](../index.md) / [RequestParamsException](index.md) / [<init>](./-init-.md) - -# <init> - -`RequestParamsException(code: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, request: Request)` - -404 - diff --git a/docs/api/net/com.drake.net.error/-request-params-exception/code.md b/docs/api/net/com.drake.net.error/-request-params-exception/code.md deleted file mode 100644 index cdda117aa..000000000 --- a/docs/api/net/com.drake.net.error/-request-params-exception/code.md +++ /dev/null @@ -1,5 +0,0 @@ -[net](../../index.md) / [com.drake.net.error](../index.md) / [RequestParamsException](index.md) / [code](./code.md) - -# code - -`val code: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.error/-request-params-exception/index.md b/docs/api/net/com.drake.net.error/-request-params-exception/index.md deleted file mode 100644 index 8d094c1ac..000000000 --- a/docs/api/net/com.drake.net.error/-request-params-exception/index.md +++ /dev/null @@ -1,19 +0,0 @@ -[net](../../index.md) / [com.drake.net.error](../index.md) / [RequestParamsException](./index.md) - -# RequestParamsException - -`class RequestParamsException : NetException` - -404 - -### Constructors - -| Name | Summary | -|---|---| -| [<init>](-init-.md) | 404`RequestParamsException(code: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, request: Request)` | - -### Properties - -| Name | Summary | -|---|---| -| [code](code.md) | `val code: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | diff --git a/docs/api/net/com.drake.net.error/-response-exception/-init-.md b/docs/api/net/com.drake.net.error/-response-exception/-init-.md deleted file mode 100644 index fa1155b70..000000000 --- a/docs/api/net/com.drake.net.error/-response-exception/-init-.md +++ /dev/null @@ -1,15 +0,0 @@ -[net](../../index.md) / [com.drake.net.error](../index.md) / [ResponseException](index.md) / [<init>](./-init-.md) - -# <init> - -`ResponseException(code: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, msg: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, request: Request)` - -对应网络请求后台定义的错误信息 - -### Parameters - -`msg` - 网络请求错误信息 - -`code` - 网络请求错误码 - -`tag` - 应对错误码判断为错时但是后端又返回了需要使用的数据(建议后端修改). 一般在Convert中设置数据 \ No newline at end of file diff --git a/docs/api/net/com.drake.net.error/-response-exception/code.md b/docs/api/net/com.drake.net.error/-response-exception/code.md deleted file mode 100644 index 0509c1342..000000000 --- a/docs/api/net/com.drake.net.error/-response-exception/code.md +++ /dev/null @@ -1,8 +0,0 @@ -[net](../../index.md) / [com.drake.net.error](../index.md) / [ResponseException](index.md) / [code](./code.md) - -# code - -`val code: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) - -网络请求错误码 - diff --git a/docs/api/net/com.drake.net.error/-response-exception/index.md b/docs/api/net/com.drake.net.error/-response-exception/index.md deleted file mode 100644 index 151f2a26d..000000000 --- a/docs/api/net/com.drake.net.error/-response-exception/index.md +++ /dev/null @@ -1,28 +0,0 @@ -[net](../../index.md) / [com.drake.net.error](../index.md) / [ResponseException](./index.md) - -# ResponseException - -`class ResponseException : NetException` - -对应网络请求后台定义的错误信息 - -### Parameters - -`msg` - 网络请求错误信息 - -`code` - 网络请求错误码 - -`tag` - 应对错误码判断为错时但是后端又返回了需要使用的数据(建议后端修改). 一般在Convert中设置数据 - -### Constructors - -| Name | Summary | -|---|---| -| [<init>](-init-.md) | 对应网络请求后台定义的错误信息`ResponseException(code: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, msg: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, request: Request)` | - -### Properties - -| Name | Summary | -|---|---| -| [code](code.md) | 网络请求错误码`val code: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | -| [msg](msg.md) | 网络请求错误信息`val msg: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | diff --git a/docs/api/net/com.drake.net.error/-response-exception/msg.md b/docs/api/net/com.drake.net.error/-response-exception/msg.md deleted file mode 100644 index f0a1f6464..000000000 --- a/docs/api/net/com.drake.net.error/-response-exception/msg.md +++ /dev/null @@ -1,8 +0,0 @@ -[net](../../index.md) / [com.drake.net.error](../index.md) / [ResponseException](index.md) / [msg](./msg.md) - -# msg - -`val msg: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) - -网络请求错误信息 - diff --git a/docs/api/net/com.drake.net.error/-server-response-exception/-init-.md b/docs/api/net/com.drake.net.error/-server-response-exception/-init-.md deleted file mode 100644 index 87c554842..000000000 --- a/docs/api/net/com.drake.net.error/-server-response-exception/-init-.md +++ /dev/null @@ -1,8 +0,0 @@ -[net](../../index.md) / [com.drake.net.error](../index.md) / [ServerResponseException](index.md) / [<init>](./-init-.md) - -# <init> - -`ServerResponseException(code: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, request: Request)` - -500 - diff --git a/docs/api/net/com.drake.net.error/-server-response-exception/code.md b/docs/api/net/com.drake.net.error/-server-response-exception/code.md deleted file mode 100644 index 198423caf..000000000 --- a/docs/api/net/com.drake.net.error/-server-response-exception/code.md +++ /dev/null @@ -1,5 +0,0 @@ -[net](../../index.md) / [com.drake.net.error](../index.md) / [ServerResponseException](index.md) / [code](./code.md) - -# code - -`val code: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.error/-server-response-exception/index.md b/docs/api/net/com.drake.net.error/-server-response-exception/index.md deleted file mode 100644 index f81919917..000000000 --- a/docs/api/net/com.drake.net.error/-server-response-exception/index.md +++ /dev/null @@ -1,19 +0,0 @@ -[net](../../index.md) / [com.drake.net.error](../index.md) / [ServerResponseException](./index.md) - -# ServerResponseException - -`class ServerResponseException : NetException` - -500 - -### Constructors - -| Name | Summary | -|---|---| -| [<init>](-init-.md) | 500`ServerResponseException(code: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, request: Request)` | - -### Properties - -| Name | Summary | -|---|---| -| [code](code.md) | `val code: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | diff --git a/docs/api/net/com.drake.net.error/index.md b/docs/api/net/com.drake.net.error/index.md deleted file mode 100644 index 7bdc85a86..000000000 --- a/docs/api/net/com.drake.net.error/index.md +++ /dev/null @@ -1,18 +0,0 @@ -[net](../index.md) / [com.drake.net.error](./index.md) - -## Package com.drake.net.error - -### Exceptions - -| Name | Summary | -|---|---| -| [NetCancellationException](-net-cancellation-exception/index.md) | 取消网络任务的异常`class NetCancellationException : `[`CancellationException`](https://docs.oracle.com/javase/6/docs/api/java/util/concurrent/CancellationException.html) | -| [RequestParamsException](-request-params-exception/index.md) | 404`class RequestParamsException : NetException` | -| [ResponseException](-response-exception/index.md) | 对应网络请求后台定义的错误信息`class ResponseException : NetException` | -| [ServerResponseException](-server-response-exception/index.md) | 500`class ServerResponseException : NetException` | - -### Extensions for External Classes - -| Name | Summary | -|---|---| -| [kotlinx.coroutines.CoroutineScope](kotlinx.coroutines.-coroutine-scope/index.md) | | diff --git a/docs/api/net/com.drake.net.exception/-convert-exception/-init-.md b/docs/api/net/com.drake.net.exception/-convert-exception/-init-.md new file mode 100644 index 000000000..4a0e8487f --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-convert-exception/-init-.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [ConvertException](index.md) / [<init>](./-init-.md) + +# <init> + +`ConvertException(response: Response, message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "An exception occurred while converting the data", cause: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`? = null)` + +转换数据异常 + diff --git a/docs/api/net/com.drake.net.exception/-convert-exception/index.md b/docs/api/net/com.drake.net.exception/-convert-exception/index.md new file mode 100644 index 000000000..322ff55af --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-convert-exception/index.md @@ -0,0 +1,19 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [ConvertException](./index.md) + +# ConvertException + +`class ConvertException : `[`NetException`](../-net-exception/index.md) + +转换数据异常 + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | 转换数据异常`ConvertException(response: Response, message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "An exception occurred while converting the data", cause: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`? = null)` | + +### Properties + +| Name | Summary | +|---|---| +| [response](response.md) | `val response: Response` | diff --git a/docs/api/net/com.drake.net.exception/-convert-exception/response.md b/docs/api/net/com.drake.net.exception/-convert-exception/response.md new file mode 100644 index 000000000..8c86798a6 --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-convert-exception/response.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [ConvertException](index.md) / [response](./response.md) + +# response + +`val response: Response` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.exception/-download-file-exception/-init-.md b/docs/api/net/com.drake.net.exception/-download-file-exception/-init-.md new file mode 100644 index 000000000..43749dcbf --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-download-file-exception/-init-.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [DownloadFileException](index.md) / [<init>](./-init-.md) + +# <init> + +`DownloadFileException(response: Response, message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`? = "", cause: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`? = null)` + +下载文件异常 + diff --git a/docs/api/net/com.drake.net.exception/-download-file-exception/index.md b/docs/api/net/com.drake.net.exception/-download-file-exception/index.md new file mode 100644 index 000000000..b4b39391d --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-download-file-exception/index.md @@ -0,0 +1,13 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [DownloadFileException](./index.md) + +# DownloadFileException + +`class DownloadFileException : `[`NetException`](../-net-exception/index.md) + +下载文件异常 + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | 下载文件异常`DownloadFileException(response: Response, message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`? = "", cause: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`? = null)` | diff --git a/docs/api/net/com.drake.net.error/-net-cancellation-exception/-init-.md b/docs/api/net/com.drake.net.exception/-net-cancellation-exception/-init-.md similarity index 61% rename from docs/api/net/com.drake.net.error/-net-cancellation-exception/-init-.md rename to docs/api/net/com.drake.net.exception/-net-cancellation-exception/-init-.md index e2c9416c5..799ed4e0b 100644 --- a/docs/api/net/com.drake.net.error/-net-cancellation-exception/-init-.md +++ b/docs/api/net/com.drake.net.exception/-net-cancellation-exception/-init-.md @@ -1,4 +1,4 @@ -[net](../../index.md) / [com.drake.net.error](../index.md) / [NetCancellationException](index.md) / [<init>](./-init-.md) +[net](../../index.md) / [com.drake.net.exception](../index.md) / [NetCancellationException](index.md) / [<init>](./-init-.md) # <init> diff --git a/docs/api/net/com.drake.net.error/-net-cancellation-exception/index.md b/docs/api/net/com.drake.net.exception/-net-cancellation-exception/index.md similarity index 82% rename from docs/api/net/com.drake.net.error/-net-cancellation-exception/index.md rename to docs/api/net/com.drake.net.exception/-net-cancellation-exception/index.md index 261dac1c7..7a4c93b5e 100644 --- a/docs/api/net/com.drake.net.error/-net-cancellation-exception/index.md +++ b/docs/api/net/com.drake.net.exception/-net-cancellation-exception/index.md @@ -1,4 +1,4 @@ -[net](../../index.md) / [com.drake.net.error](../index.md) / [NetCancellationException](./index.md) +[net](../../index.md) / [com.drake.net.exception](../index.md) / [NetCancellationException](./index.md) # NetCancellationException diff --git a/docs/api/net/com.drake.net.exception/-net-exception/-init-.md b/docs/api/net/com.drake.net.exception/-net-exception/-init-.md new file mode 100644 index 000000000..6f35bf548 --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-net-exception/-init-.md @@ -0,0 +1,13 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [NetException](index.md) / [<init>](./-init-.md) + +# <init> + +`NetException(request: Request, message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`? = "", cause: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`? = null)` + +Net网络异常 + +### Parameters + +`request` - 请求信息 + +`message` - 异常信息 \ No newline at end of file diff --git a/docs/api/net/com.drake.net.exception/-net-exception/get-localized-message.md b/docs/api/net/com.drake.net.exception/-net-exception/get-localized-message.md new file mode 100644 index 000000000..35fac2ca6 --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-net-exception/get-localized-message.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [NetException](index.md) / [getLocalizedMessage](./get-localized-message.md) + +# getLocalizedMessage + +`open fun getLocalizedMessage(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.exception/-net-exception/index.md b/docs/api/net/com.drake.net.exception/-net-exception/index.md new file mode 100644 index 000000000..ceb71f3a0 --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-net-exception/index.md @@ -0,0 +1,44 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [NetException](./index.md) + +# NetException + +`open class NetException : `[`IOException`](https://docs.oracle.com/javase/6/docs/api/java/io/IOException.html) + +Net网络异常 + +### Parameters + +`request` - 请求信息 + +`message` - 异常信息 + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | Net网络异常`NetException(request: Request, message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`? = "", cause: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`? = null)` | + +### Properties + +| Name | Summary | +|---|---| +| [request](request.md) | 请求信息`val request: Request` | + +### Functions + +| Name | Summary | +|---|---| +| [getLocalizedMessage](get-localized-message.md) | `open fun getLocalizedMessage(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?` | + +### Inheritors + +| Name | Summary | +|---|---| +| [ConvertException](../-convert-exception/index.md) | 转换数据异常`class ConvertException : `[`NetException`](./index.md) | +| [DownloadFileException](../-download-file-exception/index.md) | 下载文件异常`class DownloadFileException : `[`NetException`](./index.md) | +| [NetSocketTimeoutException](../-net-socket-timeout-exception/index.md) | `class NetSocketTimeoutException : `[`NetException`](./index.md) | +| [NetworkingException](../-networking-exception/index.md) | `class NetworkingException : `[`NetException`](./index.md) | +| [NoCacheException](../-no-cache-exception/index.md) | `class NoCacheException : `[`NetException`](./index.md) | +| [RequestParamsException](../-request-params-exception/index.md) | 404`class RequestParamsException : `[`NetException`](./index.md) | +| [ResponseException](../-response-exception/index.md) | 对应网络请求后台定义的错误信息`class ResponseException : `[`NetException`](./index.md) | +| [ServerResponseException](../-server-response-exception/index.md) | 500`class ServerResponseException : `[`NetException`](./index.md) | diff --git a/docs/api/net/com.drake.net.exception/-net-exception/request.md b/docs/api/net/com.drake.net.exception/-net-exception/request.md new file mode 100644 index 000000000..7d747e2cb --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-net-exception/request.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [NetException](index.md) / [request](./request.md) + +# request + +`val request: Request` + +请求信息 + diff --git a/docs/api/net/com.drake.net.exception/-net-socket-timeout-exception/-init-.md b/docs/api/net/com.drake.net.exception/-net-socket-timeout-exception/-init-.md new file mode 100644 index 000000000..ca1b90f72 --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-net-socket-timeout-exception/-init-.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [NetSocketTimeoutException](index.md) / [<init>](./-init-.md) + +# <init> + +`NetSocketTimeoutException(request: Request, message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`? = "", cause: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`? = null)` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.exception/-net-socket-timeout-exception/index.md b/docs/api/net/com.drake.net.exception/-net-socket-timeout-exception/index.md new file mode 100644 index 000000000..db3cac241 --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-net-socket-timeout-exception/index.md @@ -0,0 +1,11 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [NetSocketTimeoutException](./index.md) + +# NetSocketTimeoutException + +`class NetSocketTimeoutException : `[`NetException`](../-net-exception/index.md) + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `NetSocketTimeoutException(request: Request, message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`? = "", cause: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`? = null)` | diff --git a/docs/api/net/com.drake.net.exception/-networking-exception/-init-.md b/docs/api/net/com.drake.net.exception/-networking-exception/-init-.md new file mode 100644 index 000000000..9bb900c8e --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-networking-exception/-init-.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [NetworkingException](index.md) / [<init>](./-init-.md) + +# <init> + +`NetworkingException(request: Request, message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`? = "", cause: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`? = null)` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.exception/-networking-exception/index.md b/docs/api/net/com.drake.net.exception/-networking-exception/index.md new file mode 100644 index 000000000..3b36704fa --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-networking-exception/index.md @@ -0,0 +1,11 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [NetworkingException](./index.md) + +# NetworkingException + +`class NetworkingException : `[`NetException`](../-net-exception/index.md) + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `NetworkingException(request: Request, message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`? = "", cause: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`? = null)` | diff --git a/docs/api/net/com.drake.net.exception/-no-cache-exception/-init-.md b/docs/api/net/com.drake.net.exception/-no-cache-exception/-init-.md new file mode 100644 index 000000000..1083178d5 --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-no-cache-exception/-init-.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [NoCacheException](index.md) / [<init>](./-init-.md) + +# <init> + +`NoCacheException(request: Request, message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`? = "", cause: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`? = null)` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.exception/-no-cache-exception/index.md b/docs/api/net/com.drake.net.exception/-no-cache-exception/index.md new file mode 100644 index 000000000..5d14716f4 --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-no-cache-exception/index.md @@ -0,0 +1,11 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [NoCacheException](./index.md) + +# NoCacheException + +`class NoCacheException : `[`NetException`](../-net-exception/index.md) + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `NoCacheException(request: Request, message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`? = "", cause: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`? = null)` | diff --git a/docs/api/net/com.drake.net.exception/-request-params-exception/-init-.md b/docs/api/net/com.drake.net.exception/-request-params-exception/-init-.md new file mode 100644 index 000000000..5b45fb432 --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-request-params-exception/-init-.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [RequestParamsException](index.md) / [<init>](./-init-.md) + +# <init> + +`RequestParamsException(response: Response)` + +404 + diff --git a/docs/api/net/com.drake.net.exception/-request-params-exception/index.md b/docs/api/net/com.drake.net.exception/-request-params-exception/index.md new file mode 100644 index 000000000..c98ded980 --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-request-params-exception/index.md @@ -0,0 +1,19 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [RequestParamsException](./index.md) + +# RequestParamsException + +`class RequestParamsException : `[`NetException`](../-net-exception/index.md) + +404 + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | 404`RequestParamsException(response: Response)` | + +### Properties + +| Name | Summary | +|---|---| +| [response](response.md) | `val response: Response` | diff --git a/docs/api/net/com.drake.net.exception/-request-params-exception/response.md b/docs/api/net/com.drake.net.exception/-request-params-exception/response.md new file mode 100644 index 000000000..e6c9fffc3 --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-request-params-exception/response.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [RequestParamsException](index.md) / [response](./response.md) + +# response + +`val response: Response` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.exception/-response-exception/-init-.md b/docs/api/net/com.drake.net.exception/-response-exception/-init-.md new file mode 100644 index 000000000..7e50f33a2 --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-response-exception/-init-.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [ResponseException](index.md) / [<init>](./-init-.md) + +# <init> + +`ResponseException(response: Response, message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "")` + +对应网络请求后台定义的错误信息 + diff --git a/docs/api/net/com.drake.net.exception/-response-exception/index.md b/docs/api/net/com.drake.net.exception/-response-exception/index.md new file mode 100644 index 000000000..0c34d4e6b --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-response-exception/index.md @@ -0,0 +1,13 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [ResponseException](./index.md) + +# ResponseException + +`class ResponseException : `[`NetException`](../-net-exception/index.md) + +对应网络请求后台定义的错误信息 + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | 对应网络请求后台定义的错误信息`ResponseException(response: Response, message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "")` | diff --git a/docs/api/net/com.drake.net.exception/-server-response-exception/-init-.md b/docs/api/net/com.drake.net.exception/-server-response-exception/-init-.md new file mode 100644 index 000000000..bec629346 --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-server-response-exception/-init-.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [ServerResponseException](index.md) / [<init>](./-init-.md) + +# <init> + +`ServerResponseException(response: Response)` + +500 + diff --git a/docs/api/net/com.drake.net.exception/-server-response-exception/index.md b/docs/api/net/com.drake.net.exception/-server-response-exception/index.md new file mode 100644 index 000000000..0d3ec0513 --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-server-response-exception/index.md @@ -0,0 +1,19 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [ServerResponseException](./index.md) + +# ServerResponseException + +`class ServerResponseException : `[`NetException`](../-net-exception/index.md) + +500 + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | 500`ServerResponseException(response: Response)` | + +### Properties + +| Name | Summary | +|---|---| +| [response](response.md) | `val response: Response` | diff --git a/docs/api/net/com.drake.net.exception/-server-response-exception/response.md b/docs/api/net/com.drake.net.exception/-server-response-exception/response.md new file mode 100644 index 000000000..202ab7fb8 --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-server-response-exception/response.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [ServerResponseException](index.md) / [response](./response.md) + +# response + +`val response: Response` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.exception/-u-r-l-parse-exception/-init-.md b/docs/api/net/com.drake.net.exception/-u-r-l-parse-exception/-init-.md new file mode 100644 index 000000000..9dbd5b50b --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-u-r-l-parse-exception/-init-.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [URLParseException](index.md) / [<init>](./-init-.md) + +# <init> + +`URLParseException(url: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, cause: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`? = null)` + +URL地址错误 + diff --git a/docs/api/net/com.drake.net.exception/-u-r-l-parse-exception/index.md b/docs/api/net/com.drake.net.exception/-u-r-l-parse-exception/index.md new file mode 100644 index 000000000..d86678358 --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-u-r-l-parse-exception/index.md @@ -0,0 +1,19 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [URLParseException](./index.md) + +# URLParseException + +`open class URLParseException : `[`Exception`](https://docs.oracle.com/javase/6/docs/api/java/lang/Exception.html) + +URL地址错误 + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | URL地址错误`URLParseException(url: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, cause: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`? = null)` | + +### Properties + +| Name | Summary | +|---|---| +| [url](url.md) | `val url: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | diff --git a/docs/api/net/com.drake.net.exception/-u-r-l-parse-exception/url.md b/docs/api/net/com.drake.net.exception/-u-r-l-parse-exception/url.md new file mode 100644 index 000000000..e72d4fe20 --- /dev/null +++ b/docs/api/net/com.drake.net.exception/-u-r-l-parse-exception/url.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.exception](../index.md) / [URLParseException](index.md) / [url](./url.md) + +# url + +`val url: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.exception/index.md b/docs/api/net/com.drake.net.exception/index.md new file mode 100644 index 000000000..2a1e27523 --- /dev/null +++ b/docs/api/net/com.drake.net.exception/index.md @@ -0,0 +1,25 @@ +[net](../index.md) / [com.drake.net.exception](./index.md) + +## Package com.drake.net.exception + +### Exceptions + +| Name | Summary | +|---|---| +| [ConvertException](-convert-exception/index.md) | 转换数据异常`class ConvertException : `[`NetException`](-net-exception/index.md) | +| [DownloadFileException](-download-file-exception/index.md) | 下载文件异常`class DownloadFileException : `[`NetException`](-net-exception/index.md) | +| [NetCancellationException](-net-cancellation-exception/index.md) | 取消网络任务的异常`class NetCancellationException : `[`CancellationException`](https://docs.oracle.com/javase/6/docs/api/java/util/concurrent/CancellationException.html) | +| [NetException](-net-exception/index.md) | Net网络异常`open class NetException : `[`IOException`](https://docs.oracle.com/javase/6/docs/api/java/io/IOException.html) | +| [NetSocketTimeoutException](-net-socket-timeout-exception/index.md) | `class NetSocketTimeoutException : `[`NetException`](-net-exception/index.md) | +| [NetworkingException](-networking-exception/index.md) | `class NetworkingException : `[`NetException`](-net-exception/index.md) | +| [NoCacheException](-no-cache-exception/index.md) | `class NoCacheException : `[`NetException`](-net-exception/index.md) | +| [RequestParamsException](-request-params-exception/index.md) | 404`class RequestParamsException : `[`NetException`](-net-exception/index.md) | +| [ResponseException](-response-exception/index.md) | 对应网络请求后台定义的错误信息`class ResponseException : `[`NetException`](-net-exception/index.md) | +| [ServerResponseException](-server-response-exception/index.md) | 500`class ServerResponseException : `[`NetException`](-net-exception/index.md) | +| [URLParseException](-u-r-l-parse-exception/index.md) | URL地址错误`open class URLParseException : `[`Exception`](https://docs.oracle.com/javase/6/docs/api/java/lang/Exception.html) | + +### Extensions for External Classes + +| Name | Summary | +|---|---| +| [kotlinx.coroutines.CoroutineScope](kotlinx.coroutines.-coroutine-scope/index.md) | | diff --git a/docs/api/net/com.drake.net.error/kotlinx.coroutines.-coroutine-scope/-net-cancellation-exception.md b/docs/api/net/com.drake.net.exception/kotlinx.coroutines.-coroutine-scope/-net-cancellation-exception.md similarity index 63% rename from docs/api/net/com.drake.net.error/kotlinx.coroutines.-coroutine-scope/-net-cancellation-exception.md rename to docs/api/net/com.drake.net.exception/kotlinx.coroutines.-coroutine-scope/-net-cancellation-exception.md index e0411b9a9..064fbb29b 100644 --- a/docs/api/net/com.drake.net.error/kotlinx.coroutines.-coroutine-scope/-net-cancellation-exception.md +++ b/docs/api/net/com.drake.net.exception/kotlinx.coroutines.-coroutine-scope/-net-cancellation-exception.md @@ -1,4 +1,4 @@ -[net](../../index.md) / [com.drake.net.error](../index.md) / [kotlinx.coroutines.CoroutineScope](index.md) / [NetCancellationException](./-net-cancellation-exception.md) +[net](../../index.md) / [com.drake.net.exception](../index.md) / [kotlinx.coroutines.CoroutineScope](index.md) / [NetCancellationException](./-net-cancellation-exception.md) # NetCancellationException diff --git a/docs/api/net/com.drake.net.error/kotlinx.coroutines.-coroutine-scope/index.md b/docs/api/net/com.drake.net.exception/kotlinx.coroutines.-coroutine-scope/index.md similarity index 79% rename from docs/api/net/com.drake.net.error/kotlinx.coroutines.-coroutine-scope/index.md rename to docs/api/net/com.drake.net.exception/kotlinx.coroutines.-coroutine-scope/index.md index f3fcbe312..6d8d1ff23 100644 --- a/docs/api/net/com.drake.net.error/kotlinx.coroutines.-coroutine-scope/index.md +++ b/docs/api/net/com.drake.net.exception/kotlinx.coroutines.-coroutine-scope/index.md @@ -1,4 +1,4 @@ -[net](../../index.md) / [com.drake.net.error](../index.md) / [kotlinx.coroutines.CoroutineScope](./index.md) +[net](../../index.md) / [com.drake.net.exception](../index.md) / [kotlinx.coroutines.CoroutineScope](./index.md) ### Extensions for kotlinx.coroutines.CoroutineScope diff --git a/docs/api/net/com.drake.net.interceptor/-log-record-interceptor/-init-.md b/docs/api/net/com.drake.net.interceptor/-log-record-interceptor/-init-.md new file mode 100644 index 000000000..1559effdd --- /dev/null +++ b/docs/api/net/com.drake.net.interceptor/-log-record-interceptor/-init-.md @@ -0,0 +1,9 @@ +[net](../../index.md) / [com.drake.net.interceptor](../index.md) / [LogRecordInterceptor](index.md) / [<init>](./-init-.md) + +# <init> + +`LogRecordInterceptor(enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` + +网络日志记录器 +可以参考此拦截器为项目中其他网络请求库配置. 本拦截器属于标准的OkHttp拦截器适用于所有OkHttp拦截器内核的网络请求库 + diff --git a/docs/api/net/com.drake.net.interceptor/-log-record-interceptor/index.md b/docs/api/net/com.drake.net.interceptor/-log-record-interceptor/index.md new file mode 100644 index 000000000..1da3014ef --- /dev/null +++ b/docs/api/net/com.drake.net.interceptor/-log-record-interceptor/index.md @@ -0,0 +1,20 @@ +[net](../../index.md) / [com.drake.net.interceptor](../index.md) / [LogRecordInterceptor](./index.md) + +# LogRecordInterceptor + +`class LogRecordInterceptor : Interceptor` + +网络日志记录器 +可以参考此拦截器为项目中其他网络请求库配置. 本拦截器属于标准的OkHttp拦截器适用于所有OkHttp拦截器内核的网络请求库 + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | 网络日志记录器 可以参考此拦截器为项目中其他网络请求库配置. 本拦截器属于标准的OkHttp拦截器适用于所有OkHttp拦截器内核的网络请求库`LogRecordInterceptor(enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` | + +### Functions + +| Name | Summary | +|---|---| +| [intercept](intercept.md) | `fun intercept(chain: Chain): Response` | diff --git a/docs/api/net/com.drake.net.interceptor/-log-record-interceptor/intercept.md b/docs/api/net/com.drake.net.interceptor/-log-record-interceptor/intercept.md new file mode 100644 index 000000000..61efeef84 --- /dev/null +++ b/docs/api/net/com.drake.net.interceptor/-log-record-interceptor/intercept.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.interceptor](../index.md) / [LogRecordInterceptor](index.md) / [intercept](./intercept.md) + +# intercept + +`fun intercept(chain: Chain): Response` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.interceptor/-request-interceptor/index.md b/docs/api/net/com.drake.net.interceptor/-request-interceptor/index.md new file mode 100644 index 000000000..eaa2c46f3 --- /dev/null +++ b/docs/api/net/com.drake.net.interceptor/-request-interceptor/index.md @@ -0,0 +1,11 @@ +[net](../../index.md) / [com.drake.net.interceptor](../index.md) / [RequestInterceptor](./index.md) + +# RequestInterceptor + +`interface RequestInterceptor` + +### Functions + +| Name | Summary | +|---|---| +| [interceptor](interceptor.md) | 当你使用Net发起请求的时候就会触发该拦截器 该拦截器属于轻量级不具备重发的功能, 一般用于请求参数的修改 请勿在这里进行请求重发可能会导致死循环`abstract fun interceptor(request: `[`BaseRequest`](../../com.drake.net.request/-base-request/index.md)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | diff --git a/docs/api/net/com.drake.net.interceptor/-request-interceptor/interceptor.md b/docs/api/net/com.drake.net.interceptor/-request-interceptor/interceptor.md new file mode 100644 index 000000000..811adb522 --- /dev/null +++ b/docs/api/net/com.drake.net.interceptor/-request-interceptor/interceptor.md @@ -0,0 +1,10 @@ +[net](../../index.md) / [com.drake.net.interceptor](../index.md) / [RequestInterceptor](index.md) / [interceptor](./interceptor.md) + +# interceptor + +`abstract fun interceptor(request: `[`BaseRequest`](../../com.drake.net.request/-base-request/index.md)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +当你使用Net发起请求的时候就会触发该拦截器 +该拦截器属于轻量级不具备重发的功能, 一般用于请求参数的修改 +请勿在这里进行请求重发可能会导致死循环 + diff --git a/docs/api/net/com.drake.net.interceptor/index.md b/docs/api/net/com.drake.net.interceptor/index.md new file mode 100644 index 000000000..cb633cce5 --- /dev/null +++ b/docs/api/net/com.drake.net.interceptor/index.md @@ -0,0 +1,10 @@ +[net](../index.md) / [com.drake.net.interceptor](./index.md) + +## Package com.drake.net.interceptor + +### Types + +| Name | Summary | +|---|---| +| [LogRecordInterceptor](-log-record-interceptor/index.md) | 网络日志记录器 可以参考此拦截器为项目中其他网络请求库配置. 本拦截器属于标准的OkHttp拦截器适用于所有OkHttp拦截器内核的网络请求库`class LogRecordInterceptor : Interceptor` | +| [RequestInterceptor](-request-interceptor/index.md) | `interface RequestInterceptor` | diff --git a/docs/api/net/com.drake.net.interfaces/-net-callback/-init-.md b/docs/api/net/com.drake.net.interfaces/-net-callback/-init-.md new file mode 100644 index 000000000..0ef4c9530 --- /dev/null +++ b/docs/api/net/com.drake.net.interfaces/-net-callback/-init-.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.interfaces](../index.md) / [NetCallback](index.md) / [<init>](./-init-.md) + +# <init> + +`NetCallback()` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.interfaces/-net-callback/index.md b/docs/api/net/com.drake.net.interfaces/-net-callback/index.md new file mode 100644 index 000000000..ea7de20af --- /dev/null +++ b/docs/api/net/com.drake.net.interfaces/-net-callback/index.md @@ -0,0 +1,21 @@ +[net](../../index.md) / [com.drake.net.interfaces](../index.md) / [NetCallback](./index.md) + +# NetCallback + +`abstract class NetCallback : Callback` + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `NetCallback()` | + +### Functions + +| Name | Summary | +|---|---| +| [onComplete](on-complete.md) | 请求完成`fun onComplete(call: Call, e: `[`IOException`](https://docs.oracle.com/javase/6/docs/api/java/io/IOException.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [onError](on-error.md) | 请求错误`fun onError(call: Call, e: `[`IOException`](https://docs.oracle.com/javase/6/docs/api/java/io/IOException.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [onFailure](on-failure.md) | `open fun onFailure(call: Call, e: `[`IOException`](https://docs.oracle.com/javase/6/docs/api/java/io/IOException.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [onResponse](on-response.md) | `open fun onResponse(call: Call, response: Response): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [onSuccess](on-success.md) | 请求成功`abstract fun onSuccess(call: Call, data: T): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | diff --git a/docs/api/net/com.drake.net.interfaces/-net-callback/on-complete.md b/docs/api/net/com.drake.net.interfaces/-net-callback/on-complete.md new file mode 100644 index 000000000..70bf301dc --- /dev/null +++ b/docs/api/net/com.drake.net.interfaces/-net-callback/on-complete.md @@ -0,0 +1,11 @@ +[net](../../index.md) / [com.drake.net.interfaces](../index.md) / [NetCallback](index.md) / [onComplete](./on-complete.md) + +# onComplete + +`fun onComplete(call: Call, e: `[`IOException`](https://docs.oracle.com/javase/6/docs/api/java/io/IOException.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +请求完成 + +### Parameters + +`e` - 正常结束则为NULL, 发生异常结束则为异常对象 \ No newline at end of file diff --git a/docs/api/net/com.drake.net.interfaces/-net-callback/on-error.md b/docs/api/net/com.drake.net.interfaces/-net-callback/on-error.md new file mode 100644 index 000000000..d3c98e76a --- /dev/null +++ b/docs/api/net/com.drake.net.interfaces/-net-callback/on-error.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.interfaces](../index.md) / [NetCallback](index.md) / [onError](./on-error.md) + +# onError + +`fun onError(call: Call, e: `[`IOException`](https://docs.oracle.com/javase/6/docs/api/java/io/IOException.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +请求错误 + diff --git a/docs/api/net/com.drake.net.interfaces/-net-callback/on-failure.md b/docs/api/net/com.drake.net.interfaces/-net-callback/on-failure.md new file mode 100644 index 000000000..5bf5c830b --- /dev/null +++ b/docs/api/net/com.drake.net.interfaces/-net-callback/on-failure.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.interfaces](../index.md) / [NetCallback](index.md) / [onFailure](./on-failure.md) + +# onFailure + +`open fun onFailure(call: Call, e: `[`IOException`](https://docs.oracle.com/javase/6/docs/api/java/io/IOException.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.interfaces/-net-callback/on-response.md b/docs/api/net/com.drake.net.interfaces/-net-callback/on-response.md new file mode 100644 index 000000000..678d2fe46 --- /dev/null +++ b/docs/api/net/com.drake.net.interfaces/-net-callback/on-response.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.interfaces](../index.md) / [NetCallback](index.md) / [onResponse](./on-response.md) + +# onResponse + +`open fun onResponse(call: Call, response: Response): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.interfaces/-net-callback/on-success.md b/docs/api/net/com.drake.net.interfaces/-net-callback/on-success.md new file mode 100644 index 000000000..35c540a7d --- /dev/null +++ b/docs/api/net/com.drake.net.interfaces/-net-callback/on-success.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.interfaces](../index.md) / [NetCallback](index.md) / [onSuccess](./on-success.md) + +# onSuccess + +`abstract fun onSuccess(call: Call, data: T): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +请求成功 + diff --git a/docs/api/net/com.drake.net.interfaces/index.md b/docs/api/net/com.drake.net.interfaces/index.md new file mode 100644 index 000000000..190787a62 --- /dev/null +++ b/docs/api/net/com.drake.net.interfaces/index.md @@ -0,0 +1,9 @@ +[net](../index.md) / [com.drake.net.interfaces](./index.md) + +## Package com.drake.net.interfaces + +### Types + +| Name | Summary | +|---|---| +| [NetCallback](-net-callback/index.md) | `abstract class NetCallback : Callback` | diff --git a/docs/api/net/com.drake.net.log/-log-recorder/enabled.md b/docs/api/net/com.drake.net.log/-log-recorder/enabled.md new file mode 100644 index 000000000..df44586e6 --- /dev/null +++ b/docs/api/net/com.drake.net.log/-log-recorder/enabled.md @@ -0,0 +1,11 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [LogRecorder](index.md) / [enabled](./enabled.md) + +# enabled + +`@JvmStatic var enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) + +是否启用日志记录器 + +### Property + +`enabled` - 是否启用日志记录器 \ No newline at end of file diff --git a/docs/api/net/com.drake.net.log/-log-recorder/generate-id.md b/docs/api/net/com.drake.net.log/-log-recorder/generate-id.md new file mode 100644 index 000000000..88460a9ed --- /dev/null +++ b/docs/api/net/com.drake.net.log/-log-recorder/generate-id.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [LogRecorder](index.md) / [generateId](./generate-id.md) + +# generateId + +`@JvmStatic @Synchronized fun generateId(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) + +产生一个唯一的基于时间戳Id + diff --git a/docs/api/net/com.drake.net.log/-log-recorder/index.md b/docs/api/net/com.drake.net.log/-log-recorder/index.md new file mode 100644 index 000000000..44d3191e7 --- /dev/null +++ b/docs/api/net/com.drake.net.log/-log-recorder/index.md @@ -0,0 +1,22 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [LogRecorder](./index.md) + +# LogRecorder + +`object LogRecorder` + +日志记录器 + +### Properties + +| Name | Summary | +|---|---| +| [enabled](enabled.md) | 是否启用日志记录器`var enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | + +### Functions + +| Name | Summary | +|---|---| +| [generateId](generate-id.md) | 产生一个唯一的基于时间戳Id`fun generateId(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | +| [recordException](record-exception.md) | 发送请求异常到记录器`fun recordException(id: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, requestMillis: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`, code: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`?, response: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?, errorMessage: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [recordRequest](record-request.md) | 发送请求信息到记录器中`fun recordRequest(id: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, url: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, method: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, headers: `[`Map`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `[`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>>, body: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [recordResponse](record-response.md) | 发送响应信息到记录器中`fun recordResponse(id: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, requestMillis: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`, code: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, headers: `[`Map`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `[`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>>, body: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | diff --git a/docs/api/net/com.drake.net.log/-log-recorder/record-exception.md b/docs/api/net/com.drake.net.log/-log-recorder/record-exception.md new file mode 100644 index 000000000..0b74f6fd6 --- /dev/null +++ b/docs/api/net/com.drake.net.log/-log-recorder/record-exception.md @@ -0,0 +1,15 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [LogRecorder](index.md) / [recordException](./record-exception.md) + +# recordException + +`@JvmStatic fun recordException(id: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, requestMillis: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`, code: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`?, response: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?, errorMessage: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +发送请求异常到记录器 + +### Parameters + +`id` - 请求的唯一标识符 + +`requestMillis` - 请求时间毫秒值 + +`errorMessage` - 错误信息, 如果存在\n换行符, 仅接受最后一行 \ No newline at end of file diff --git a/docs/api/net/com.drake.net.log/-log-recorder/record-request.md b/docs/api/net/com.drake.net.log/-log-recorder/record-request.md new file mode 100644 index 000000000..85ecf7ead --- /dev/null +++ b/docs/api/net/com.drake.net.log/-log-recorder/record-request.md @@ -0,0 +1,19 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [LogRecorder](index.md) / [recordRequest](./record-request.md) + +# recordRequest + +`@JvmStatic fun recordRequest(id: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, url: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, method: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, headers: `[`Map`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `[`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>>, body: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +发送请求信息到记录器中 + +### Parameters + +`id` - 请求的唯一标识符 + +`url` - 请求URL地址 + +`method` - 请求方法 + +`headers` - 请求头 + +`body` - 请求体 \ No newline at end of file diff --git a/docs/api/net/com.drake.net.log/-log-recorder/record-response.md b/docs/api/net/com.drake.net.log/-log-recorder/record-response.md new file mode 100644 index 000000000..869ac3896 --- /dev/null +++ b/docs/api/net/com.drake.net.log/-log-recorder/record-response.md @@ -0,0 +1,17 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [LogRecorder](index.md) / [recordResponse](./record-response.md) + +# recordResponse + +`@JvmStatic fun recordResponse(id: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, requestMillis: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`, code: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, headers: `[`Map`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `[`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>>, body: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +发送响应信息到记录器中 + +### Parameters + +`id` - 请求的唯一标识符 + +`code` - 响应码 + +`headers` - 响应头 + +`body` - 响应体 \ No newline at end of file diff --git a/docs/api/net/com.drake.net.log/-message-type/-r-e-q-u-e-s-t_-b-o-d-y.md b/docs/api/net/com.drake.net.log/-message-type/-r-e-q-u-e-s-t_-b-o-d-y.md new file mode 100644 index 000000000..e27dc0d2a --- /dev/null +++ b/docs/api/net/com.drake.net.log/-message-type/-r-e-q-u-e-s-t_-b-o-d-y.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [MessageType](index.md) / [REQUEST_BODY](./-r-e-q-u-e-s-t_-b-o-d-y.md) + +# REQUEST_BODY + +`REQUEST_BODY` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.log/-message-type/-r-e-q-u-e-s-t_-e-n-d.md b/docs/api/net/com.drake.net.log/-message-type/-r-e-q-u-e-s-t_-e-n-d.md new file mode 100644 index 000000000..21f39fcf8 --- /dev/null +++ b/docs/api/net/com.drake.net.log/-message-type/-r-e-q-u-e-s-t_-e-n-d.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [MessageType](index.md) / [REQUEST_END](./-r-e-q-u-e-s-t_-e-n-d.md) + +# REQUEST_END + +`REQUEST_END` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.log/-message-type/-r-e-q-u-e-s-t_-h-e-a-d-e-r.md b/docs/api/net/com.drake.net.log/-message-type/-r-e-q-u-e-s-t_-h-e-a-d-e-r.md new file mode 100644 index 000000000..1feb033db --- /dev/null +++ b/docs/api/net/com.drake.net.log/-message-type/-r-e-q-u-e-s-t_-h-e-a-d-e-r.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [MessageType](index.md) / [REQUEST_HEADER](./-r-e-q-u-e-s-t_-h-e-a-d-e-r.md) + +# REQUEST_HEADER + +`REQUEST_HEADER` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.log/-message-type/-r-e-q-u-e-s-t_-m-e-t-h-o-d.md b/docs/api/net/com.drake.net.log/-message-type/-r-e-q-u-e-s-t_-m-e-t-h-o-d.md new file mode 100644 index 000000000..90d633ab4 --- /dev/null +++ b/docs/api/net/com.drake.net.log/-message-type/-r-e-q-u-e-s-t_-m-e-t-h-o-d.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [MessageType](index.md) / [REQUEST_METHOD](./-r-e-q-u-e-s-t_-m-e-t-h-o-d.md) + +# REQUEST_METHOD + +`REQUEST_METHOD` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.log/-message-type/-r-e-q-u-e-s-t_-t-i-m-e.md b/docs/api/net/com.drake.net.log/-message-type/-r-e-q-u-e-s-t_-t-i-m-e.md new file mode 100644 index 000000000..586be6139 --- /dev/null +++ b/docs/api/net/com.drake.net.log/-message-type/-r-e-q-u-e-s-t_-t-i-m-e.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [MessageType](index.md) / [REQUEST_TIME](./-r-e-q-u-e-s-t_-t-i-m-e.md) + +# REQUEST_TIME + +`REQUEST_TIME` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.log/-message-type/-r-e-q-u-e-s-t_-u-r-l.md b/docs/api/net/com.drake.net.log/-message-type/-r-e-q-u-e-s-t_-u-r-l.md new file mode 100644 index 000000000..3097411b0 --- /dev/null +++ b/docs/api/net/com.drake.net.log/-message-type/-r-e-q-u-e-s-t_-u-r-l.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [MessageType](index.md) / [REQUEST_URL](./-r-e-q-u-e-s-t_-u-r-l.md) + +# REQUEST_URL + +`REQUEST_URL` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.log/-message-type/-r-e-s-p-o-n-s-e_-b-o-d-y.md b/docs/api/net/com.drake.net.log/-message-type/-r-e-s-p-o-n-s-e_-b-o-d-y.md new file mode 100644 index 000000000..6c29b25d4 --- /dev/null +++ b/docs/api/net/com.drake.net.log/-message-type/-r-e-s-p-o-n-s-e_-b-o-d-y.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [MessageType](index.md) / [RESPONSE_BODY](./-r-e-s-p-o-n-s-e_-b-o-d-y.md) + +# RESPONSE_BODY + +`RESPONSE_BODY` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.log/-message-type/-r-e-s-p-o-n-s-e_-e-n-d.md b/docs/api/net/com.drake.net.log/-message-type/-r-e-s-p-o-n-s-e_-e-n-d.md new file mode 100644 index 000000000..b99d98ffd --- /dev/null +++ b/docs/api/net/com.drake.net.log/-message-type/-r-e-s-p-o-n-s-e_-e-n-d.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [MessageType](index.md) / [RESPONSE_END](./-r-e-s-p-o-n-s-e_-e-n-d.md) + +# RESPONSE_END + +`RESPONSE_END` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.log/-message-type/-r-e-s-p-o-n-s-e_-e-r-r-o-r.md b/docs/api/net/com.drake.net.log/-message-type/-r-e-s-p-o-n-s-e_-e-r-r-o-r.md new file mode 100644 index 000000000..0787562da --- /dev/null +++ b/docs/api/net/com.drake.net.log/-message-type/-r-e-s-p-o-n-s-e_-e-r-r-o-r.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [MessageType](index.md) / [RESPONSE_ERROR](./-r-e-s-p-o-n-s-e_-e-r-r-o-r.md) + +# RESPONSE_ERROR + +`RESPONSE_ERROR` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.log/-message-type/-r-e-s-p-o-n-s-e_-h-e-a-d-e-r.md b/docs/api/net/com.drake.net.log/-message-type/-r-e-s-p-o-n-s-e_-h-e-a-d-e-r.md new file mode 100644 index 000000000..1802111a1 --- /dev/null +++ b/docs/api/net/com.drake.net.log/-message-type/-r-e-s-p-o-n-s-e_-h-e-a-d-e-r.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [MessageType](index.md) / [RESPONSE_HEADER](./-r-e-s-p-o-n-s-e_-h-e-a-d-e-r.md) + +# RESPONSE_HEADER + +`RESPONSE_HEADER` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.log/-message-type/-r-e-s-p-o-n-s-e_-s-t-a-t-u-s.md b/docs/api/net/com.drake.net.log/-message-type/-r-e-s-p-o-n-s-e_-s-t-a-t-u-s.md new file mode 100644 index 000000000..e93a1e23b --- /dev/null +++ b/docs/api/net/com.drake.net.log/-message-type/-r-e-s-p-o-n-s-e_-s-t-a-t-u-s.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [MessageType](index.md) / [RESPONSE_STATUS](./-r-e-s-p-o-n-s-e_-s-t-a-t-u-s.md) + +# RESPONSE_STATUS + +`RESPONSE_STATUS` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.log/-message-type/-r-e-s-p-o-n-s-e_-t-i-m-e.md b/docs/api/net/com.drake.net.log/-message-type/-r-e-s-p-o-n-s-e_-t-i-m-e.md new file mode 100644 index 000000000..fdb50be27 --- /dev/null +++ b/docs/api/net/com.drake.net.log/-message-type/-r-e-s-p-o-n-s-e_-t-i-m-e.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [MessageType](index.md) / [RESPONSE_TIME](./-r-e-s-p-o-n-s-e_-t-i-m-e.md) + +# RESPONSE_TIME + +`RESPONSE_TIME` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.log/-message-type/-u-n-k-n-o-w-n.md b/docs/api/net/com.drake.net.log/-message-type/-u-n-k-n-o-w-n.md new file mode 100644 index 000000000..d40087d52 --- /dev/null +++ b/docs/api/net/com.drake.net.log/-message-type/-u-n-k-n-o-w-n.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [MessageType](index.md) / [UNKNOWN](./-u-n-k-n-o-w-n.md) + +# UNKNOWN + +`UNKNOWN` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.log/-message-type/index.md b/docs/api/net/com.drake.net.log/-message-type/index.md new file mode 100644 index 000000000..d70423883 --- /dev/null +++ b/docs/api/net/com.drake.net.log/-message-type/index.md @@ -0,0 +1,29 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [MessageType](./index.md) + +# MessageType + +`enum class MessageType` + +### Enum Values + +| Name | Summary | +|---|---| +| [REQUEST_URL](-r-e-q-u-e-s-t_-u-r-l.md) | | +| [REQUEST_TIME](-r-e-q-u-e-s-t_-t-i-m-e.md) | | +| [REQUEST_METHOD](-r-e-q-u-e-s-t_-m-e-t-h-o-d.md) | | +| [REQUEST_HEADER](-r-e-q-u-e-s-t_-h-e-a-d-e-r.md) | | +| [REQUEST_BODY](-r-e-q-u-e-s-t_-b-o-d-y.md) | | +| [REQUEST_END](-r-e-q-u-e-s-t_-e-n-d.md) | | +| [RESPONSE_TIME](-r-e-s-p-o-n-s-e_-t-i-m-e.md) | | +| [RESPONSE_STATUS](-r-e-s-p-o-n-s-e_-s-t-a-t-u-s.md) | | +| [RESPONSE_HEADER](-r-e-s-p-o-n-s-e_-h-e-a-d-e-r.md) | | +| [RESPONSE_BODY](-r-e-s-p-o-n-s-e_-b-o-d-y.md) | | +| [RESPONSE_END](-r-e-s-p-o-n-s-e_-e-n-d.md) | | +| [RESPONSE_ERROR](-r-e-s-p-o-n-s-e_-e-r-r-o-r.md) | | +| [UNKNOWN](-u-n-k-n-o-w-n.md) | | + +### Properties + +| Name | Summary | +|---|---| +| [type](type.md) | `var type: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | diff --git a/docs/api/net/com.drake.net.log/-message-type/type.md b/docs/api/net/com.drake.net.log/-message-type/type.md new file mode 100644 index 000000000..04ff3f04c --- /dev/null +++ b/docs/api/net/com.drake.net.log/-message-type/type.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.log](../index.md) / [MessageType](index.md) / [type](./type.md) + +# type + +`var type: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.log/index.md b/docs/api/net/com.drake.net.log/index.md new file mode 100644 index 000000000..993ffbb1f --- /dev/null +++ b/docs/api/net/com.drake.net.log/index.md @@ -0,0 +1,10 @@ +[net](../index.md) / [com.drake.net.log](./index.md) + +## Package com.drake.net.log + +### Types + +| Name | Summary | +|---|---| +| [LogRecorder](-log-recorder/index.md) | 日志记录器`object LogRecorder` | +| [MessageType](-message-type/index.md) | `enum class MessageType` | diff --git a/docs/api/net/com.drake.net.request/-base-request/-init-.md b/docs/api/net/com.drake.net.request/-base-request/-init-.md new file mode 100644 index 000000000..dae0a88bb --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/-init-.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [<init>](./-init-.md) + +# <init> + +`BaseRequest()` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-base-request/add-download-listener.md b/docs/api/net/com.drake.net.request/-base-request/add-download-listener.md new file mode 100644 index 000000000..60fd26b4d --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/add-download-listener.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [addDownloadListener](./add-download-listener.md) + +# addDownloadListener + +`fun addDownloadListener(progressListener: `[`ProgressListener`](../-progress-listener/index.md)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +下载监听器 + diff --git a/docs/api/net/com.drake.net.request/-base-request/add-header.md b/docs/api/net/com.drake.net.request/-base-request/add-header.md new file mode 100644 index 000000000..abef254bf --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/add-header.md @@ -0,0 +1,9 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [addHeader](./add-header.md) + +# addHeader + +`fun addHeader(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +添加请求头 +如果已存在相同`name`的请求头会添加而不会覆盖, 因为请求头本身存在多个值 + diff --git a/docs/api/net/com.drake.net.request/-base-request/build-request.md b/docs/api/net/com.drake.net.request/-base-request/build-request.md new file mode 100644 index 000000000..e58f11251 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/build-request.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [buildRequest](./build-request.md) + +# buildRequest + +`open fun buildRequest(): ` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-base-request/converter.md b/docs/api/net/com.drake.net.request/-base-request/converter.md new file mode 100644 index 000000000..14601f3c1 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/converter.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [converter](./converter.md) + +# converter + +`open var converter: `[`NetConverter`](../../com.drake.net.convert/-net-converter/index.md) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-base-request/download-listeners.md b/docs/api/net/com.drake.net.request/-base-request/download-listeners.md new file mode 100644 index 000000000..6424666cb --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/download-listeners.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [downloadListeners](./download-listeners.md) + +# downloadListeners + +`protected val downloadListeners: DownloadListeners` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-base-request/enqueue.md b/docs/api/net/com.drake.net.request/-base-request/enqueue.md new file mode 100644 index 000000000..839f46d87 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/enqueue.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [enqueue](./enqueue.md) + +# enqueue + +`fun enqueue(block: Callback): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-base-request/http-url.md b/docs/api/net/com.drake.net.request/-base-request/http-url.md new file mode 100644 index 000000000..7ae8eb3e2 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/http-url.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [httpUrl](./http-url.md) + +# httpUrl + +`open var httpUrl: Builder` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-base-request/index.md b/docs/api/net/com.drake.net.request/-base-request/index.md new file mode 100644 index 000000000..8940fc348 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/index.md @@ -0,0 +1,58 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](./index.md) + +# BaseRequest + +`abstract class BaseRequest` + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `BaseRequest()` | + +### Properties + +| Name | Summary | +|---|---| +| [converter](converter.md) | `open var converter: `[`NetConverter`](../../com.drake.net.convert/-net-converter/index.md) | +| [downloadListeners](download-listeners.md) | `val downloadListeners: DownloadListeners` | +| [httpUrl](http-url.md) | `open var httpUrl: Builder` | +| [method](method.md) | `open var method: `[`Method`](../-method/index.md) | +| [okHttpClient](ok-http-client.md) | `var okHttpClient: OkHttpClient` | +| [okHttpRequest](ok-http-request.md) | `open var okHttpRequest: Builder` | + +### Functions + +| Name | Summary | +|---|---| +| [addDownloadListener](add-download-listener.md) | 下载监听器`fun addDownloadListener(progressListener: `[`ProgressListener`](../-progress-listener/index.md)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [addHeader](add-header.md) | 添加请求头 如果已存在相同`name`的请求头会添加而不会覆盖, 因为请求头本身存在多个值`fun addHeader(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [buildRequest](build-request.md) | `open fun buildRequest(): ` | +| [enqueue](enqueue.md) | `fun enqueue(block: Callback): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [param](param.md) | `abstract fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?, encoded: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`abstract fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`Number`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-number/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`abstract fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [removeHeader](remove-header.md) | 删除请求头`fun removeHeader(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [setCache](set-cache.md) | 设置缓存策略`fun setCache(cache: `[`Cache`](../../com.drake.net.cache/-cache/index.md)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [setCacheControl](set-cache-control.md) | 设置请求头的缓存控制`fun setCacheControl(cacheControl: CacheControl): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [setCacheKey](set-cache-key.md) | `fun setCacheKey(): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [setClient](set-client.md) | 修改当前Request的OkHttpClient配置, 不会影响全局默认的OkHttpClient`fun setClient(block: Builder.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [setDownloadDir](set-download-dir.md) | 下载文件的保存目录`fun setDownloadDir(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`fun setDownloadDir(name: `[`File`](https://docs.oracle.com/javase/6/docs/api/java/io/File.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [setDownloadFileName](set-download-file-name.md) | 下载文件名`fun setDownloadFileName(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [setDownloadFileNameConflict](set-download-file-name-conflict.md) | 假设下载文件路径已存在同名文件是否重命名, 例如`file_name(1).apk``fun setDownloadFileNameConflict(enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = true): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [setDownloadFileNameDecode](set-download-file-name-decode.md) | 文件名称是否使用URL解码 例如下载的文件名如果是中文, 服务器传输给你的会是被URL编码的字符串. 你使用URL解码后才是可读的中文名称`fun setDownloadFileNameDecode(enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = true): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [setDownloadMd5Verify](set-download-md5-verify.md) | 如果服务器返回 "Content-MD5"响应头和制定路径已经存在的文件MD5相同是否直接返回File`fun setDownloadMd5Verify(enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = true): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [setDownloadTempFile](set-download-temp-file.md) | 下载是否使用临时文件 避免下载失败后覆盖同名文件或者无法判别是否已下载完整, 仅在下载完整以后才会显示为原有文件名 临时文件命名规则: 文件名 + .net-download 下载文件名: install.apk, 临时文件名: install.apk.net-download`fun setDownloadTempFile(enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = true): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [setGroup](set-group.md) | 分组`fun setGroup(group: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [setHeader](set-header.md) | 设置请求头, 会覆盖请求头而不像[addHeader](add-header.md)是添加`fun setHeader(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [setHeaders](set-headers.md) | 批量设置请求头`fun setHeaders(headers: Headers): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [setId](set-id.md) | 唯一的Id`fun setId(id: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [setPath](set-path.md) | `fun setPath(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, encoded: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [setQuery](set-query.md) | `fun setQuery(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?, encoded: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [setTag](set-tag.md) | 将一个任意对象添加到Request对象中, 一般用于在拦截器或者转换器中被获取到标签, 针对某个请求的特殊业务逻辑 使用`Request.tag()`获取标签`fun setTag(tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
添加标签 使用`Request.tag(name)`得到指定标签`fun setTag(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [setUrl](set-url.md) | 设置一个Url字符串, 其参数不会和你初始化时设置的主域名[NetConfig.host](../../com.drake.net/-net-config/host.md)进行拼接 一般情况下我建议使用更为聪明的[setPath](set-path.md)`open fun setUrl(url: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`open fun setUrl(url: HttpUrl): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`open fun setUrl(url: `[`URL`](https://docs.oracle.com/javase/6/docs/api/java/net/URL.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | + +### Inheritors + +| Name | Summary | +|---|---| +| [BodyRequest](../-body-request/index.md) | `class BodyRequest : `[`BaseRequest`](./index.md) | +| [UrlRequest](../-url-request/index.md) | `class UrlRequest : `[`BaseRequest`](./index.md) | diff --git a/docs/api/net/com.drake.net.request/-base-request/method.md b/docs/api/net/com.drake.net.request/-base-request/method.md new file mode 100644 index 000000000..2ae18263b --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/method.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [method](./method.md) + +# method + +`open var method: `[`Method`](../-method/index.md) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-base-request/ok-http-client.md b/docs/api/net/com.drake.net.request/-base-request/ok-http-client.md new file mode 100644 index 000000000..df0f61658 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/ok-http-client.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [okHttpClient](./ok-http-client.md) + +# okHttpClient + +`var okHttpClient: OkHttpClient` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-base-request/ok-http-request.md b/docs/api/net/com.drake.net.request/-base-request/ok-http-request.md new file mode 100644 index 000000000..0427a9082 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/ok-http-request.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [okHttpRequest](./ok-http-request.md) + +# okHttpRequest + +`open var okHttpRequest: Builder` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-base-request/param.md b/docs/api/net/com.drake.net.request/-base-request/param.md new file mode 100644 index 000000000..2e6742b17 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/param.md @@ -0,0 +1,7 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [param](./param.md) + +# param + +`abstract fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?, encoded: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) +`abstract fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`Number`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-number/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) +`abstract fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-base-request/remove-header.md b/docs/api/net/com.drake.net.request/-base-request/remove-header.md new file mode 100644 index 000000000..e23b9208e --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/remove-header.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [removeHeader](./remove-header.md) + +# removeHeader + +`fun removeHeader(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +删除请求头 + diff --git a/docs/api/net/com.drake.net.request/-base-request/set-cache-control.md b/docs/api/net/com.drake.net.request/-base-request/set-cache-control.md new file mode 100644 index 000000000..d8bcbb623 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/set-cache-control.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [setCacheControl](./set-cache-control.md) + +# setCacheControl + +`fun setCacheControl(cacheControl: CacheControl): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +设置请求头的缓存控制 + diff --git a/docs/api/net/com.drake.net.request/-base-request/set-cache-key.md b/docs/api/net/com.drake.net.request/-base-request/set-cache-key.md new file mode 100644 index 000000000..275cc3d61 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/set-cache-key.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [setCacheKey](./set-cache-key.md) + +# setCacheKey + +`fun setCacheKey(): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-base-request/set-cache.md b/docs/api/net/com.drake.net.request/-base-request/set-cache.md new file mode 100644 index 000000000..72bd7011f --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/set-cache.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [setCache](./set-cache.md) + +# setCache + +`fun setCache(cache: `[`Cache`](../../com.drake.net.cache/-cache/index.md)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +设置缓存策略 + diff --git a/docs/api/net/com.drake.net.request/-base-request/set-client.md b/docs/api/net/com.drake.net.request/-base-request/set-client.md new file mode 100644 index 000000000..ed5024c84 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/set-client.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [setClient](./set-client.md) + +# setClient + +`fun setClient(block: Builder.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +修改当前Request的OkHttpClient配置, 不会影响全局默认的OkHttpClient + diff --git a/docs/api/net/com.drake.net.request/-base-request/set-download-dir.md b/docs/api/net/com.drake.net.request/-base-request/set-download-dir.md new file mode 100644 index 000000000..4a4774607 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/set-download-dir.md @@ -0,0 +1,9 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [setDownloadDir](./set-download-dir.md) + +# setDownloadDir + +`fun setDownloadDir(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +下载文件的保存目录 + +`fun setDownloadDir(name: `[`File`](https://docs.oracle.com/javase/6/docs/api/java/io/File.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-base-request/set-download-file-name-conflict.md b/docs/api/net/com.drake.net.request/-base-request/set-download-file-name-conflict.md new file mode 100644 index 000000000..8618dcfdf --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/set-download-file-name-conflict.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [setDownloadFileNameConflict](./set-download-file-name-conflict.md) + +# setDownloadFileNameConflict + +`fun setDownloadFileNameConflict(enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = true): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +假设下载文件路径已存在同名文件是否重命名, 例如`file_name(1).apk` + diff --git a/docs/api/net/com.drake.net.request/-base-request/set-download-file-name-decode.md b/docs/api/net/com.drake.net.request/-base-request/set-download-file-name-decode.md new file mode 100644 index 000000000..9bb663d55 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/set-download-file-name-decode.md @@ -0,0 +1,9 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [setDownloadFileNameDecode](./set-download-file-name-decode.md) + +# setDownloadFileNameDecode + +`fun setDownloadFileNameDecode(enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = true): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +文件名称是否使用URL解码 +例如下载的文件名如果是中文, 服务器传输给你的会是被URL编码的字符串. 你使用URL解码后才是可读的中文名称 + diff --git a/docs/api/net/com.drake.net.request/-base-request/set-download-file-name.md b/docs/api/net/com.drake.net.request/-base-request/set-download-file-name.md new file mode 100644 index 000000000..2167955ca --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/set-download-file-name.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [setDownloadFileName](./set-download-file-name.md) + +# setDownloadFileName + +`fun setDownloadFileName(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +下载文件名 + diff --git a/docs/api/net/com.drake.net.request/-base-request/set-download-md5-verify.md b/docs/api/net/com.drake.net.request/-base-request/set-download-md5-verify.md new file mode 100644 index 000000000..2e38b3156 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/set-download-md5-verify.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [setDownloadMd5Verify](./set-download-md5-verify.md) + +# setDownloadMd5Verify + +`fun setDownloadMd5Verify(enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = true): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +如果服务器返回 "Content-MD5"响应头和制定路径已经存在的文件MD5相同是否直接返回File + diff --git a/docs/api/net/com.drake.net.request/-base-request/set-download-temp-file.md b/docs/api/net/com.drake.net.request/-base-request/set-download-temp-file.md new file mode 100644 index 000000000..fd2061666 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/set-download-temp-file.md @@ -0,0 +1,11 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [setDownloadTempFile](./set-download-temp-file.md) + +# setDownloadTempFile + +`fun setDownloadTempFile(enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = true): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +下载是否使用临时文件 +避免下载失败后覆盖同名文件或者无法判别是否已下载完整, 仅在下载完整以后才会显示为原有文件名 +临时文件命名规则: 文件名 + .net-download + 下载文件名: install.apk, 临时文件名: install.apk.net-download + diff --git a/docs/api/net/com.drake.net.request/-base-request/set-group.md b/docs/api/net/com.drake.net.request/-base-request/set-group.md new file mode 100644 index 000000000..ebfbdd03b --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/set-group.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [setGroup](./set-group.md) + +# setGroup + +`fun setGroup(group: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +分组 + diff --git a/docs/api/net/com.drake.net.request/-base-request/set-header.md b/docs/api/net/com.drake.net.request/-base-request/set-header.md new file mode 100644 index 000000000..dc56ed2f7 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/set-header.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [setHeader](./set-header.md) + +# setHeader + +`fun setHeader(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +设置请求头, 会覆盖请求头而不像[addHeader](add-header.md)是添加 + diff --git a/docs/api/net/com.drake.net.request/-base-request/set-headers.md b/docs/api/net/com.drake.net.request/-base-request/set-headers.md new file mode 100644 index 000000000..61f0abb9a --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/set-headers.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [setHeaders](./set-headers.md) + +# setHeaders + +`fun setHeaders(headers: Headers): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +批量设置请求头 + diff --git a/docs/api/net/com.drake.net.request/-base-request/set-id.md b/docs/api/net/com.drake.net.request/-base-request/set-id.md new file mode 100644 index 000000000..ed5b62906 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/set-id.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [setId](./set-id.md) + +# setId + +`fun setId(id: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +唯一的Id + diff --git a/docs/api/net/com.drake.net.request/-base-request/set-path.md b/docs/api/net/com.drake.net.request/-base-request/set-path.md new file mode 100644 index 000000000..5a624e2a0 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/set-path.md @@ -0,0 +1,11 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [setPath](./set-path.md) + +# setPath + +`fun setPath(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, encoded: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +### Parameters + +`path` - 如果其不包含http/https则会自动拼接[NetConfig.host](../../com.drake.net/-net-config/host.md) + +`encoded` - 是否已经进行过URLEncoder编码 \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-base-request/set-query.md b/docs/api/net/com.drake.net.request/-base-request/set-query.md new file mode 100644 index 000000000..d551ab3b8 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/set-query.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [setQuery](./set-query.md) + +# setQuery + +`fun setQuery(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?, encoded: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-base-request/set-tag.md b/docs/api/net/com.drake.net.request/-base-request/set-tag.md new file mode 100644 index 000000000..2d74bb451 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/set-tag.md @@ -0,0 +1,19 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [setTag](./set-tag.md) + +# setTag + +`fun setTag(tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +将一个任意对象添加到Request对象中, 一般用于在拦截器或者转换器中被获取到标签, 针对某个请求的特殊业务逻辑 +使用`Request.tag()`获取标签 + +`fun setTag(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +添加标签 +使用`Request.tag(name)`得到指定标签 + +### Parameters + +`name` - 标签名称 + +`tag` - 标签 \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-base-request/set-url.md b/docs/api/net/com.drake.net.request/-base-request/set-url.md new file mode 100644 index 000000000..1e94213fd --- /dev/null +++ b/docs/api/net/com.drake.net.request/-base-request/set-url.md @@ -0,0 +1,11 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BaseRequest](index.md) / [setUrl](./set-url.md) + +# setUrl + +`open fun setUrl(url: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +设置一个Url字符串, 其参数不会和你初始化时设置的主域名[NetConfig.host](../../com.drake.net/-net-config/host.md)进行拼接 +一般情况下我建议使用更为聪明的[setPath](set-path.md) + +`open fun setUrl(url: HttpUrl): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) +`open fun setUrl(url: `[`URL`](https://docs.oracle.com/javase/6/docs/api/java/net/URL.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-body-request/-init-.md b/docs/api/net/com.drake.net.request/-body-request/-init-.md new file mode 100644 index 000000000..ea061d516 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-body-request/-init-.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BodyRequest](index.md) / [<init>](./-init-.md) + +# <init> + +`BodyRequest()` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-body-request/add-upload-listener.md b/docs/api/net/com.drake.net.request/-body-request/add-upload-listener.md new file mode 100644 index 000000000..c28b80fd7 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-body-request/add-upload-listener.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BodyRequest](index.md) / [addUploadListener](./add-upload-listener.md) + +# addUploadListener + +`fun addUploadListener(progressListener: `[`ProgressListener`](../-progress-listener/index.md)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +上传进度监听器 + diff --git a/docs/api/net/com.drake.net.request/-body-request/body.md b/docs/api/net/com.drake.net.request/-body-request/body.md new file mode 100644 index 000000000..47b378a9f --- /dev/null +++ b/docs/api/net/com.drake.net.request/-body-request/body.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BodyRequest](index.md) / [body](./body.md) + +# body + +`var body: RequestBody?` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-body-request/build-request.md b/docs/api/net/com.drake.net.request/-body-request/build-request.md new file mode 100644 index 000000000..de026aa2d --- /dev/null +++ b/docs/api/net/com.drake.net.request/-body-request/build-request.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BodyRequest](index.md) / [buildRequest](./build-request.md) + +# buildRequest + +`fun buildRequest(): Request` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-body-request/execute.md b/docs/api/net/com.drake.net.request/-body-request/execute.md new file mode 100644 index 000000000..f2c260260 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-body-request/execute.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BodyRequest](index.md) / [execute](./execute.md) + +# execute + +`fun execute(): R` + +执行请求 + diff --git a/docs/api/net/com.drake.net.request/-body-request/form-param.md b/docs/api/net/com.drake.net.request/-body-request/form-param.md new file mode 100644 index 000000000..10f63b379 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-body-request/form-param.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BodyRequest](index.md) / [formParam](./form-param.md) + +# formParam + +`var formParam: Builder` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-body-request/index.md b/docs/api/net/com.drake.net.request/-body-request/index.md new file mode 100644 index 000000000..380517454 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-body-request/index.md @@ -0,0 +1,31 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BodyRequest](./index.md) + +# BodyRequest + +`class BodyRequest : `[`BaseRequest`](../-base-request/index.md) + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `BodyRequest()` | + +### Properties + +| Name | Summary | +|---|---| +| [body](body.md) | `var body: RequestBody?` | +| [formParam](form-param.md) | `var formParam: Builder` | +| [mediaType](media-type.md) | `var mediaType: MediaType` | +| [method](method.md) | `var method: `[`Method`](../-method/index.md) | +| [partParam](part-param.md) | `var partParam: Builder` | + +### Functions + +| Name | Summary | +|---|---| +| [addUploadListener](add-upload-listener.md) | 上传进度监听器`fun addUploadListener(progressListener: `[`ProgressListener`](../-progress-listener/index.md)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [buildRequest](build-request.md) | `fun buildRequest(): Request` | +| [execute](execute.md) | 执行请求`fun execute(): R` | +| [json](json.md) | `fun json(body: `[`JSONObject`](https://developer.android.com/reference/org/json/JSONObject.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`fun json(body: `[`JSONArray`](https://developer.android.com/reference/org/json/JSONArray.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`fun json(body: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`fun json(body: `[`Map`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?>?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`fun json(vararg body: `[`Pair`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-pair/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?>): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [param](param.md) | `fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?, encoded: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`Number`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-number/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: RequestBody?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: ByteString?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`ByteArray`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`File`](https://docs.oracle.com/javase/6/docs/api/java/io/File.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, values: `[`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)`<`[`File`](https://docs.oracle.com/javase/6/docs/api/java/io/File.html)`?>?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, fileName: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?, value: `[`File`](https://docs.oracle.com/javase/6/docs/api/java/io/File.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`fun param(body: RequestBody, header: Headers? = null): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`fun param(body: Part): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | diff --git a/docs/api/net/com.drake.net.request/-body-request/json.md b/docs/api/net/com.drake.net.request/-body-request/json.md new file mode 100644 index 000000000..081f6f25f --- /dev/null +++ b/docs/api/net/com.drake.net.request/-body-request/json.md @@ -0,0 +1,9 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BodyRequest](index.md) / [json](./json.md) + +# json + +`fun json(body: `[`JSONObject`](https://developer.android.com/reference/org/json/JSONObject.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) +`fun json(body: `[`JSONArray`](https://developer.android.com/reference/org/json/JSONArray.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) +`fun json(body: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) +`fun json(body: `[`Map`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?>?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) +`fun json(vararg body: `[`Pair`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-pair/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?>): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-body-request/media-type.md b/docs/api/net/com.drake.net.request/-body-request/media-type.md new file mode 100644 index 000000000..db5663e38 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-body-request/media-type.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BodyRequest](index.md) / [mediaType](./media-type.md) + +# mediaType + +`var mediaType: MediaType` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-body-request/method.md b/docs/api/net/com.drake.net.request/-body-request/method.md new file mode 100644 index 000000000..50d6e77bb --- /dev/null +++ b/docs/api/net/com.drake.net.request/-body-request/method.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BodyRequest](index.md) / [method](./method.md) + +# method + +`var method: `[`Method`](../-method/index.md) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-body-request/param.md b/docs/api/net/com.drake.net.request/-body-request/param.md new file mode 100644 index 000000000..ff72f6d6d --- /dev/null +++ b/docs/api/net/com.drake.net.request/-body-request/param.md @@ -0,0 +1,15 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BodyRequest](index.md) / [param](./param.md) + +# param + +`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?, encoded: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) +`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`Number`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-number/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) +`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) +`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: RequestBody?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) +`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: ByteString?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) +`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`ByteArray`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) +`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`File`](https://docs.oracle.com/javase/6/docs/api/java/io/File.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) +`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, values: `[`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)`<`[`File`](https://docs.oracle.com/javase/6/docs/api/java/io/File.html)`?>?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) +`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, fileName: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?, value: `[`File`](https://docs.oracle.com/javase/6/docs/api/java/io/File.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) +`fun param(body: RequestBody, header: Headers? = null): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) +`fun param(body: Part): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-body-request/part-param.md b/docs/api/net/com.drake.net.request/-body-request/part-param.md new file mode 100644 index 000000000..16e0c13c3 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-body-request/part-param.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [BodyRequest](index.md) / [partParam](./part-param.md) + +# partParam + +`var partParam: Builder` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-method/-d-e-l-e-t-e.md b/docs/api/net/com.drake.net.request/-method/-d-e-l-e-t-e.md new file mode 100644 index 000000000..1fefa77e8 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-method/-d-e-l-e-t-e.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Method](index.md) / [DELETE](./-d-e-l-e-t-e.md) + +# DELETE + +`DELETE` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-method/-g-e-t.md b/docs/api/net/com.drake.net.request/-method/-g-e-t.md new file mode 100644 index 000000000..4a5207448 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-method/-g-e-t.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Method](index.md) / [GET](./-g-e-t.md) + +# GET + +`GET` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-method/-h-e-a-d.md b/docs/api/net/com.drake.net.request/-method/-h-e-a-d.md new file mode 100644 index 000000000..793dcacb0 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-method/-h-e-a-d.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Method](index.md) / [HEAD](./-h-e-a-d.md) + +# HEAD + +`HEAD` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-method/-o-p-t-i-o-n-s.md b/docs/api/net/com.drake.net.request/-method/-o-p-t-i-o-n-s.md new file mode 100644 index 000000000..1893ae278 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-method/-o-p-t-i-o-n-s.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Method](index.md) / [OPTIONS](./-o-p-t-i-o-n-s.md) + +# OPTIONS + +`OPTIONS` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-method/-p-a-t-c-h.md b/docs/api/net/com.drake.net.request/-method/-p-a-t-c-h.md new file mode 100644 index 000000000..76e8e1e0e --- /dev/null +++ b/docs/api/net/com.drake.net.request/-method/-p-a-t-c-h.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Method](index.md) / [PATCH](./-p-a-t-c-h.md) + +# PATCH + +`PATCH` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-method/-p-o-s-t.md b/docs/api/net/com.drake.net.request/-method/-p-o-s-t.md new file mode 100644 index 000000000..315d09c2d --- /dev/null +++ b/docs/api/net/com.drake.net.request/-method/-p-o-s-t.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Method](index.md) / [POST](./-p-o-s-t.md) + +# POST + +`POST` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-method/-p-u-t.md b/docs/api/net/com.drake.net.request/-method/-p-u-t.md new file mode 100644 index 000000000..1f8052efd --- /dev/null +++ b/docs/api/net/com.drake.net.request/-method/-p-u-t.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Method](index.md) / [PUT](./-p-u-t.md) + +# PUT + +`PUT` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-method/-t-r-a-c-e.md b/docs/api/net/com.drake.net.request/-method/-t-r-a-c-e.md new file mode 100644 index 000000000..0d47d5d7a --- /dev/null +++ b/docs/api/net/com.drake.net.request/-method/-t-r-a-c-e.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Method](index.md) / [TRACE](./-t-r-a-c-e.md) + +# TRACE + +`TRACE` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-method/index.md b/docs/api/net/com.drake.net.request/-method/index.md new file mode 100644 index 000000000..888549e92 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-method/index.md @@ -0,0 +1,18 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Method](./index.md) + +# Method + +`enum class Method` + +### Enum Values + +| Name | Summary | +|---|---| +| [GET](-g-e-t.md) | | +| [HEAD](-h-e-a-d.md) | | +| [OPTIONS](-o-p-t-i-o-n-s.md) | | +| [TRACE](-t-r-a-c-e.md) | | +| [POST](-p-o-s-t.md) | | +| [DELETE](-d-e-l-e-t-e.md) | | +| [PUT](-p-u-t.md) | | +| [PATCH](-p-a-t-c-h.md) | | diff --git a/docs/api/net/com.drake.net.request/-progress-listener/-init-.md b/docs/api/net/com.drake.net.request/-progress-listener/-init-.md new file mode 100644 index 000000000..afb101f84 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress-listener/-init-.md @@ -0,0 +1,11 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [ProgressListener](index.md) / [<init>](./-init-.md) + +# <init> + +`ProgressListener(interval: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)` = 500)` + +进度监听器, 为下载和上传两者 + +### Parameters + +`interval` - 进度监听器刷新的间隔时间, 单位为毫秒, 默认值为500ms \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-progress-listener/elapsed-time.md b/docs/api/net/com.drake.net.request/-progress-listener/elapsed-time.md new file mode 100644 index 000000000..cd17c210d --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress-listener/elapsed-time.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [ProgressListener](index.md) / [elapsedTime](./elapsed-time.md) + +# elapsedTime + +`var elapsedTime: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-progress-listener/index.md b/docs/api/net/com.drake.net.request/-progress-listener/index.md new file mode 100644 index 000000000..e2ae27714 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress-listener/index.md @@ -0,0 +1,31 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [ProgressListener](./index.md) + +# ProgressListener + +`abstract class ProgressListener` + +进度监听器, 为下载和上传两者 + +### Parameters + +`interval` - 进度监听器刷新的间隔时间, 单位为毫秒, 默认值为500ms + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | 进度监听器, 为下载和上传两者`ProgressListener(interval: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)` = 500)` | + +### Properties + +| Name | Summary | +|---|---| +| [elapsedTime](elapsed-time.md) | `var elapsedTime: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | +| [interval](interval.md) | 进度监听器刷新的间隔时间, 单位为毫秒, 默认值为500ms`var interval: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | +| [progressBuffBytes](progress-buff-bytes.md) | `var progressBuffBytes: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | + +### Functions + +| Name | Summary | +|---|---| +| [onProgress](on-progress.md) | `abstract fun onProgress(p: `[`Progress`](../-progress/index.md)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | diff --git a/docs/api/net/com.drake.net.request/-progress-listener/interval.md b/docs/api/net/com.drake.net.request/-progress-listener/interval.md new file mode 100644 index 000000000..0a9c48482 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress-listener/interval.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [ProgressListener](index.md) / [interval](./interval.md) + +# interval + +`var interval: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) + +进度监听器刷新的间隔时间, 单位为毫秒, 默认值为500ms + diff --git a/docs/api/net/com.drake.net.request/-progress-listener/on-progress.md b/docs/api/net/com.drake.net.request/-progress-listener/on-progress.md new file mode 100644 index 000000000..5530ca75b --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress-listener/on-progress.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [ProgressListener](index.md) / [onProgress](./on-progress.md) + +# onProgress + +`abstract fun onProgress(p: `[`Progress`](../-progress/index.md)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-progress-listener/progress-buff-bytes.md b/docs/api/net/com.drake.net.request/-progress-listener/progress-buff-bytes.md new file mode 100644 index 000000000..9ae364ce7 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress-listener/progress-buff-bytes.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [ProgressListener](index.md) / [progressBuffBytes](./progress-buff-bytes.md) + +# progressBuffBytes + +`var progressBuffBytes: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-progress/-init-.md b/docs/api/net/com.drake.net.request/-progress/-init-.md new file mode 100644 index 000000000..370a192d1 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress/-init-.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Progress](index.md) / [<init>](./-init-.md) + +# <init> + +`Progress(currentBytes: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)` = 0, totalBytes: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)` = 0, intervalBytes: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)` = 0, intervalTime: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)` = 0, startElapsedRealtime: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)` = SystemClock.elapsedRealtime())` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-progress/current-bytes.md b/docs/api/net/com.drake.net.request/-progress/current-bytes.md new file mode 100644 index 000000000..225b0dfce --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress/current-bytes.md @@ -0,0 +1,11 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Progress](index.md) / [currentBytes](./current-bytes.md) + +# currentBytes + +`var currentBytes: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) + +当前已经完成的字节数 + +### Property + +`currentBytes` - 当前已经完成的字节数 \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-progress/current-size.md b/docs/api/net/com.drake.net.request/-progress/current-size.md new file mode 100644 index 000000000..10f616e03 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress/current-size.md @@ -0,0 +1,9 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Progress](index.md) / [currentSize](./current-size.md) + +# currentSize + +`fun currentSize(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) + +已完成文件大小 +根据字节数自动显示内存单位, 例如 19MB 或者 27KB + diff --git a/docs/api/net/com.drake.net.request/-progress/finish.md b/docs/api/net/com.drake.net.request/-progress/finish.md new file mode 100644 index 000000000..55aca78a3 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress/finish.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Progress](index.md) / [finish](./finish.md) + +# finish + +`fun finish(): `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) + +是否完成 + diff --git a/docs/api/net/com.drake.net.request/-progress/index.md b/docs/api/net/com.drake.net.request/-progress/index.md new file mode 100644 index 000000000..32903bad4 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress/index.md @@ -0,0 +1,37 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Progress](./index.md) + +# Progress + +`data class Progress` + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `Progress(currentBytes: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)` = 0, totalBytes: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)` = 0, intervalBytes: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)` = 0, intervalTime: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)` = 0, startElapsedRealtime: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)` = SystemClock.elapsedRealtime())` | + +### Properties + +| Name | Summary | +|---|---| +| [currentBytes](current-bytes.md) | 当前已经完成的字节数`var currentBytes: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | +| [intervalBytes](interval-bytes.md) | 进度间隔时间内完成的字节数`var intervalBytes: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | +| [intervalTime](interval-time.md) | 距离上次进度变化间隔时间`var intervalTime: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | +| [speedBytes](speed-bytes.md) | 每秒下载速度, 字节单位`var speedBytes: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | +| [startElapsedRealtime](start-elapsed-realtime.md) | 开始下载的时间`val startElapsedRealtime: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | +| [totalBytes](total-bytes.md) | 当前已经完成的字节数`var totalBytes: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | + +### Functions + +| Name | Summary | +|---|---| +| [currentSize](current-size.md) | 已完成文件大小 根据字节数自动显示内存单位, 例如 19MB 或者 27KB`fun currentSize(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | +| [finish](finish.md) | 是否完成`fun finish(): `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | +| [progress](progress.md) | 请求或者响应的进度, 值范围在0-100`fun progress(): `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | +| [remainSize](remain-size.md) | 剩余大小 根据字节数自动显示内存单位, 例如 19MB 或者 27KB`fun remainSize(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | +| [remainTime](remain-time.md) | 剩余时间`fun remainTime(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | +| [remainTimeSeconds](remain-time-seconds.md) | 剩余时间`fun remainTimeSeconds(): `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | +| [speedSize](speed-size.md) | 每秒下载速度 根据字节数自动显示内存单位, 例如 19MB 或者 27KB`fun speedSize(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | +| [totalSize](total-size.md) | 文件全部大小 根据字节数自动显示内存单位, 例如 19MB 或者 27KB`fun totalSize(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | +| [useTime](use-time.md) | 已使用时间`fun useTime(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | +| [useTimeSeconds](use-time-seconds.md) | 已使用时间`fun useTimeSeconds(): `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | diff --git a/docs/api/net/com.drake.net.request/-progress/interval-bytes.md b/docs/api/net/com.drake.net.request/-progress/interval-bytes.md new file mode 100644 index 000000000..c9afc786a --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress/interval-bytes.md @@ -0,0 +1,11 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Progress](index.md) / [intervalBytes](./interval-bytes.md) + +# intervalBytes + +`var intervalBytes: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) + +进度间隔时间内完成的字节数 + +### Property + +`intervalBytes` - 进度间隔时间内完成的字节数 \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-progress/interval-time.md b/docs/api/net/com.drake.net.request/-progress/interval-time.md new file mode 100644 index 000000000..db22a7910 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress/interval-time.md @@ -0,0 +1,11 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Progress](index.md) / [intervalTime](./interval-time.md) + +# intervalTime + +`var intervalTime: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) + +距离上次进度变化间隔时间 + +### Property + +`intervalTime` - 距离上次进度变化间隔时间 \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-progress/progress.md b/docs/api/net/com.drake.net.request/-progress/progress.md new file mode 100644 index 000000000..b17a5dfe3 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress/progress.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Progress](index.md) / [progress](./progress.md) + +# progress + +`fun progress(): `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) + +请求或者响应的进度, 值范围在0-100 + diff --git a/docs/api/net/com.drake.net.request/-progress/remain-size.md b/docs/api/net/com.drake.net.request/-progress/remain-size.md new file mode 100644 index 000000000..8d554af59 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress/remain-size.md @@ -0,0 +1,9 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Progress](index.md) / [remainSize](./remain-size.md) + +# remainSize + +`fun remainSize(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) + +剩余大小 +根据字节数自动显示内存单位, 例如 19MB 或者 27KB + diff --git a/docs/api/net/com.drake.net.request/-progress/remain-time-seconds.md b/docs/api/net/com.drake.net.request/-progress/remain-time-seconds.md new file mode 100644 index 000000000..395625a60 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress/remain-time-seconds.md @@ -0,0 +1,11 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Progress](index.md) / [remainTimeSeconds](./remain-time-seconds.md) + +# remainTimeSeconds + +`fun remainTimeSeconds(): `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) + +剩余时间 + +**Return** +秒 + diff --git a/docs/api/net/com.drake.net.request/-progress/remain-time.md b/docs/api/net/com.drake.net.request/-progress/remain-time.md new file mode 100644 index 000000000..12004433f --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress/remain-time.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Progress](index.md) / [remainTime](./remain-time.md) + +# remainTime + +`fun remainTime(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) + +剩余时间 + diff --git a/docs/api/net/com.drake.net.request/-progress/speed-bytes.md b/docs/api/net/com.drake.net.request/-progress/speed-bytes.md new file mode 100644 index 000000000..04817b18c --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress/speed-bytes.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Progress](index.md) / [speedBytes](./speed-bytes.md) + +# speedBytes + +`var speedBytes: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) + +每秒下载速度, 字节单位 + diff --git a/docs/api/net/com.drake.net.request/-progress/speed-size.md b/docs/api/net/com.drake.net.request/-progress/speed-size.md new file mode 100644 index 000000000..fee0d773b --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress/speed-size.md @@ -0,0 +1,9 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Progress](index.md) / [speedSize](./speed-size.md) + +# speedSize + +`fun speedSize(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) + +每秒下载速度 +根据字节数自动显示内存单位, 例如 19MB 或者 27KB + diff --git a/docs/api/net/com.drake.net.request/-progress/start-elapsed-realtime.md b/docs/api/net/com.drake.net.request/-progress/start-elapsed-realtime.md new file mode 100644 index 000000000..572ca1b93 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress/start-elapsed-realtime.md @@ -0,0 +1,11 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Progress](index.md) / [startElapsedRealtime](./start-elapsed-realtime.md) + +# startElapsedRealtime + +`val startElapsedRealtime: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) + +开始下载的时间 + +### Property + +`startElapsedRealtime` - 开始下载的时间 \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-progress/total-bytes.md b/docs/api/net/com.drake.net.request/-progress/total-bytes.md new file mode 100644 index 000000000..dddb70faf --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress/total-bytes.md @@ -0,0 +1,11 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Progress](index.md) / [totalBytes](./total-bytes.md) + +# totalBytes + +`var totalBytes: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) + +当前已经完成的字节数 + +### Property + +`totalBytes` - 当前已经完成的字节数 \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-progress/total-size.md b/docs/api/net/com.drake.net.request/-progress/total-size.md new file mode 100644 index 000000000..fb0e4f3c9 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress/total-size.md @@ -0,0 +1,9 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Progress](index.md) / [totalSize](./total-size.md) + +# totalSize + +`fun totalSize(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) + +文件全部大小 +根据字节数自动显示内存单位, 例如 19MB 或者 27KB + diff --git a/docs/api/net/com.drake.net.request/-progress/use-time-seconds.md b/docs/api/net/com.drake.net.request/-progress/use-time-seconds.md new file mode 100644 index 000000000..c59e09703 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress/use-time-seconds.md @@ -0,0 +1,11 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Progress](index.md) / [useTimeSeconds](./use-time-seconds.md) + +# useTimeSeconds + +`fun useTimeSeconds(): `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) + +已使用时间 + +**Return** +秒 + diff --git a/docs/api/net/com.drake.net.request/-progress/use-time.md b/docs/api/net/com.drake.net.request/-progress/use-time.md new file mode 100644 index 000000000..7117dac82 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-progress/use-time.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [Progress](index.md) / [useTime](./use-time.md) + +# useTime + +`fun useTime(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) + +已使用时间 + diff --git a/docs/api/net/com.drake.net.request/-url-request/-init-.md b/docs/api/net/com.drake.net.request/-url-request/-init-.md new file mode 100644 index 000000000..a0f5efb77 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-url-request/-init-.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [UrlRequest](index.md) / [<init>](./-init-.md) + +# <init> + +`UrlRequest()` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/-url-request/execute.md b/docs/api/net/com.drake.net.request/-url-request/execute.md new file mode 100644 index 000000000..825463654 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-url-request/execute.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [UrlRequest](index.md) / [execute](./execute.md) + +# execute + +`fun execute(): R` + +执行请求 + diff --git a/docs/api/net/com.drake.net.request/-url-request/index.md b/docs/api/net/com.drake.net.request/-url-request/index.md new file mode 100644 index 000000000..c03122f72 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-url-request/index.md @@ -0,0 +1,18 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [UrlRequest](./index.md) + +# UrlRequest + +`class UrlRequest : `[`BaseRequest`](../-base-request/index.md) + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `UrlRequest()` | + +### Functions + +| Name | Summary | +|---|---| +| [execute](execute.md) | 执行请求`fun execute(): R` | +| [param](param.md) | `fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?, encoded: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`Number`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-number/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | diff --git a/docs/api/net/com.drake.net.request/-url-request/param.md b/docs/api/net/com.drake.net.request/-url-request/param.md new file mode 100644 index 000000000..19b786b12 --- /dev/null +++ b/docs/api/net/com.drake.net.request/-url-request/param.md @@ -0,0 +1,7 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [UrlRequest](index.md) / [param](./param.md) + +# param + +`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?, encoded: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) +`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`Number`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-number/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) +`fun param(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, value: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/index.md b/docs/api/net/com.drake.net.request/index.md new file mode 100644 index 000000000..89569704e --- /dev/null +++ b/docs/api/net/com.drake.net.request/index.md @@ -0,0 +1,22 @@ +[net](../index.md) / [com.drake.net.request](./index.md) + +## Package com.drake.net.request + +### Types + +| Name | Summary | +|---|---| +| [BaseRequest](-base-request/index.md) | `abstract class BaseRequest` | +| [BodyRequest](-body-request/index.md) | `class BodyRequest : `[`BaseRequest`](-base-request/index.md) | +| [Method](-method/index.md) | `enum class Method` | +| [Progress](-progress/index.md) | `data class Progress` | +| [ProgressListener](-progress-listener/index.md) | 进度监听器, 为下载和上传两者`abstract class ProgressListener` | +| [UrlRequest](-url-request/index.md) | `class UrlRequest : `[`BaseRequest`](-base-request/index.md) | + +### Extensions for External Classes + +| Name | Summary | +|---|---| +| [okhttp3.MediaType](okhttp3.-media-type/index.md) | | +| [okhttp3.Request](okhttp3.-request/index.md) | | +| [okhttp3.Request.Builder](okhttp3.-request.-builder/index.md) | | diff --git a/docs/api/net/com.drake.net.request/okhttp3.-media-type/-f-o-r-m.md b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-f-o-r-m.md new file mode 100644 index 000000000..e8633798a --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-f-o-r-m.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.MediaType](index.md) / [FORM](./-f-o-r-m.md) + +# FORM + +`val MediaType.Companion.FORM: MediaType` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/okhttp3.-media-type/-g-i-f.md b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-g-i-f.md new file mode 100644 index 000000000..c0800a06a --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-g-i-f.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.MediaType](index.md) / [GIF](./-g-i-f.md) + +# GIF + +`val MediaType.Companion.GIF: MediaType` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/okhttp3.-media-type/-h-t-m-l.md b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-h-t-m-l.md new file mode 100644 index 000000000..2ba2e7dc7 --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-h-t-m-l.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.MediaType](index.md) / [HTML](./-h-t-m-l.md) + +# HTML + +`val MediaType.Companion.HTML: MediaType` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/okhttp3.-media-type/-i-m-g.md b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-i-m-g.md new file mode 100644 index 000000000..18b32d276 --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-i-m-g.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.MediaType](index.md) / [IMG](./-i-m-g.md) + +# IMG + +`val MediaType.Companion.IMG: MediaType` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/okhttp3.-media-type/-j-p-e-g.md b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-j-p-e-g.md new file mode 100644 index 000000000..8fbda5cb8 --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-j-p-e-g.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.MediaType](index.md) / [JPEG](./-j-p-e-g.md) + +# JPEG + +`val MediaType.Companion.JPEG: MediaType` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/okhttp3.-media-type/-j-s-o-n.md b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-j-s-o-n.md new file mode 100644 index 000000000..8395c4acf --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-j-s-o-n.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.MediaType](index.md) / [JSON](./-j-s-o-n.md) + +# JSON + +`val MediaType.Companion.JSON: MediaType` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/okhttp3.-media-type/-m-p4.md b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-m-p4.md new file mode 100644 index 000000000..1dd3a3c5b --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-m-p4.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.MediaType](index.md) / [MP4](./-m-p4.md) + +# MP4 + +`val MediaType.Companion.MP4: MediaType` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/okhttp3.-media-type/-p-n-g.md b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-p-n-g.md new file mode 100644 index 000000000..427ffd6db --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-p-n-g.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.MediaType](index.md) / [PNG](./-p-n-g.md) + +# PNG + +`val MediaType.Companion.PNG: MediaType` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/okhttp3.-media-type/-t-x-t.md b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-t-x-t.md new file mode 100644 index 000000000..d59a3d0e8 --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-t-x-t.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.MediaType](index.md) / [TXT](./-t-x-t.md) + +# TXT + +`val MediaType.Companion.TXT: MediaType` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/okhttp3.-media-type/-u-r-l-e-n-c-o-d-e-d.md b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-u-r-l-e-n-c-o-d-e-d.md new file mode 100644 index 000000000..41b89d08b --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-u-r-l-e-n-c-o-d-e-d.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.MediaType](index.md) / [URLENCODED](./-u-r-l-e-n-c-o-d-e-d.md) + +# URLENCODED + +`val MediaType.Companion.URLENCODED: MediaType` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/okhttp3.-media-type/-x-m-l.md b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-x-m-l.md new file mode 100644 index 000000000..b2174538a --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-media-type/-x-m-l.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.MediaType](index.md) / [XML](./-x-m-l.md) + +# XML + +`val MediaType.Companion.XML: MediaType` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/okhttp3.-media-type/index.md b/docs/api/net/com.drake.net.request/okhttp3.-media-type/index.md new file mode 100644 index 000000000..73d5f75b8 --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-media-type/index.md @@ -0,0 +1,17 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.MediaType](./index.md) + +### Extensions for okhttp3.MediaType + +| Name | Summary | +|---|---| +| [FORM](-f-o-r-m.md) | `val MediaType.Companion.FORM: MediaType` | +| [GIF](-g-i-f.md) | `val MediaType.Companion.GIF: MediaType` | +| [HTML](-h-t-m-l.md) | `val MediaType.Companion.HTML: MediaType` | +| [IMG](-i-m-g.md) | `val MediaType.Companion.IMG: MediaType` | +| [JPEG](-j-p-e-g.md) | `val MediaType.Companion.JPEG: MediaType` | +| [JSON](-j-s-o-n.md) | `val MediaType.Companion.JSON: MediaType` | +| [MP4](-m-p4.md) | `val MediaType.Companion.MP4: MediaType` | +| [PNG](-p-n-g.md) | `val MediaType.Companion.PNG: MediaType` | +| [TXT](-t-x-t.md) | `val MediaType.Companion.TXT: MediaType` | +| [URLENCODED](-u-r-l-e-n-c-o-d-e-d.md) | `val MediaType.Companion.URLENCODED: MediaType` | +| [XML](-x-m-l.md) | `val MediaType.Companion.XML: MediaType` | diff --git a/docs/api/net/com.drake.net.request/okhttp3.-request.-builder/index.md b/docs/api/net/com.drake.net.request/okhttp3.-request.-builder/index.md new file mode 100644 index 000000000..135d33091 --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-request.-builder/index.md @@ -0,0 +1,10 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.Request.Builder](./index.md) + +### Extensions for okhttp3.Request.Builder + +| Name | Summary | +|---|---| +| [setConverter](set-converter.md) | `fun Builder.setConverter(converter: `[`NetConverter`](../../com.drake.net.convert/-net-converter/index.md)`): ` | +| [setGroup](set-group.md) | `fun Builder.setGroup(group: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?): ` | +| [setId](set-id.md) | `fun Builder.setId(id: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?): ` | +| [setLabel](set-label.md) | `fun Builder.setLabel(any: T): ` | diff --git a/docs/api/net/com.drake.net.request/okhttp3.-request.-builder/set-converter.md b/docs/api/net/com.drake.net.request/okhttp3.-request.-builder/set-converter.md new file mode 100644 index 000000000..4f4e3bb36 --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-request.-builder/set-converter.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.Request.Builder](index.md) / [setConverter](./set-converter.md) + +# setConverter + +`fun Builder.setConverter(converter: `[`NetConverter`](../../com.drake.net.convert/-net-converter/index.md)`): ` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/okhttp3.-request.-builder/set-group.md b/docs/api/net/com.drake.net.request/okhttp3.-request.-builder/set-group.md new file mode 100644 index 000000000..b27ab225e --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-request.-builder/set-group.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.Request.Builder](index.md) / [setGroup](./set-group.md) + +# setGroup + +`fun Builder.setGroup(group: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?): ` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/okhttp3.-request.-builder/set-id.md b/docs/api/net/com.drake.net.request/okhttp3.-request.-builder/set-id.md new file mode 100644 index 000000000..5e7862464 --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-request.-builder/set-id.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.Request.Builder](index.md) / [setId](./set-id.md) + +# setId + +`fun Builder.setId(id: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?): ` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/okhttp3.-request.-builder/set-label.md b/docs/api/net/com.drake.net.request/okhttp3.-request.-builder/set-label.md new file mode 100644 index 000000000..7871b9421 --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-request.-builder/set-label.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.Request.Builder](index.md) / [setLabel](./set-label.md) + +# setLabel + +`fun Builder.setLabel(any: T): ` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/okhttp3.-request/converter.md b/docs/api/net/com.drake.net.request/okhttp3.-request/converter.md new file mode 100644 index 000000000..de2aba67e --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-request/converter.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.Request](index.md) / [converter](./converter.md) + +# converter + +`fun Request.converter(): `[`NetConverter`](../../com.drake.net.convert/-net-converter/index.md)`?` + +转换器 + diff --git a/docs/api/net/com.drake.net.request/okhttp3.-request/download-conflict-rename.md b/docs/api/net/com.drake.net.request/okhttp3.-request/download-conflict-rename.md new file mode 100644 index 000000000..62fa61dfc --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-request/download-conflict-rename.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.Request](index.md) / [downloadConflictRename](./download-conflict-rename.md) + +# downloadConflictRename + +`fun Request.downloadConflictRename(): `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`?` + +当指定下载目录存在同名文件是覆盖还是进行重命名, 重命名规则是: $文件名_($序号).$后缀 + diff --git a/docs/api/net/com.drake.net.request/okhttp3.-request/download-file-dir.md b/docs/api/net/com.drake.net.request/okhttp3.-request/download-file-dir.md new file mode 100644 index 000000000..d468fe649 --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-request/download-file-dir.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.Request](index.md) / [downloadFileDir](./download-file-dir.md) + +# downloadFileDir + +`fun Request.downloadFileDir(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) + +下载文件目录 + diff --git a/docs/api/net/com.drake.net.request/okhttp3.-request/download-file-name-decode.md b/docs/api/net/com.drake.net.request/okhttp3.-request/download-file-name-decode.md new file mode 100644 index 000000000..c93b26931 --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-request/download-file-name-decode.md @@ -0,0 +1,9 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.Request](index.md) / [downloadFileNameDecode](./download-file-name-decode.md) + +# downloadFileNameDecode + +`fun Request.downloadFileNameDecode(): `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`?` + +下载的文件名称是否解码 +例如下载的文件名如果是中文, 服务器传输给你的会是被URL编码的字符串. 你使用URL解码后才是可读的中文名称 + diff --git a/docs/api/net/com.drake.net.request/okhttp3.-request/download-listeners.md b/docs/api/net/com.drake.net.request/okhttp3.-request/download-listeners.md new file mode 100644 index 000000000..02d521001 --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-request/download-listeners.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.Request](index.md) / [downloadListeners](./download-listeners.md) + +# downloadListeners + +`fun Request.downloadListeners(): `[`ConcurrentLinkedQueue`](https://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html)`<`[`ProgressListener`](../-progress-listener/index.md)`>?` + +下载监听器 + diff --git a/docs/api/net/com.drake.net.request/okhttp3.-request/download-md5-verify.md b/docs/api/net/com.drake.net.request/okhttp3.-request/download-md5-verify.md new file mode 100644 index 000000000..76852161b --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-request/download-md5-verify.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.Request](index.md) / [downloadMd5Verify](./download-md5-verify.md) + +# downloadMd5Verify + +`fun Request.downloadMd5Verify(): `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`?` + +是否进行校验文件md5, 如果校验则匹配上既马上返回文件而不会进行下载 + diff --git a/docs/api/net/com.drake.net.request/okhttp3.-request/download-temp-file.md b/docs/api/net/com.drake.net.request/okhttp3.-request/download-temp-file.md new file mode 100644 index 000000000..f829e45fa --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-request/download-temp-file.md @@ -0,0 +1,11 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.Request](index.md) / [downloadTempFile](./download-temp-file.md) + +# downloadTempFile + +`fun Request.downloadTempFile(): `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`?` + +下载是否使用临时文件 +避免下载失败后覆盖同名文件或者无法判别是否已下载完整, 仅在下载完整以后才会显示为原有文件名 +临时文件命名规则: 文件名 + .net-download + 下载文件名: install.apk, 临时文件名: install.apk.net-download + diff --git a/docs/api/net/com.drake.net.request/okhttp3.-request/file-name.md b/docs/api/net/com.drake.net.request/okhttp3.-request/file-name.md new file mode 100644 index 000000000..c2b6c3df3 --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-request/file-name.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.Request](index.md) / [fileName](./file-name.md) + +# fileName + +`fun Request.fileName(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?` + +下载文件名 + diff --git a/docs/api/net/com.drake.net.request/okhttp3.-request/group.md b/docs/api/net/com.drake.net.request/okhttp3.-request/group.md new file mode 100644 index 000000000..75be2fc77 --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-request/group.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.Request](index.md) / [group](./group.md) + +# group + +`fun Request.group(): `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?` + +请求的分组名 + diff --git a/docs/api/net/com.drake.net.request/okhttp3.-request/id.md b/docs/api/net/com.drake.net.request/okhttp3.-request/id.md new file mode 100644 index 000000000..e4d675266 --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-request/id.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.Request](index.md) / [id](./id.md) + +# id + +`fun Request.id(): `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?` + +请求的Id + diff --git a/docs/api/net/com.drake.net.request/okhttp3.-request/index.md b/docs/api/net/com.drake.net.request/okhttp3.-request/index.md new file mode 100644 index 000000000..876b27eae --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-request/index.md @@ -0,0 +1,19 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.Request](./index.md) + +### Extensions for okhttp3.Request + +| Name | Summary | +|---|---| +| [converter](converter.md) | 转换器`fun Request.converter(): `[`NetConverter`](../../com.drake.net.convert/-net-converter/index.md)`?` | +| [downloadConflictRename](download-conflict-rename.md) | 当指定下载目录存在同名文件是覆盖还是进行重命名, 重命名规则是: $文件名_($序号).$后缀`fun Request.downloadConflictRename(): `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`?` | +| [downloadFileDir](download-file-dir.md) | 下载文件目录`fun Request.downloadFileDir(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | +| [downloadFileNameDecode](download-file-name-decode.md) | 下载的文件名称是否解码 例如下载的文件名如果是中文, 服务器传输给你的会是被URL编码的字符串. 你使用URL解码后才是可读的中文名称`fun Request.downloadFileNameDecode(): `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`?` | +| [downloadListeners](download-listeners.md) | 下载监听器`fun Request.downloadListeners(): `[`ConcurrentLinkedQueue`](https://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html)`<`[`ProgressListener`](../-progress-listener/index.md)`>?` | +| [downloadMd5Verify](download-md5-verify.md) | 是否进行校验文件md5, 如果校验则匹配上既马上返回文件而不会进行下载`fun Request.downloadMd5Verify(): `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`?` | +| [downloadTempFile](download-temp-file.md) | 下载是否使用临时文件 避免下载失败后覆盖同名文件或者无法判别是否已下载完整, 仅在下载完整以后才会显示为原有文件名 临时文件命名规则: 文件名 + .net-download 下载文件名: install.apk, 临时文件名: install.apk.net-download`fun Request.downloadTempFile(): `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`?` | +| [fileName](file-name.md) | 下载文件名`fun Request.fileName(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?` | +| [group](group.md) | 请求的分组名`fun Request.group(): `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?` | +| [id](id.md) | 请求的Id`fun Request.id(): `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?` | +| [label](label.md) | `fun Request.label(): T?` | +| [tag](tag.md) | 请求标签`fun Request.tag(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`): `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?` | +| [uploadListeners](upload-listeners.md) | 上传监听器`fun Request.uploadListeners(): `[`ConcurrentLinkedQueue`](https://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html)`<`[`ProgressListener`](../-progress-listener/index.md)`>?` | diff --git a/docs/api/net/com.drake.net.request/okhttp3.-request/label.md b/docs/api/net/com.drake.net.request/okhttp3.-request/label.md new file mode 100644 index 000000000..f412a9fdd --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-request/label.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.Request](index.md) / [label](./label.md) + +# label + +`fun Request.label(): T?` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.request/okhttp3.-request/tag.md b/docs/api/net/com.drake.net.request/okhttp3.-request/tag.md new file mode 100644 index 000000000..13cf778d9 --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-request/tag.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.Request](index.md) / [tag](./tag.md) + +# tag + +`fun Request.tag(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`): `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?` + +请求标签 + diff --git a/docs/api/net/com.drake.net.request/okhttp3.-request/upload-listeners.md b/docs/api/net/com.drake.net.request/okhttp3.-request/upload-listeners.md new file mode 100644 index 000000000..dd88b267e --- /dev/null +++ b/docs/api/net/com.drake.net.request/okhttp3.-request/upload-listeners.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.request](../index.md) / [okhttp3.Request](index.md) / [uploadListeners](./upload-listeners.md) + +# uploadListeners + +`fun Request.uploadListeners(): `[`ConcurrentLinkedQueue`](https://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html)`<`[`ProgressListener`](../-progress-listener/index.md)`>?` + +上传监听器 + diff --git a/docs/api/net/com.drake.net.response/index.md b/docs/api/net/com.drake.net.response/index.md new file mode 100644 index 000000000..3bc8a41d2 --- /dev/null +++ b/docs/api/net/com.drake.net.response/index.md @@ -0,0 +1,9 @@ +[net](../index.md) / [com.drake.net.response](./index.md) + +## Package com.drake.net.response + +### Extensions for External Classes + +| Name | Summary | +|---|---| +| [okhttp3.Response](okhttp3.-response/index.md) | | diff --git a/docs/api/net/com.drake.net.response/okhttp3.-response/file-name.md b/docs/api/net/com.drake.net.response/okhttp3.-response/file-name.md new file mode 100644 index 000000000..d711a33d3 --- /dev/null +++ b/docs/api/net/com.drake.net.response/okhttp3.-response/file-name.md @@ -0,0 +1,12 @@ +[net](../../index.md) / [com.drake.net.response](../index.md) / [okhttp3.Response](index.md) / [fileName](./file-name.md) + +# fileName + +`fun Response.fileName(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) + +按照以下顺序返回最终的下载文件的名称 + +1. 指定文件名 +2. 响应头文件名 +3. 请求URL路径 +4. 时间戳 diff --git a/docs/api/net/com.drake.net.response/okhttp3.-response/file.md b/docs/api/net/com.drake.net.response/okhttp3.-response/file.md new file mode 100644 index 000000000..32a98e8f9 --- /dev/null +++ b/docs/api/net/com.drake.net.response/okhttp3.-response/file.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.response](../index.md) / [okhttp3.Response](index.md) / [file](./file.md) + +# file + +`fun Response.file(): `[`File`](https://docs.oracle.com/javase/6/docs/api/java/io/File.html)`?` + +下载到指定文件 + diff --git a/docs/api/net/com.drake.net.response/okhttp3.-response/index.md b/docs/api/net/com.drake.net.response/okhttp3.-response/index.md new file mode 100644 index 000000000..1fa0282a6 --- /dev/null +++ b/docs/api/net/com.drake.net.response/okhttp3.-response/index.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.response](../index.md) / [okhttp3.Response](./index.md) + +### Extensions for okhttp3.Response + +| Name | Summary | +|---|---| +| [file](file.md) | 下载到指定文件`fun Response.file(): `[`File`](https://docs.oracle.com/javase/6/docs/api/java/io/File.html)`?` | +| [fileName](file-name.md) | 按照以下顺序返回最终的下载文件的名称`fun Response.fileName(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | diff --git a/docs/api/net/com.drake.net.scope/-android-scope/adjust-dispatcher.md b/docs/api/net/com.drake.net.scope/-android-scope/adjust-dispatcher.md deleted file mode 100644 index aedd2e6a3..000000000 --- a/docs/api/net/com.drake.net.scope/-android-scope/adjust-dispatcher.md +++ /dev/null @@ -1,5 +0,0 @@ -[net](../../index.md) / [com.drake.net.scope](../index.md) / [AndroidScope](index.md) / [adjustDispatcher](./adjust-dispatcher.md) - -# adjustDispatcher - -`protected fun adjustDispatcher(): CoroutineDispatcher` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.scope/-android-scope/close.md b/docs/api/net/com.drake.net.scope/-android-scope/close.md new file mode 100644 index 000000000..01356f647 --- /dev/null +++ b/docs/api/net/com.drake.net.scope/-android-scope/close.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.scope](../index.md) / [AndroidScope](index.md) / [close](./close.md) + +# close + +`open fun close(): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.scope/-android-scope/index.md b/docs/api/net/com.drake.net.scope/-android-scope/index.md index 053519eec..81e985359 100644 --- a/docs/api/net/com.drake.net.scope/-android-scope/index.md +++ b/docs/api/net/com.drake.net.scope/-android-scope/index.md @@ -2,7 +2,7 @@ # AndroidScope -`open class AndroidScope : CoroutineScope` +`open class AndroidScope : CoroutineScope, `[`Closeable`](https://docs.oracle.com/javase/6/docs/api/java/io/Closeable.html) 异步协程作用域 @@ -20,7 +20,7 @@ | [coroutineContext](coroutine-context.md) | `open val coroutineContext: `[`CoroutineContext`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-coroutine-context/index.html) | | [dispatcher](dispatcher.md) | `val dispatcher: CoroutineDispatcher` | | [finally](finally.md) | `var finally: (`[`AndroidScope`](./index.md)`.(`[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`?) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)?` | -| [uid](uid.md) | `val uid: CoroutineExceptionHandler` | +| [scopeGroup](scope-group.md) | `val scopeGroup: CoroutineExceptionHandler` | ### Functions @@ -28,6 +28,7 @@ |---|---| | [cancel](cancel.md) | `open fun cancel(cause: CancellationException? = null): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`open fun cancel(message: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, cause: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`? = null): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | | [catch](catch.md) | `open fun catch(e: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
当作用域内发生异常时回调`open fun catch(block: `[`AndroidScope`](./index.md)`.(`[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): `[`AndroidScope`](./index.md) | +| [close](close.md) | `open fun close(): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | | [finally](finally.md) | `open fun finally(e: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
无论正常或者异常结束都将最终执行`open fun finally(block: `[`AndroidScope`](./index.md)`.(`[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`?) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): `[`AndroidScope`](./index.md) | | [handleError](handle-error.md) | 错误处理`open fun handleError(e: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | | [launch](launch.md) | `open fun launch(block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`AndroidScope`](./index.md) | diff --git a/docs/api/net/com.drake.net.scope/-android-scope/scope-group.md b/docs/api/net/com.drake.net.scope/-android-scope/scope-group.md new file mode 100644 index 000000000..489c3cc64 --- /dev/null +++ b/docs/api/net/com.drake.net.scope/-android-scope/scope-group.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net.scope](../index.md) / [AndroidScope](index.md) / [scopeGroup](./scope-group.md) + +# scopeGroup + +`val scopeGroup: CoroutineExceptionHandler` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.scope/-android-scope/start.md b/docs/api/net/com.drake.net.scope/-android-scope/start.md deleted file mode 100644 index d177779e6..000000000 --- a/docs/api/net/com.drake.net.scope/-android-scope/start.md +++ /dev/null @@ -1,5 +0,0 @@ -[net](../../index.md) / [com.drake.net.scope](../index.md) / [AndroidScope](index.md) / [start](./start.md) - -# start - -`protected open fun start(): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.scope/-android-scope/uid.md b/docs/api/net/com.drake.net.scope/-android-scope/uid.md deleted file mode 100644 index 0526e697b..000000000 --- a/docs/api/net/com.drake.net.scope/-android-scope/uid.md +++ /dev/null @@ -1,5 +0,0 @@ -[net](../../index.md) / [com.drake.net.scope](../index.md) / [AndroidScope](index.md) / [uid](./uid.md) - -# uid - -`val uid: CoroutineExceptionHandler` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.scope/-net-coroutine-scope/cache.md b/docs/api/net/com.drake.net.scope/-net-coroutine-scope/cache.md deleted file mode 100644 index 10e6fc95e..000000000 --- a/docs/api/net/com.drake.net.scope/-net-coroutine-scope/cache.md +++ /dev/null @@ -1,18 +0,0 @@ -[net](../../index.md) / [com.drake.net.scope](../index.md) / [NetCoroutineScope](index.md) / [cache](./cache.md) - -# cache - -`fun cache(error: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, animate: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, onCache: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`AndroidScope`](../-android-scope/index.md) - -该函数一般用于缓存读取 -只在第一次启动作用域时回调 -该函数在作用域[launch](launch.md)之前执行 -函数内部所有的异常都不会被抛出, 也不会终止作用域执行 - -### Parameters - -`error` - 是否在缓存读取成功但网络请求错误时吐司错误信息 - -`animate` - 是否在缓存成功后依然显示加载动画 - -`onCache` - 该作用域内的所有异常都算缓存读取失败, 不会吐司和打印任何错误 \ No newline at end of file diff --git a/docs/api/net/com.drake.net.scope/-net-coroutine-scope/on-cache.md b/docs/api/net/com.drake.net.scope/-net-coroutine-scope/on-cache.md deleted file mode 100644 index d2370279c..000000000 --- a/docs/api/net/com.drake.net.scope/-net-coroutine-scope/on-cache.md +++ /dev/null @@ -1,5 +0,0 @@ -[net](../../index.md) / [com.drake.net.scope](../index.md) / [NetCoroutineScope](index.md) / [onCache](./on-cache.md) - -# onCache - -`protected var onCache: (suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)?` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.scope/index.md b/docs/api/net/com.drake.net.scope/index.md index 4d17e8b0f..7a8193193 100644 --- a/docs/api/net/com.drake.net.scope/index.md +++ b/docs/api/net/com.drake.net.scope/index.md @@ -6,7 +6,7 @@ | Name | Summary | |---|---| -| [AndroidScope](-android-scope/index.md) | 异步协程作用域`open class AndroidScope : CoroutineScope` | +| [AndroidScope](-android-scope/index.md) | 异步协程作用域`open class AndroidScope : CoroutineScope, `[`Closeable`](https://docs.oracle.com/javase/6/docs/api/java/io/Closeable.html) | | [DialogCoroutineScope](-dialog-coroutine-scope/index.md) | 自动加载对话框网络请求`class DialogCoroutineScope : `[`NetCoroutineScope`](-net-coroutine-scope/index.md)`, LifecycleObserver` | | [NetCoroutineScope](-net-coroutine-scope/index.md) | 自动显示网络错误信息协程作用域`open class NetCoroutineScope : `[`AndroidScope`](-android-scope/index.md) | | [PageCoroutineScope](-page-coroutine-scope/index.md) | `class PageCoroutineScope : `[`NetCoroutineScope`](-net-coroutine-scope/index.md) | diff --git a/docs/api/net/com.drake.net.tag/-label/-download-file-conflict-rename/-init-.md b/docs/api/net/com.drake.net.tag/-label/-download-file-conflict-rename/-init-.md new file mode 100644 index 000000000..6590db396 --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-download-file-conflict-rename/-init-.md @@ -0,0 +1,5 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [DownloadFileConflictRename](index.md) / [<init>](./-init-.md) + +# <init> + +`DownloadFileConflictRename(enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = true)` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-download-file-conflict-rename/enabled.md b/docs/api/net/com.drake.net.tag/-label/-download-file-conflict-rename/enabled.md new file mode 100644 index 000000000..e9a07ab81 --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-download-file-conflict-rename/enabled.md @@ -0,0 +1,5 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [DownloadFileConflictRename](index.md) / [enabled](./enabled.md) + +# enabled + +`val enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-download-file-conflict-rename/index.md b/docs/api/net/com.drake.net.tag/-label/-download-file-conflict-rename/index.md new file mode 100644 index 000000000..a804d367c --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-download-file-conflict-rename/index.md @@ -0,0 +1,17 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [DownloadFileConflictRename](./index.md) + +# DownloadFileConflictRename + +`inline class DownloadFileConflictRename` + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `DownloadFileConflictRename(enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = true)` | + +### Properties + +| Name | Summary | +|---|---| +| [enabled](enabled.md) | `val enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | diff --git a/docs/api/net/com.drake.net.tag/-label/-download-file-dir/-init-.md b/docs/api/net/com.drake.net.tag/-label/-download-file-dir/-init-.md new file mode 100644 index 000000000..b23d258c8 --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-download-file-dir/-init-.md @@ -0,0 +1,6 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [DownloadFileDir](index.md) / [<init>](./-init-.md) + +# <init> + +`DownloadFileDir(fileDir: `[`File`](https://docs.oracle.com/javase/6/docs/api/java/io/File.html)`?)` +`DownloadFileDir(dir: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?)` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-download-file-dir/dir.md b/docs/api/net/com.drake.net.tag/-label/-download-file-dir/dir.md new file mode 100644 index 000000000..06ebad0f7 --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-download-file-dir/dir.md @@ -0,0 +1,5 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [DownloadFileDir](index.md) / [dir](./dir.md) + +# dir + +`val dir: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-download-file-dir/index.md b/docs/api/net/com.drake.net.tag/-label/-download-file-dir/index.md new file mode 100644 index 000000000..c86ef338d --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-download-file-dir/index.md @@ -0,0 +1,17 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [DownloadFileDir](./index.md) + +# DownloadFileDir + +`inline class DownloadFileDir` + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `DownloadFileDir(fileDir: `[`File`](https://docs.oracle.com/javase/6/docs/api/java/io/File.html)`?)`
`DownloadFileDir(dir: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?)` | + +### Properties + +| Name | Summary | +|---|---| +| [dir](dir.md) | `val dir: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?` | diff --git a/docs/api/net/com.drake.net.tag/-label/-download-file-m-d5-verify/-init-.md b/docs/api/net/com.drake.net.tag/-label/-download-file-m-d5-verify/-init-.md new file mode 100644 index 000000000..803d8aa08 --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-download-file-m-d5-verify/-init-.md @@ -0,0 +1,5 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [DownloadFileMD5Verify](index.md) / [<init>](./-init-.md) + +# <init> + +`DownloadFileMD5Verify(enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = true)` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-download-file-m-d5-verify/enabled.md b/docs/api/net/com.drake.net.tag/-label/-download-file-m-d5-verify/enabled.md new file mode 100644 index 000000000..52f012589 --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-download-file-m-d5-verify/enabled.md @@ -0,0 +1,5 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [DownloadFileMD5Verify](index.md) / [enabled](./enabled.md) + +# enabled + +`val enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-download-file-m-d5-verify/index.md b/docs/api/net/com.drake.net.tag/-label/-download-file-m-d5-verify/index.md new file mode 100644 index 000000000..9468965ef --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-download-file-m-d5-verify/index.md @@ -0,0 +1,17 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [DownloadFileMD5Verify](./index.md) + +# DownloadFileMD5Verify + +`inline class DownloadFileMD5Verify` + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `DownloadFileMD5Verify(enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = true)` | + +### Properties + +| Name | Summary | +|---|---| +| [enabled](enabled.md) | `val enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | diff --git a/docs/api/net/com.drake.net.tag/-label/-download-file-name-decode/-init-.md b/docs/api/net/com.drake.net.tag/-label/-download-file-name-decode/-init-.md new file mode 100644 index 000000000..3bb944b2c --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-download-file-name-decode/-init-.md @@ -0,0 +1,5 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [DownloadFileNameDecode](index.md) / [<init>](./-init-.md) + +# <init> + +`DownloadFileNameDecode(enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = true)` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-download-file-name-decode/enabled.md b/docs/api/net/com.drake.net.tag/-label/-download-file-name-decode/enabled.md new file mode 100644 index 000000000..3e486cf98 --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-download-file-name-decode/enabled.md @@ -0,0 +1,5 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [DownloadFileNameDecode](index.md) / [enabled](./enabled.md) + +# enabled + +`val enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-download-file-name-decode/index.md b/docs/api/net/com.drake.net.tag/-label/-download-file-name-decode/index.md new file mode 100644 index 000000000..135148805 --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-download-file-name-decode/index.md @@ -0,0 +1,17 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [DownloadFileNameDecode](./index.md) + +# DownloadFileNameDecode + +`inline class DownloadFileNameDecode` + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `DownloadFileNameDecode(enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = true)` | + +### Properties + +| Name | Summary | +|---|---| +| [enabled](enabled.md) | `val enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | diff --git a/docs/api/net/com.drake.net.tag/-label/-download-file-name/-init-.md b/docs/api/net/com.drake.net.tag/-label/-download-file-name/-init-.md new file mode 100644 index 000000000..1b6f25cad --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-download-file-name/-init-.md @@ -0,0 +1,5 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [DownloadFileName](index.md) / [<init>](./-init-.md) + +# <init> + +`DownloadFileName(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?)` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-download-file-name/index.md b/docs/api/net/com.drake.net.tag/-label/-download-file-name/index.md new file mode 100644 index 000000000..3e3d6135c --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-download-file-name/index.md @@ -0,0 +1,17 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [DownloadFileName](./index.md) + +# DownloadFileName + +`inline class DownloadFileName` + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `DownloadFileName(name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?)` | + +### Properties + +| Name | Summary | +|---|---| +| [name](name.md) | `val name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?` | diff --git a/docs/api/net/com.drake.net.tag/-label/-download-file-name/name.md b/docs/api/net/com.drake.net.tag/-label/-download-file-name/name.md new file mode 100644 index 000000000..3997a023f --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-download-file-name/name.md @@ -0,0 +1,5 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [DownloadFileName](index.md) / [name](./name.md) + +# name + +`val name: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-download-listeners/-init-.md b/docs/api/net/com.drake.net.tag/-label/-download-listeners/-init-.md new file mode 100644 index 000000000..d1adf7e1b --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-download-listeners/-init-.md @@ -0,0 +1,5 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [DownloadListeners](index.md) / [<init>](./-init-.md) + +# <init> + +`DownloadListeners()` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-download-listeners/index.md b/docs/api/net/com.drake.net.tag/-label/-download-listeners/index.md new file mode 100644 index 000000000..1989ef012 --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-download-listeners/index.md @@ -0,0 +1,11 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [DownloadListeners](./index.md) + +# DownloadListeners + +`class DownloadListeners : `[`ConcurrentLinkedQueue`](https://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html)`<`[`ProgressListener`](../../../com.drake.net.request/-progress-listener/index.md)`>` + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `DownloadListeners()` | diff --git a/docs/api/net/com.drake.net.tag/-label/-download-temp-file/-init-.md b/docs/api/net/com.drake.net.tag/-label/-download-temp-file/-init-.md new file mode 100644 index 000000000..7e65bee3b --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-download-temp-file/-init-.md @@ -0,0 +1,5 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [DownloadTempFile](index.md) / [<init>](./-init-.md) + +# <init> + +`DownloadTempFile(enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = true)` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-download-temp-file/enabled.md b/docs/api/net/com.drake.net.tag/-label/-download-temp-file/enabled.md new file mode 100644 index 000000000..3750a6050 --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-download-temp-file/enabled.md @@ -0,0 +1,5 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [DownloadTempFile](index.md) / [enabled](./enabled.md) + +# enabled + +`val enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-download-temp-file/index.md b/docs/api/net/com.drake.net.tag/-label/-download-temp-file/index.md new file mode 100644 index 000000000..6177e5334 --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-download-temp-file/index.md @@ -0,0 +1,17 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [DownloadTempFile](./index.md) + +# DownloadTempFile + +`inline class DownloadTempFile` + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `DownloadTempFile(enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = true)` | + +### Properties + +| Name | Summary | +|---|---| +| [enabled](enabled.md) | `val enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | diff --git a/docs/api/net/com.drake.net.tag/-label/-request-generic/-init-.md b/docs/api/net/com.drake.net.tag/-label/-request-generic/-init-.md new file mode 100644 index 000000000..30e8bea4d --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-request-generic/-init-.md @@ -0,0 +1,5 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [RequestGeneric](index.md) / [<init>](./-init-.md) + +# <init> + +`RequestGeneric(type: `[`Type`](https://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Type.html)`)` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-request-generic/index.md b/docs/api/net/com.drake.net.tag/-label/-request-generic/index.md new file mode 100644 index 000000000..a9377140b --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-request-generic/index.md @@ -0,0 +1,17 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [RequestGeneric](./index.md) + +# RequestGeneric + +`inline class RequestGeneric` + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `RequestGeneric(type: `[`Type`](https://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Type.html)`)` | + +### Properties + +| Name | Summary | +|---|---| +| [type](type.md) | `val type: `[`Type`](https://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Type.html) | diff --git a/docs/api/net/com.drake.net.tag/-label/-request-generic/type.md b/docs/api/net/com.drake.net.tag/-label/-request-generic/type.md new file mode 100644 index 000000000..5bcefd4d6 --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-request-generic/type.md @@ -0,0 +1,5 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [RequestGeneric](index.md) / [type](./type.md) + +# type + +`val type: `[`Type`](https://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Type.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-request-group/-init-.md b/docs/api/net/com.drake.net.tag/-label/-request-group/-init-.md new file mode 100644 index 000000000..d7a731bb8 --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-request-group/-init-.md @@ -0,0 +1,5 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [RequestGroup](index.md) / [<init>](./-init-.md) + +# <init> + +`RequestGroup(value: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?)` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-request-group/index.md b/docs/api/net/com.drake.net.tag/-label/-request-group/index.md new file mode 100644 index 000000000..f152c8328 --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-request-group/index.md @@ -0,0 +1,17 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [RequestGroup](./index.md) + +# RequestGroup + +`inline class RequestGroup` + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `RequestGroup(value: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?)` | + +### Properties + +| Name | Summary | +|---|---| +| [value](value.md) | `val value: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?` | diff --git a/docs/api/net/com.drake.net.tag/-label/-request-group/value.md b/docs/api/net/com.drake.net.tag/-label/-request-group/value.md new file mode 100644 index 000000000..4a5775a71 --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-request-group/value.md @@ -0,0 +1,5 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [RequestGroup](index.md) / [value](./value.md) + +# value + +`val value: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-request-id/-init-.md b/docs/api/net/com.drake.net.tag/-label/-request-id/-init-.md new file mode 100644 index 000000000..78dcd0c69 --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-request-id/-init-.md @@ -0,0 +1,5 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [RequestId](index.md) / [<init>](./-init-.md) + +# <init> + +`RequestId(value: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?)` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-request-id/index.md b/docs/api/net/com.drake.net.tag/-label/-request-id/index.md new file mode 100644 index 000000000..f0a67c7e6 --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-request-id/index.md @@ -0,0 +1,17 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [RequestId](./index.md) + +# RequestId + +`inline class RequestId` + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `RequestId(value: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?)` | + +### Properties + +| Name | Summary | +|---|---| +| [value](value.md) | `val value: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?` | diff --git a/docs/api/net/com.drake.net.tag/-label/-request-id/value.md b/docs/api/net/com.drake.net.tag/-label/-request-id/value.md new file mode 100644 index 000000000..bc56d8c88 --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-request-id/value.md @@ -0,0 +1,5 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [RequestId](index.md) / [value](./value.md) + +# value + +`val value: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-tag-map/-init-.md b/docs/api/net/com.drake.net.tag/-label/-tag-map/-init-.md new file mode 100644 index 000000000..1b694a85d --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-tag-map/-init-.md @@ -0,0 +1,5 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [TagMap](index.md) / [<init>](./-init-.md) + +# <init> + +`TagMap()` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-tag-map/index.md b/docs/api/net/com.drake.net.tag/-label/-tag-map/index.md new file mode 100644 index 000000000..f39cdf9d3 --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-tag-map/index.md @@ -0,0 +1,11 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [TagMap](./index.md) + +# TagMap + +`class TagMap` + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `TagMap()` | diff --git a/docs/api/net/com.drake.net.tag/-label/-upload-listeners/-init-.md b/docs/api/net/com.drake.net.tag/-label/-upload-listeners/-init-.md new file mode 100644 index 000000000..c7a11abab --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-upload-listeners/-init-.md @@ -0,0 +1,5 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [UploadListeners](index.md) / [<init>](./-init-.md) + +# <init> + +`UploadListeners()` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-label/-upload-listeners/index.md b/docs/api/net/com.drake.net.tag/-label/-upload-listeners/index.md new file mode 100644 index 000000000..7113935af --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/-upload-listeners/index.md @@ -0,0 +1,11 @@ +[net](../../../index.md) / [com.drake.net.tag](../../index.md) / [Label](../index.md) / [UploadListeners](./index.md) + +# UploadListeners + +`class UploadListeners : `[`ConcurrentLinkedQueue`](https://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html)`<`[`ProgressListener`](../../../com.drake.net.request/-progress-listener/index.md)`>` + +### Constructors + +| Name | Summary | +|---|---| +| [<init>](-init-.md) | `UploadListeners()` | diff --git a/docs/api/net/com.drake.net.tag/-label/index.md b/docs/api/net/com.drake.net.tag/-label/index.md new file mode 100644 index 000000000..a5da50cbf --- /dev/null +++ b/docs/api/net/com.drake.net.tag/-label/index.md @@ -0,0 +1,22 @@ +[net](../../index.md) / [com.drake.net.tag](../index.md) / [Label](./index.md) + +# Label + +`sealed class Label` + +### Types + +| Name | Summary | +|---|---| +| [DownloadFileConflictRename](-download-file-conflict-rename/index.md) | `class DownloadFileConflictRename` | +| [DownloadFileDir](-download-file-dir/index.md) | `class DownloadFileDir` | +| [DownloadFileMD5Verify](-download-file-m-d5-verify/index.md) | `class DownloadFileMD5Verify` | +| [DownloadFileName](-download-file-name/index.md) | `class DownloadFileName` | +| [DownloadFileNameDecode](-download-file-name-decode/index.md) | `class DownloadFileNameDecode` | +| [DownloadListeners](-download-listeners/index.md) | `class DownloadListeners : `[`ConcurrentLinkedQueue`](https://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html)`<`[`ProgressListener`](../../com.drake.net.request/-progress-listener/index.md)`>` | +| [DownloadTempFile](-download-temp-file/index.md) | `class DownloadTempFile` | +| [RequestGeneric](-request-generic/index.md) | `class RequestGeneric` | +| [RequestGroup](-request-group/index.md) | `class RequestGroup` | +| [RequestId](-request-id/index.md) | `class RequestId` | +| [TagMap](-tag-map/index.md) | `class TagMap` | +| [UploadListeners](-upload-listeners/index.md) | `class UploadListeners : `[`ConcurrentLinkedQueue`](https://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html)`<`[`ProgressListener`](../../com.drake.net.request/-progress-listener/index.md)`>` | diff --git a/docs/api/net/com.drake.net.tag/-r-e-q-u-e-s-t.md b/docs/api/net/com.drake.net.tag/-r-e-q-u-e-s-t.md deleted file mode 100644 index d3d013e4c..000000000 --- a/docs/api/net/com.drake.net.tag/-r-e-q-u-e-s-t.md +++ /dev/null @@ -1,8 +0,0 @@ -[net](../index.md) / [com.drake.net.tag](index.md) / [REQUEST](./-r-e-q-u-e-s-t.md) - -# REQUEST - -`object REQUEST : `[`TAG`](-t-a-g/index.md) - -请求参数打印标签 - diff --git a/docs/api/net/com.drake.net.tag/-r-e-s-p-o-n-s-e.md b/docs/api/net/com.drake.net.tag/-r-e-s-p-o-n-s-e.md deleted file mode 100644 index 6f80ed644..000000000 --- a/docs/api/net/com.drake.net.tag/-r-e-s-p-o-n-s-e.md +++ /dev/null @@ -1,8 +0,0 @@ -[net](../index.md) / [com.drake.net.tag](index.md) / [RESPONSE](./-r-e-s-p-o-n-s-e.md) - -# RESPONSE - -`object RESPONSE : `[`TAG`](-t-a-g/index.md) - -响应体打印标签 - diff --git a/docs/api/net/com.drake.net.tag/-t-a-g/-init-.md b/docs/api/net/com.drake.net.tag/-t-a-g/-init-.md deleted file mode 100644 index c56c04f67..000000000 --- a/docs/api/net/com.drake.net.tag/-t-a-g/-init-.md +++ /dev/null @@ -1,5 +0,0 @@ -[net](../../index.md) / [com.drake.net.tag](../index.md) / [TAG](index.md) / [<init>](./-init-.md) - -# <init> - -`TAG()` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-t-a-g/contains.md b/docs/api/net/com.drake.net.tag/-t-a-g/contains.md deleted file mode 100644 index 2787c93d8..000000000 --- a/docs/api/net/com.drake.net.tag/-t-a-g/contains.md +++ /dev/null @@ -1,5 +0,0 @@ -[net](../../index.md) / [com.drake.net.tag](../index.md) / [TAG](index.md) / [contains](./contains.md) - -# contains - -`operator fun contains(tag: @UnsafeVariance `[`TAG`](index.md)`): `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-t-a-g/get.md b/docs/api/net/com.drake.net.tag/-t-a-g/get.md deleted file mode 100644 index 5dd9bcd91..000000000 --- a/docs/api/net/com.drake.net.tag/-t-a-g/get.md +++ /dev/null @@ -1,5 +0,0 @@ -[net](../../index.md) / [com.drake.net.tag](../index.md) / [TAG](index.md) / [get](./get.md) - -# get - -`operator fun get(key: `[`KClass`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect/-k-class/index.html)`): `[`TAG`](index.md)`?` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-t-a-g/index.md b/docs/api/net/com.drake.net.tag/-t-a-g/index.md deleted file mode 100644 index 914bc1afd..000000000 --- a/docs/api/net/com.drake.net.tag/-t-a-g/index.md +++ /dev/null @@ -1,33 +0,0 @@ -[net](../../index.md) / [com.drake.net.tag](../index.md) / [TAG](./index.md) - -# TAG - -`abstract class TAG` - -### Constructors - -| Name | Summary | -|---|---| -| [<init>](-init-.md) | `TAG()` | - -### Properties - -| Name | Summary | -|---|---| -| [list](list.md) | `var list: `[`MutableList`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)`<`[`TAG`](./index.md)`>?` | - -### Functions - -| Name | Summary | -|---|---| -| [contains](contains.md) | `operator fun contains(tag: `[`TAG`](./index.md)`): `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | -| [get](get.md) | `operator fun get(key: `[`KClass`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect/-k-class/index.html)`): `[`TAG`](./index.md)`?` | -| [minus](minus.md) | `operator fun minus(tag: `[`TAG`](./index.md)`): `[`TAG`](./index.md) | -| [plus](plus.md) | `operator fun plus(tag: `[`TAG`](./index.md)`): `[`TAG`](./index.md) | - -### Inheritors - -| Name | Summary | -|---|---| -| [REQUEST](../-r-e-q-u-e-s-t.md) | 请求参数打印标签`object REQUEST : `[`TAG`](./index.md) | -| [RESPONSE](../-r-e-s-p-o-n-s-e.md) | 响应体打印标签`object RESPONSE : `[`TAG`](./index.md) | diff --git a/docs/api/net/com.drake.net.tag/-t-a-g/list.md b/docs/api/net/com.drake.net.tag/-t-a-g/list.md deleted file mode 100644 index 391396daf..000000000 --- a/docs/api/net/com.drake.net.tag/-t-a-g/list.md +++ /dev/null @@ -1,5 +0,0 @@ -[net](../../index.md) / [com.drake.net.tag](../index.md) / [TAG](index.md) / [list](./list.md) - -# list - -`protected var list: `[`MutableList`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)`<`[`TAG`](index.md)`>?` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-t-a-g/minus.md b/docs/api/net/com.drake.net.tag/-t-a-g/minus.md deleted file mode 100644 index 40ceababf..000000000 --- a/docs/api/net/com.drake.net.tag/-t-a-g/minus.md +++ /dev/null @@ -1,5 +0,0 @@ -[net](../../index.md) / [com.drake.net.tag](../index.md) / [TAG](index.md) / [minus](./minus.md) - -# minus - -`operator fun minus(tag: `[`TAG`](index.md)`): `[`TAG`](index.md) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/-t-a-g/plus.md b/docs/api/net/com.drake.net.tag/-t-a-g/plus.md deleted file mode 100644 index 946ff34f8..000000000 --- a/docs/api/net/com.drake.net.tag/-t-a-g/plus.md +++ /dev/null @@ -1,5 +0,0 @@ -[net](../../index.md) / [com.drake.net.tag](../index.md) / [TAG](index.md) / [plus](./plus.md) - -# plus - -`operator fun plus(tag: `[`TAG`](index.md)`): `[`TAG`](index.md) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.tag/index.md b/docs/api/net/com.drake.net.tag/index.md index 469c7ecb8..3a3060182 100644 --- a/docs/api/net/com.drake.net.tag/index.md +++ b/docs/api/net/com.drake.net.tag/index.md @@ -6,6 +6,4 @@ | Name | Summary | |---|---| -| [REQUEST](-r-e-q-u-e-s-t.md) | 请求参数打印标签`object REQUEST : `[`TAG`](-t-a-g/index.md) | -| [RESPONSE](-r-e-s-p-o-n-s-e.md) | 响应体打印标签`object RESPONSE : `[`TAG`](-t-a-g/index.md) | -| [TAG](-t-a-g/index.md) | `abstract class TAG` | +| [Label](-label/index.md) | `sealed class Label` | diff --git a/docs/api/net/com.drake.net.time/-interval/-init-.md b/docs/api/net/com.drake.net.time/-interval/-init-.md index edb4dba36..0671e9901 100644 --- a/docs/api/net/com.drake.net.time/-interval/-init-.md +++ b/docs/api/net/com.drake.net.time/-interval/-init-.md @@ -25,10 +25,10 @@ `end` - 结束值 -`period` - 事件间隔 +`period` - 计时器间隔 -`unit` - 事件单位 +`unit` - 计时器单位 -`initialDelay` - 第一次事件的间隔时间 +`initialDelay` - 第一次事件的间隔时间, 默认0 -`start` - 开始值, 当[start](start.md)]比[end](end.md)值大, 且end不等于-1时, 即为倒计时 \ No newline at end of file +`start` - 开始值, 当[start](start.md)]比[end](end.md)值大, 且end不等于-1时, 即为倒计时, 反之正计时 \ No newline at end of file diff --git a/docs/api/net/com.drake.net.time/-interval/finish.md b/docs/api/net/com.drake.net.time/-interval/finish.md index 0b03a2417..89ea8a6c6 100644 --- a/docs/api/net/com.drake.net.time/-interval/finish.md +++ b/docs/api/net/com.drake.net.time/-interval/finish.md @@ -4,5 +4,5 @@ `fun finish(block: (`[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`Interval`](index.md) -轮循器完成 +轮循器完成时回调该函数 diff --git a/docs/api/net/com.drake.net.time/-interval/index.md b/docs/api/net/com.drake.net.time/-interval/index.md index 7f49c6c17..9a2bd16da 100644 --- a/docs/api/net/com.drake.net.time/-interval/index.md +++ b/docs/api/net/com.drake.net.time/-interval/index.md @@ -25,13 +25,13 @@ `end` - 结束值 -`period` - 事件间隔 +`period` - 计时器间隔 -`unit` - 事件单位 +`unit` - 计时器单位 -`initialDelay` - 第一次事件的间隔时间 +`initialDelay` - 第一次事件的间隔时间, 默认0 -`start` - 开始值, 当[start](start.md)]比[end](end.md)值大, 且end不等于-1时, 即为倒计时 +`start` - 开始值, 当[start](start.md)]比[end](end.md)值大, 且end不等于-1时, 即为倒计时, 反之正计时 ### Constructors @@ -51,12 +51,12 @@ | Name | Summary | |---|---| -| [finish](finish.md) | 轮循器完成`fun finish(block: (`[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`Interval`](./index.md) | +| [finish](finish.md) | 轮循器完成时回调该函数`fun finish(block: (`[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`Interval`](./index.md) | | [life](life.md) | 绑定生命周期, 在指定生命周期发生时取消轮循器`fun life(lifecycleOwner: LifecycleOwner, lifeEvent: Event = Lifecycle.Event.ON_STOP): `[`Interval`](./index.md) | | [pause](pause.md) | 暂停`fun pause(): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | | [reset](reset.md) | 重置`fun reset(): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | -| [resume](resume.md) | 继续`fun resume(): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [resume](resume.md) | 继续 要求轮循器为暂停状态[IntervalStatus.STATE_PAUSE](../-interval-status/-s-t-a-t-e_-p-a-u-s-e.md), 否则无效`fun resume(): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | | [start](start.md) | 开始`fun start(): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | | [stop](stop.md) | 停止`fun stop(): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | -| [subscribe](subscribe.md) | 订阅轮循器`fun subscribe(block: (`[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`Interval`](./index.md) | -| [switch](switch.md) | 开关`fun switch(): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [subscribe](subscribe.md) | 订阅轮循器 每次轮循器计时都会调用该回调函数 轮循器完成时会同时触发回调[block](subscribe.md#com.drake.net.time.Interval$subscribe(kotlin.Function1((kotlin.Long, kotlin.Unit)))/block)和[finish](finish.md)`fun subscribe(block: (`[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`Interval`](./index.md) | +| [switch](switch.md) | 切换轮循器开始或结束`fun switch(): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | diff --git a/docs/api/net/com.drake.net.time/-interval/life.md b/docs/api/net/com.drake.net.time/-interval/life.md index 6185f4c4e..57729f8b4 100644 --- a/docs/api/net/com.drake.net.time/-interval/life.md +++ b/docs/api/net/com.drake.net.time/-interval/life.md @@ -8,4 +8,13 @@ ### Parameters -`lifecycleOwner` - 默认在销毁时取消轮循器 \ No newline at end of file +`lifecycleOwner` - 默认在销毁时取消轮循器 + +`lifeEvent` - + +销毁的时机, 默认为 ON_STOP 界面停止时停止轮循器 + + + +Fragment的显示/隐藏不会调用onDestroy, 故轮循器默认是在ON_STOP停止, 如果你设置ON_DESTORY请考虑Fragment的情况下 + diff --git a/docs/api/net/com.drake.net.time/-interval/resume.md b/docs/api/net/com.drake.net.time/-interval/resume.md index e520be810..124eec4a4 100644 --- a/docs/api/net/com.drake.net.time/-interval/resume.md +++ b/docs/api/net/com.drake.net.time/-interval/resume.md @@ -5,4 +5,5 @@ `fun resume(): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) 继续 +要求轮循器为暂停状态[IntervalStatus.STATE_PAUSE](../-interval-status/-s-t-a-t-e_-p-a-u-s-e.md), 否则无效 diff --git a/docs/api/net/com.drake.net.time/-interval/subscribe.md b/docs/api/net/com.drake.net.time/-interval/subscribe.md index 6ea969dcc..2b71b5ef7 100644 --- a/docs/api/net/com.drake.net.time/-interval/subscribe.md +++ b/docs/api/net/com.drake.net.time/-interval/subscribe.md @@ -5,4 +5,6 @@ `fun subscribe(block: (`[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`Interval`](index.md) 订阅轮循器 +每次轮循器计时都会调用该回调函数 +轮循器完成时会同时触发回调[block](subscribe.md#com.drake.net.time.Interval$subscribe(kotlin.Function1((kotlin.Long, kotlin.Unit)))/block)和[finish](finish.md) diff --git a/docs/api/net/com.drake.net.time/-interval/switch.md b/docs/api/net/com.drake.net.time/-interval/switch.md index 5f4c5b4b0..09963156d 100644 --- a/docs/api/net/com.drake.net.time/-interval/switch.md +++ b/docs/api/net/com.drake.net.time/-interval/switch.md @@ -4,5 +4,5 @@ `fun switch(): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) -开关 +切换轮循器开始或结束 diff --git a/docs/api/net/com.drake.net.utils/-saved-view-model/-init-.md b/docs/api/net/com.drake.net.utils/-saved-view-model/-init-.md deleted file mode 100644 index 21bfaa1ea..000000000 --- a/docs/api/net/com.drake.net.utils/-saved-view-model/-init-.md +++ /dev/null @@ -1,8 +0,0 @@ -[net](../../index.md) / [com.drake.net.utils](../index.md) / [SavedViewModel](index.md) / [<init>](./-init-.md) - -# <init> - -`SavedViewModel(saved: SavedStateHandle)` - -继承这个类可以快速创建具备saveInstance的ViewModel - diff --git a/docs/api/net/com.drake.net.utils/-saved-view-model/index.md b/docs/api/net/com.drake.net.utils/-saved-view-model/index.md deleted file mode 100644 index 063a434cf..000000000 --- a/docs/api/net/com.drake.net.utils/-saved-view-model/index.md +++ /dev/null @@ -1,19 +0,0 @@ -[net](../../index.md) / [com.drake.net.utils](../index.md) / [SavedViewModel](./index.md) - -# SavedViewModel - -`open class SavedViewModel : ViewModel` - -继承这个类可以快速创建具备saveInstance的ViewModel - -### Constructors - -| Name | Summary | -|---|---| -| [<init>](-init-.md) | 继承这个类可以快速创建具备saveInstance的ViewModel`SavedViewModel(saved: SavedStateHandle)` | - -### Properties - -| Name | Summary | -|---|---| -| [saved](saved.md) | `var saved: SavedStateHandle` | diff --git a/docs/api/net/com.drake.net.utils/-saved-view-model/saved.md b/docs/api/net/com.drake.net.utils/-saved-view-model/saved.md deleted file mode 100644 index 3ce621a8c..000000000 --- a/docs/api/net/com.drake.net.utils/-saved-view-model/saved.md +++ /dev/null @@ -1,5 +0,0 @@ -[net](../../index.md) / [com.drake.net.utils](../index.md) / [SavedViewModel](index.md) / [saved](./saved.md) - -# saved - -`var saved: SavedStateHandle` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.utils/android.database.-cursor/foreach.md b/docs/api/net/com.drake.net.utils/android.database.-cursor/foreach.md deleted file mode 100644 index 95b62c9af..000000000 --- a/docs/api/net/com.drake.net.utils/android.database.-cursor/foreach.md +++ /dev/null @@ -1,8 +0,0 @@ -[net](../../index.md) / [com.drake.net.utils](../index.md) / [android.database.Cursor](index.md) / [foreach](./foreach.md) - -# foreach - -`fun `[`Cursor`](https://developer.android.com/reference/android/database/Cursor.html)`.foreach(block: `[`Cursor`](https://developer.android.com/reference/android/database/Cursor.html)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) - -方便迭代Cursor, 针对数据库的便携函数 - diff --git a/docs/api/net/com.drake.net.utils/android.database.-cursor/index.md b/docs/api/net/com.drake.net.utils/android.database.-cursor/index.md deleted file mode 100644 index b4841fb7d..000000000 --- a/docs/api/net/com.drake.net.utils/android.database.-cursor/index.md +++ /dev/null @@ -1,7 +0,0 @@ -[net](../../index.md) / [com.drake.net.utils](../index.md) / [android.database.Cursor](./index.md) - -### Extensions for android.database.Cursor - -| Name | Summary | -|---|---| -| [foreach](foreach.md) | 方便迭代Cursor, 针对数据库的便携函数`fun `[`Cursor`](https://developer.android.com/reference/android/database/Cursor.html)`.foreach(block: `[`Cursor`](https://developer.android.com/reference/android/database/Cursor.html)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | diff --git a/docs/api/net/com.drake.net.utils/android.widget.-edit-text/debounce.md b/docs/api/net/com.drake.net.utils/android.widget.-edit-text/debounce.md new file mode 100644 index 000000000..9720e7477 --- /dev/null +++ b/docs/api/net/com.drake.net.utils/android.widget.-edit-text/debounce.md @@ -0,0 +1,11 @@ +[net](../../index.md) / [com.drake.net.utils](../index.md) / [android.widget.EditText](index.md) / [debounce](./debounce.md) + +# debounce + +`fun `[`EditText`](https://developer.android.com/reference/android/widget/EditText.html)`.debounce(timeoutMillis: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)` = 800): Flow<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>` + +为EditText的输入框文本变化启用节流阀, 即超过指定时间后(默认800毫秒)的输入框文本变化事件[TextWatcher.onTextChanged](https://developer.android.com/reference/android/text/TextWatcher.html#onTextChanged(java.lang.CharSequence, int, int, int))会被下游收集到 + +### Parameters + +`timeoutMillis` - 节流阀超时时间/单位毫秒, 默认值为800 \ No newline at end of file diff --git a/docs/api/net/com.drake.net.utils/android.widget.-edit-text/index.md b/docs/api/net/com.drake.net.utils/android.widget.-edit-text/index.md new file mode 100644 index 000000000..72958c2b1 --- /dev/null +++ b/docs/api/net/com.drake.net.utils/android.widget.-edit-text/index.md @@ -0,0 +1,7 @@ +[net](../../index.md) / [com.drake.net.utils](../index.md) / [android.widget.EditText](./index.md) + +### Extensions for android.widget.EditText + +| Name | Summary | +|---|---| +| [debounce](debounce.md) | 为EditText的输入框文本变化启用节流阀, 即超过指定时间后(默认800毫秒)的输入框文本变化事件[TextWatcher.onTextChanged](https://developer.android.com/reference/android/text/TextWatcher.html#onTextChanged(java.lang.CharSequence, int, int, int))会被下游收集到`fun `[`EditText`](https://developer.android.com/reference/android/widget/EditText.html)`.debounce(timeoutMillis: `[`Long`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)` = 800): Flow<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>` | diff --git a/docs/api/net/com.drake.net.utils/androidx.fragment.app.-fragment-activity/get-saved-model.md b/docs/api/net/com.drake.net.utils/androidx.fragment.app.-fragment-activity/get-saved-model.md deleted file mode 100644 index 515274ce6..000000000 --- a/docs/api/net/com.drake.net.utils/androidx.fragment.app.-fragment-activity/get-saved-model.md +++ /dev/null @@ -1,8 +0,0 @@ -[net](../../index.md) / [com.drake.net.utils](../index.md) / [androidx.fragment.app.FragmentActivity](index.md) / [getSavedModel](./get-saved-model.md) - -# getSavedModel - -`fun FragmentActivity.getSavedModel(): M` - -返回当前组件指定的SavedViewModel - diff --git a/docs/api/net/com.drake.net.utils/androidx.fragment.app.-fragment-activity/index.md b/docs/api/net/com.drake.net.utils/androidx.fragment.app.-fragment-activity/index.md index 58345ef6b..b67f03e8c 100644 --- a/docs/api/net/com.drake.net.utils/androidx.fragment.app.-fragment-activity/index.md +++ b/docs/api/net/com.drake.net.utils/androidx.fragment.app.-fragment-activity/index.md @@ -4,5 +4,4 @@ | Name | Summary | |---|---| -| [getSavedModel](get-saved-model.md) | 返回当前组件指定的SavedViewModel`fun FragmentActivity.getSavedModel(): M` | | [scopeDialog](scope-dialog.md) | 作用域开始时自动显示加载对话框, 结束时自动关闭加载对话框 可以设置全局对话框 [com.drake.net.NetConfig.onDialog](../../com.drake.net/-net-config/on-dialog.md)`fun FragmentActivity.scopeDialog(dialog: `[`Dialog`](https://developer.android.com/reference/android/app/Dialog.html)`? = null, cancelable: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = true, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`NetCoroutineScope`](../../com.drake.net.scope/-net-coroutine-scope/index.md) | diff --git a/docs/api/net/com.drake.net.utils/androidx.fragment.app.-fragment/get-saved-model.md b/docs/api/net/com.drake.net.utils/androidx.fragment.app.-fragment/get-saved-model.md deleted file mode 100644 index 5398a78ba..000000000 --- a/docs/api/net/com.drake.net.utils/androidx.fragment.app.-fragment/get-saved-model.md +++ /dev/null @@ -1,8 +0,0 @@ -[net](../../index.md) / [com.drake.net.utils](../index.md) / [androidx.fragment.app.Fragment](index.md) / [getSavedModel](./get-saved-model.md) - -# getSavedModel - -`fun Fragment.getSavedModel(): M` - -返回当前组件指定的SavedViewModel - diff --git a/docs/api/net/com.drake.net.utils/androidx.fragment.app.-fragment/index.md b/docs/api/net/com.drake.net.utils/androidx.fragment.app.-fragment/index.md index c2c9afb11..fd3baf5d3 100644 --- a/docs/api/net/com.drake.net.utils/androidx.fragment.app.-fragment/index.md +++ b/docs/api/net/com.drake.net.utils/androidx.fragment.app.-fragment/index.md @@ -4,7 +4,6 @@ | Name | Summary | |---|---| -| [getSavedModel](get-saved-model.md) | 返回当前组件指定的SavedViewModel`fun Fragment.getSavedModel(): M` | | [scopeDialog](scope-dialog.md) | `fun Fragment.scopeDialog(dialog: `[`Dialog`](https://developer.android.com/reference/android/app/Dialog.html)`? = null, cancelable: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = true, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`NetCoroutineScope`](../../com.drake.net.scope/-net-coroutine-scope/index.md) | | [scopeLife](scope-life.md) | `fun Fragment.scopeLife(lifeEvent: Event = Lifecycle.Event.ON_STOP, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`AndroidScope`](../../com.drake.net.scope/-android-scope/index.md) | -| [scopeNetLife](scope-net-life.md) | Fragment应当在[Lifecycle.Event.ON_STOP](#)时就取消作用域, 避免[Fragment.onDestroyView](#)导致引用空视图`fun Fragment.scopeNetLife(lifeEvent: Event = Lifecycle.Event.ON_STOP, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`NetCoroutineScope`](../../com.drake.net.scope/-net-coroutine-scope/index.md) | +| [scopeNetLife](scope-net-life.md) | 和上述函数功能相同, 只是接受者为Fragment`fun Fragment.scopeNetLife(lifeEvent: Event = Lifecycle.Event.ON_STOP, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`NetCoroutineScope`](../../com.drake.net.scope/-net-coroutine-scope/index.md) | diff --git a/docs/api/net/com.drake.net.utils/androidx.fragment.app.-fragment/scope-net-life.md b/docs/api/net/com.drake.net.utils/androidx.fragment.app.-fragment/scope-net-life.md index e753608d8..7cd4e1c9c 100644 --- a/docs/api/net/com.drake.net.utils/androidx.fragment.app.-fragment/scope-net-life.md +++ b/docs/api/net/com.drake.net.utils/androidx.fragment.app.-fragment/scope-net-life.md @@ -4,5 +4,7 @@ `fun Fragment.scopeNetLife(lifeEvent: Event = Lifecycle.Event.ON_STOP, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`NetCoroutineScope`](../../com.drake.net.scope/-net-coroutine-scope/index.md) +和上述函数功能相同, 只是接受者为Fragment + Fragment应当在[Lifecycle.Event.ON_STOP](#)时就取消作用域, 避免[Fragment.onDestroyView](#)导致引用空视图 diff --git a/docs/api/net/com.drake.net.utils/androidx.lifecycle.-lifecycle-owner/index.md b/docs/api/net/com.drake.net.utils/androidx.lifecycle.-lifecycle-owner/index.md deleted file mode 100644 index c816124fd..000000000 --- a/docs/api/net/com.drake.net.utils/androidx.lifecycle.-lifecycle-owner/index.md +++ /dev/null @@ -1,9 +0,0 @@ -[net](../../index.md) / [com.drake.net.utils](../index.md) / [androidx.lifecycle.LifecycleOwner](./index.md) - -### Extensions for androidx.lifecycle.LifecycleOwner - -| Name | Summary | -|---|---| -| [observe](observe.md) | 快速创建LiveData的观察者`fun LifecycleOwner.observe(liveData: LiveData?, block: M?.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | -| [scopeLife](scope-life.md) | `fun LifecycleOwner.scopeLife(lifeEvent: Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`AndroidScope`](../../com.drake.net.scope/-android-scope/index.md) | -| [scopeNetLife](scope-net-life.md) | `fun LifecycleOwner.scopeNetLife(lifeEvent: Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`NetCoroutineScope`](../../com.drake.net.scope/-net-coroutine-scope/index.md) | diff --git a/docs/api/net/com.drake.net.utils/androidx.lifecycle.-lifecycle-owner/observe.md b/docs/api/net/com.drake.net.utils/androidx.lifecycle.-lifecycle-owner/observe.md deleted file mode 100644 index 904c58bc8..000000000 --- a/docs/api/net/com.drake.net.utils/androidx.lifecycle.-lifecycle-owner/observe.md +++ /dev/null @@ -1,8 +0,0 @@ -[net](../../index.md) / [com.drake.net.utils](../index.md) / [androidx.lifecycle.LifecycleOwner](index.md) / [observe](./observe.md) - -# observe - -`fun LifecycleOwner.observe(liveData: LiveData?, block: M?.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) - -快速创建LiveData的观察者 - diff --git a/docs/api/net/com.drake.net.utils/androidx.lifecycle.-lifecycle-owner/scope-net-life.md b/docs/api/net/com.drake.net.utils/androidx.lifecycle.-lifecycle-owner/scope-net-life.md deleted file mode 100644 index 902878edf..000000000 --- a/docs/api/net/com.drake.net.utils/androidx.lifecycle.-lifecycle-owner/scope-net-life.md +++ /dev/null @@ -1,5 +0,0 @@ -[net](../../index.md) / [com.drake.net.utils](../index.md) / [androidx.lifecycle.LifecycleOwner](index.md) / [scopeNetLife](./scope-net-life.md) - -# scopeNetLife - -`fun LifecycleOwner.scopeNetLife(lifeEvent: Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`NetCoroutineScope`](../../com.drake.net.scope/-net-coroutine-scope/index.md) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.utils/androidx.lifecycle.-view-model-store-owner/get-view-model.md b/docs/api/net/com.drake.net.utils/androidx.lifecycle.-view-model-store-owner/get-view-model.md deleted file mode 100644 index 0e2d83649..000000000 --- a/docs/api/net/com.drake.net.utils/androidx.lifecycle.-view-model-store-owner/get-view-model.md +++ /dev/null @@ -1,8 +0,0 @@ -[net](../../index.md) / [com.drake.net.utils](../index.md) / [androidx.lifecycle.ViewModelStoreOwner](index.md) / [getViewModel](./get-view-model.md) - -# getViewModel - -`fun ViewModelStoreOwner.getViewModel(): M` - -返回当前组件指定的ViewModel - diff --git a/docs/api/net/com.drake.net.utils/androidx.lifecycle.-view-model-store-owner/index.md b/docs/api/net/com.drake.net.utils/androidx.lifecycle.-view-model-store-owner/index.md deleted file mode 100644 index 59e78da64..000000000 --- a/docs/api/net/com.drake.net.utils/androidx.lifecycle.-view-model-store-owner/index.md +++ /dev/null @@ -1,7 +0,0 @@ -[net](../../index.md) / [com.drake.net.utils](../index.md) / [androidx.lifecycle.ViewModelStoreOwner](./index.md) - -### Extensions for androidx.lifecycle.ViewModelStoreOwner - -| Name | Summary | -|---|---| -| [getViewModel](get-view-model.md) | 返回当前组件指定的ViewModel`fun ViewModelStoreOwner.getViewModel(): M` | diff --git a/docs/api/net/com.drake.net.utils/index.md b/docs/api/net/com.drake.net.utils/index.md index dd061a4d1..7e0e7c74c 100644 --- a/docs/api/net/com.drake.net.utils/index.md +++ b/docs/api/net/com.drake.net.utils/index.md @@ -2,33 +2,32 @@ ## Package com.drake.net.utils -### Types - -| Name | Summary | -|---|---| -| [SavedViewModel](-saved-view-model/index.md) | 继承这个类可以快速创建具备saveInstance的ViewModel`open class SavedViewModel : ViewModel` | - ### Extensions for External Classes | Name | Summary | |---|---| -| [android.database.Cursor](android.database.-cursor/index.md) | | +| [android.widget.EditText](android.widget.-edit-text/index.md) | | | [androidx.fragment.app.Fragment](androidx.fragment.app.-fragment/index.md) | | | [androidx.fragment.app.FragmentActivity](androidx.fragment.app.-fragment-activity/index.md) | | -| [androidx.lifecycle.LifecycleOwner](androidx.lifecycle.-lifecycle-owner/index.md) | | -| [androidx.lifecycle.ViewModelStoreOwner](androidx.lifecycle.-view-model-store-owner/index.md) | | | [com.drake.brv.PageRefreshLayout](com.drake.brv.-page-refresh-layout/index.md) | | | [com.drake.statelayout.StateLayout](com.drake.statelayout.-state-layout/index.md) | | +| [java.io.File](java.io.-file/index.md) | | +| [kotlin.String](kotlin.-string/index.md) | | | [kotlinx.coroutines.CoroutineScope](kotlinx.coroutines.-coroutine-scope/index.md) | | | [kotlinx.coroutines.flow.Flow](kotlinx.coroutines.flow.-flow/index.md) | | +| [okhttp3.OkHttpClient](okhttp3.-ok-http-client/index.md) | | +| [okhttp3.OkHttpClient.Builder](okhttp3.-ok-http-client.-builder/index.md) | | ### Functions | Name | Summary | |---|---| +| [lazyField](lazy-field.md) | 延迟初始化 线程安全 等效于[lazy](#), 但是可以获取委托字段属性`fun T.lazyField(block: T.(`[`KProperty`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect/-k-property/index.html)`<*>) -> V): `[`ReadWriteProperty`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.properties/-read-write-property/index.html)`` | | [runMain](run-main.md) | 在主线程运行`fun runMain(block: () -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | | [scope](scope.md) | 异步作用域`fun scope(dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`AndroidScope`](../com.drake.net.scope/-android-scope/index.md) | -| [scopeNet](scope-net.md) | 网络请求的异步作用域 自动显示错误信息吐司`fun scopeNet(dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`NetCoroutineScope`](../com.drake.net.scope/-net-coroutine-scope/index.md) | +| [scopeLife](scope-life.md) | `fun LifecycleOwner.scopeLife(lifeEvent: Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`AndroidScope`](../com.drake.net.scope/-android-scope/index.md) | +| [scopeNet](scope-net.md) | 该函数比[scope](kotlinx.coroutines.flow.-flow/scope.md)多了以下功能`fun scopeNet(dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`NetCoroutineScope`](../com.drake.net.scope/-net-coroutine-scope/index.md) | +| [scopeNetLife](scope-net-life.md) | 该函数比scopeNet多了自动取消作用域功能`fun LifecycleOwner.scopeNetLife(lifeEvent: Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`NetCoroutineScope`](../com.drake.net.scope/-net-coroutine-scope/index.md) | | [withDefault](with-default.md) | 切换到默认调度器`suspend fun withDefault(block: suspend CoroutineScope.() -> T): T` | | [withIO](with-i-o.md) | 切换到IO程调度器`suspend fun withIO(block: suspend CoroutineScope.() -> T): T` | | [withMain](with-main.md) | 切换到主线程调度器`suspend fun withMain(block: suspend CoroutineScope.() -> T): T` | diff --git a/docs/api/net/com.drake.net.utils/java.io.-file/index.md b/docs/api/net/com.drake.net.utils/java.io.-file/index.md new file mode 100644 index 000000000..82a481c57 --- /dev/null +++ b/docs/api/net/com.drake.net.utils/java.io.-file/index.md @@ -0,0 +1,7 @@ +[net](../../index.md) / [com.drake.net.utils](../index.md) / [java.io.File](./index.md) + +### Extensions for java.io.File + +| Name | Summary | +|---|---| +| [md5](md5.md) | 返回文件的MD5值`fun `[`File`](https://docs.oracle.com/javase/6/docs/api/java/io/File.html)`?.md5(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?` | diff --git a/docs/api/net/com.drake.net.utils/java.io.-file/md5.md b/docs/api/net/com.drake.net.utils/java.io.-file/md5.md new file mode 100644 index 000000000..7e1317740 --- /dev/null +++ b/docs/api/net/com.drake.net.utils/java.io.-file/md5.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.utils](../index.md) / [java.io.File](index.md) / [md5](./md5.md) + +# md5 + +`fun `[`File`](https://docs.oracle.com/javase/6/docs/api/java/io/File.html)`?.md5(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?` + +返回文件的MD5值 + diff --git a/docs/api/net/com.drake.net.utils/kotlin.-string/index.md b/docs/api/net/com.drake.net.utils/kotlin.-string/index.md new file mode 100644 index 000000000..8e4b1dc87 --- /dev/null +++ b/docs/api/net/com.drake.net.utils/kotlin.-string/index.md @@ -0,0 +1,7 @@ +[net](../../index.md) / [com.drake.net.utils](../index.md) / [kotlin.String](./index.md) + +### Extensions for kotlin.String + +| Name | Summary | +|---|---| +| [isValid](is-valid.md) | `fun `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?.isValid(block: (`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)
`val `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?.isValid: ` | diff --git a/docs/api/net/com.drake.net.utils/kotlin.-string/is-valid.md b/docs/api/net/com.drake.net.utils/kotlin.-string/is-valid.md new file mode 100644 index 000000000..c8776e032 --- /dev/null +++ b/docs/api/net/com.drake.net.utils/kotlin.-string/is-valid.md @@ -0,0 +1,6 @@ +[net](../../index.md) / [com.drake.net.utils](../index.md) / [kotlin.String](index.md) / [isValid](./is-valid.md) + +# isValid + +`inline fun `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?.isValid(block: (`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) +`inline val `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?.isValid: ` \ No newline at end of file diff --git a/docs/api/net/com.drake.net.utils/kotlinx.coroutines.-coroutine-scope/fastest.md b/docs/api/net/com.drake.net.utils/kotlinx.coroutines.-coroutine-scope/fastest.md index 7ce44ca31..8dd035757 100644 --- a/docs/api/net/com.drake.net.utils/kotlinx.coroutines.-coroutine-scope/fastest.md +++ b/docs/api/net/com.drake.net.utils/kotlinx.coroutines.-coroutine-scope/fastest.md @@ -2,35 +2,25 @@ # fastest -`suspend fun CoroutineScope.fastest(vararg deferredArray: Deferred): T` -`suspend fun CoroutineScope.fastest(deferredArray: `[`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)`>): T` +`suspend fun CoroutineScope.fastest(listDeferred: `[`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)`>, group: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null): T` -该函数将选择[deferredArray](fastest.md#com.drake.net.utils$fastest(kotlinx.coroutines.CoroutineScope, kotlin.Array((kotlinx.coroutines.Deferred((com.drake.net.utils.fastest.T)))))/deferredArray)中的Deferred执行[Deferred.await](#), 然后将返回最快的结果 +该函数将选择[listDeferred](fastest.md#com.drake.net.utils$fastest(kotlinx.coroutines.CoroutineScope, kotlin.collections.List((kotlinx.coroutines.Deferred((com.drake.net.utils.fastest.T)))), kotlin.Any)/listDeferred)中的Deferred执行[Deferred.await](#), 然后将返回最快的结果 执行过程中的异常将被忽略, 如果全部抛出异常则将抛出最后一个Deferred的异常 ### Parameters -`deferredArray` - 一系列并发任务`suspend fun CoroutineScope.fastest(vararg deferredArray: `[`DeferredTransform`](../../com.drake.net.transform/-deferred-transform/index.md)`): R` +`group` - 指定该值将在成功返回结果后取消掉对应uid的网络请求 -该函数将选择[deferredArray](fastest.md#com.drake.net.utils$fastest(kotlinx.coroutines.CoroutineScope, kotlin.Array((com.drake.net.transform.DeferredTransform((com.drake.net.utils.fastest.T, com.drake.net.utils.fastest.R)))))/deferredArray)中的Deferred执行[Deferred.await](#), 然后将返回最快的结果 -执行过程中的异常将被忽略, 如果全部抛出异常则将抛出最后一个Deferred的异常 - -### Parameters - -`deferredArray` - 一系列并发任务 - -**See Also** - -[DeferredTransform](../../com.drake.net.transform/-deferred-transform/index.md) +`listDeferred` - 一系列并发任务`@JvmName("fastestTransform") suspend fun CoroutineScope.fastest(listDeferred: `[`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)`<`[`DeferredTransform`](../../com.drake.net.transform/-deferred-transform/index.md)`>?, group: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null): R` -`@JvmName("fastestTransform") suspend fun CoroutineScope.fastest(deferredList: `[`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)`<`[`DeferredTransform`](../../com.drake.net.transform/-deferred-transform/index.md)`>): R` - -该函数将选择[deferredList](fastest.md#com.drake.net.utils$fastest(kotlinx.coroutines.CoroutineScope, kotlin.collections.List((com.drake.net.transform.DeferredTransform((com.drake.net.utils.fastest.T, com.drake.net.utils.fastest.R)))))/deferredList)中的Deferred执行[Deferred.await](#), 然后将返回最快的结果 +该函数将选择[listDeferred](fastest.md#com.drake.net.utils$fastest(kotlinx.coroutines.CoroutineScope, kotlin.collections.List((com.drake.net.transform.DeferredTransform((com.drake.net.utils.fastest.T, com.drake.net.utils.fastest.R)))), kotlin.Any)/listDeferred)中的Deferred执行[Deferred.await](#), 然后将返回最快的结果 执行过程中的异常将被忽略, 如果全部抛出异常则将抛出最后一个Deferred的异常 ### Parameters -`deferredList` - 一系列并发任务 +`group` - 指定该值将在成功返回结果后取消掉对应uid的网络请求 + +`listDeferred` - 一系列并发任务 **See Also** diff --git a/docs/api/net/com.drake.net.utils/kotlinx.coroutines.-coroutine-scope/index.md b/docs/api/net/com.drake.net.utils/kotlinx.coroutines.-coroutine-scope/index.md index 89b52a83a..14a687a08 100644 --- a/docs/api/net/com.drake.net.utils/kotlinx.coroutines.-coroutine-scope/index.md +++ b/docs/api/net/com.drake.net.utils/kotlinx.coroutines.-coroutine-scope/index.md @@ -4,4 +4,4 @@ | Name | Summary | |---|---| -| [fastest](fastest.md) | 该函数将选择[deferredArray](fastest.md#com.drake.net.utils$fastest(kotlinx.coroutines.CoroutineScope, kotlin.Array((kotlinx.coroutines.Deferred((com.drake.net.utils.fastest.T)))))/deferredArray)中的Deferred执行[Deferred.await](#), 然后将返回最快的结果 执行过程中的异常将被忽略, 如果全部抛出异常则将抛出最后一个Deferred的异常`suspend fun CoroutineScope.fastest(vararg deferredArray: Deferred): T`
`suspend fun CoroutineScope.fastest(deferredArray: `[`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)`>): T`
`suspend fun CoroutineScope.fastest(vararg deferredArray: `[`DeferredTransform`](../../com.drake.net.transform/-deferred-transform/index.md)`): R`
该函数将选择[deferredList](fastest.md#com.drake.net.utils$fastest(kotlinx.coroutines.CoroutineScope, kotlin.collections.List((com.drake.net.transform.DeferredTransform((com.drake.net.utils.fastest.T, com.drake.net.utils.fastest.R)))))/deferredList)中的Deferred执行[Deferred.await](#), 然后将返回最快的结果 执行过程中的异常将被忽略, 如果全部抛出异常则将抛出最后一个Deferred的异常`suspend fun CoroutineScope.fastest(deferredList: `[`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)`<`[`DeferredTransform`](../../com.drake.net.transform/-deferred-transform/index.md)`>): R` | +| [fastest](fastest.md) | 该函数将选择[listDeferred](fastest.md#com.drake.net.utils$fastest(kotlinx.coroutines.CoroutineScope, kotlin.collections.List((kotlinx.coroutines.Deferred((com.drake.net.utils.fastest.T)))), kotlin.Any)/listDeferred)中的Deferred执行[Deferred.await](#), 然后将返回最快的结果 执行过程中的异常将被忽略, 如果全部抛出异常则将抛出最后一个Deferred的异常`suspend fun CoroutineScope.fastest(listDeferred: `[`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)`>, group: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null): T`
`suspend fun CoroutineScope.fastest(listDeferred: `[`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)`<`[`DeferredTransform`](../../com.drake.net.transform/-deferred-transform/index.md)`>?, group: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null): R` | diff --git a/docs/api/net/com.drake.net.utils/kotlinx.coroutines.flow.-flow/index.md b/docs/api/net/com.drake.net.utils/kotlinx.coroutines.flow.-flow/index.md index 1ee97cc4a..37309c4f7 100644 --- a/docs/api/net/com.drake.net.utils/kotlinx.coroutines.flow.-flow/index.md +++ b/docs/api/net/com.drake.net.utils/kotlinx.coroutines.flow.-flow/index.md @@ -4,5 +4,5 @@ | Name | Summary | |---|---| -| [listen](listen.md) | 收集Flow结果并过滤重复结果`fun Flow<`[`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)`>.listen(lifecycleOwner: LifecycleOwner? = null, lifeEvent: Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: (`[`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)`) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`AndroidScope`](../../com.drake.net.scope/-android-scope/index.md) | -| [scope](scope.md) | Flow直接创建作用域`fun Flow.scope(owner: LifecycleOwner? = null, event: Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, action: suspend (value: T) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`AndroidScope`](../../com.drake.net.scope/-android-scope/index.md) | +| [listen](listen.md) | 收集Flow结果并过滤重复结果`fun Flow.listen(owner: LifecycleOwner? = null, event: Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, action: suspend CoroutineScope.(value: T) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`AndroidScope`](../../com.drake.net.scope/-android-scope/index.md) | +| [scope](scope.md) | Flow直接创建作用域`fun Flow.scope(owner: LifecycleOwner? = null, event: Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, action: suspend CoroutineScope.(value: T) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`AndroidScope`](../../com.drake.net.scope/-android-scope/index.md) | diff --git a/docs/api/net/com.drake.net.utils/kotlinx.coroutines.flow.-flow/listen.md b/docs/api/net/com.drake.net.utils/kotlinx.coroutines.flow.-flow/listen.md index c7880f054..05fd35db1 100644 --- a/docs/api/net/com.drake.net.utils/kotlinx.coroutines.flow.-flow/listen.md +++ b/docs/api/net/com.drake.net.utils/kotlinx.coroutines.flow.-flow/listen.md @@ -2,7 +2,7 @@ # listen -`fun Flow<`[`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)`>.listen(lifecycleOwner: LifecycleOwner? = null, lifeEvent: Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: (`[`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)`) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`AndroidScope`](../../com.drake.net.scope/-android-scope/index.md) +`inline fun Flow.listen(owner: LifecycleOwner? = null, event: Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, crossinline action: suspend CoroutineScope.(value: T) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`AndroidScope`](../../com.drake.net.scope/-android-scope/index.md) 收集Flow结果并过滤重复结果 diff --git a/docs/api/net/com.drake.net.utils/kotlinx.coroutines.flow.-flow/scope.md b/docs/api/net/com.drake.net.utils/kotlinx.coroutines.flow.-flow/scope.md index ecdb9dd21..1444e140d 100644 --- a/docs/api/net/com.drake.net.utils/kotlinx.coroutines.flow.-flow/scope.md +++ b/docs/api/net/com.drake.net.utils/kotlinx.coroutines.flow.-flow/scope.md @@ -2,7 +2,7 @@ # scope -`inline fun Flow.scope(owner: LifecycleOwner? = null, event: Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, crossinline action: suspend (value: T) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`AndroidScope`](../../com.drake.net.scope/-android-scope/index.md) +`inline fun Flow.scope(owner: LifecycleOwner? = null, event: Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, crossinline action: suspend CoroutineScope.(value: T) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`AndroidScope`](../../com.drake.net.scope/-android-scope/index.md) Flow直接创建作用域 diff --git a/docs/api/net/com.drake.net.utils/lazy-field.md b/docs/api/net/com.drake.net.utils/lazy-field.md new file mode 100644 index 000000000..2808dd20b --- /dev/null +++ b/docs/api/net/com.drake.net.utils/lazy-field.md @@ -0,0 +1,10 @@ +[net](../index.md) / [com.drake.net.utils](index.md) / [lazyField](./lazy-field.md) + +# lazyField + +`fun T.lazyField(block: T.(`[`KProperty`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect/-k-property/index.html)`<*>) -> V): `[`ReadWriteProperty`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.properties/-read-write-property/index.html)`` + +延迟初始化 +线程安全 +等效于[lazy](#), 但是可以获取委托字段属性 + diff --git a/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/index.md b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/index.md new file mode 100644 index 000000000..9dd4c6c84 --- /dev/null +++ b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/index.md @@ -0,0 +1,13 @@ +[net](../../index.md) / [com.drake.net.utils](../index.md) / [okhttp3.OkHttpClient.Builder](./index.md) + +### Extensions for okhttp3.OkHttpClient.Builder + +| Name | Summary | +|---|---| +| [onDialog](on-dialog.md) | 全局加载对话框设置 设置在使用scopeDialog自动弹出的加载对话框`fun Builder.onDialog(block: `[`DialogCoroutineScope`](../../com.drake.net.scope/-dialog-coroutine-scope/index.md)`.(FragmentActivity) -> `[`Dialog`](https://developer.android.com/reference/android/app/Dialog.html)`): ` | +| [onError](on-error.md) | 全局网络请求错误捕获`fun Builder.onError(block: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): ` | +| [onStateError](on-state-error.md) | 全局缺省页错误捕获`fun Builder.onStateError(block: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`.(view: `[`View`](https://developer.android.com/reference/android/view/View.html)`) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): ` | +| [setConverter](set-converter.md) | 转换器`fun Builder.setConverter(converter: `[`NetConverter`](../../com.drake.net.convert/-net-converter/index.md)`): ` | +| [setHost](set-host.md) | 设置全局默认的Host, 在使用[com.drake.net.request.BaseRequest.setPath](../../com.drake.net.request/-base-request/set-path.md)的时候会成为默认的Host`fun Builder.setHost(host: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`): ` | +| [setLog](set-log.md) | 开启日志`fun Builder.setLog(enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`): ` | +| [setRequestInterceptor](set-request-interceptor.md) | 添加轻量级的请求拦截器, 可以在每次请求之前修改参数或者客户端配置 该拦截器不同于OkHttp的Interceptor无需处理请求动作`fun Builder.setRequestInterceptor(interceptor: `[`RequestInterceptor`](../../com.drake.net.interceptor/-request-interceptor/index.md)`): ` | diff --git a/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/on-dialog.md b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/on-dialog.md new file mode 100644 index 000000000..a027fd043 --- /dev/null +++ b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/on-dialog.md @@ -0,0 +1,9 @@ +[net](../../index.md) / [com.drake.net.utils](../index.md) / [okhttp3.OkHttpClient.Builder](index.md) / [onDialog](./on-dialog.md) + +# onDialog + +`fun Builder.onDialog(block: `[`DialogCoroutineScope`](../../com.drake.net.scope/-dialog-coroutine-scope/index.md)`.(FragmentActivity) -> `[`Dialog`](https://developer.android.com/reference/android/app/Dialog.html)`): ` + +全局加载对话框设置 +设置在使用scopeDialog自动弹出的加载对话框 + diff --git a/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/on-error.md b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/on-error.md new file mode 100644 index 000000000..9879aa106 --- /dev/null +++ b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/on-error.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.utils](../index.md) / [okhttp3.OkHttpClient.Builder](index.md) / [onError](./on-error.md) + +# onError + +`fun Builder.onError(block: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): ` + +全局网络请求错误捕获 + diff --git a/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/on-state-error.md b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/on-state-error.md new file mode 100644 index 000000000..d4d709c05 --- /dev/null +++ b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/on-state-error.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.utils](../index.md) / [okhttp3.OkHttpClient.Builder](index.md) / [onStateError](./on-state-error.md) + +# onStateError + +`fun Builder.onStateError(block: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`.(view: `[`View`](https://developer.android.com/reference/android/view/View.html)`) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): ` + +全局缺省页错误捕获 + diff --git a/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/set-converter.md b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/set-converter.md new file mode 100644 index 000000000..210bdb83e --- /dev/null +++ b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/set-converter.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.utils](../index.md) / [okhttp3.OkHttpClient.Builder](index.md) / [setConverter](./set-converter.md) + +# setConverter + +`fun Builder.setConverter(converter: `[`NetConverter`](../../com.drake.net.convert/-net-converter/index.md)`): ` + +转换器 + diff --git a/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/set-host.md b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/set-host.md new file mode 100644 index 000000000..934b54f94 --- /dev/null +++ b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/set-host.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.utils](../index.md) / [okhttp3.OkHttpClient.Builder](index.md) / [setHost](./set-host.md) + +# setHost + +`fun Builder.setHost(host: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`): ` + +设置全局默认的Host, 在使用[com.drake.net.request.BaseRequest.setPath](../../com.drake.net.request/-base-request/set-path.md)的时候会成为默认的Host + diff --git a/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/set-log.md b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/set-log.md new file mode 100644 index 000000000..dfb11e2c3 --- /dev/null +++ b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/set-log.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.utils](../index.md) / [okhttp3.OkHttpClient.Builder](index.md) / [setLog](./set-log.md) + +# setLog + +`fun Builder.setLog(enabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`): ` + +开启日志 + diff --git a/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/set-request-interceptor.md b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/set-request-interceptor.md new file mode 100644 index 000000000..ad57c2ae4 --- /dev/null +++ b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client.-builder/set-request-interceptor.md @@ -0,0 +1,9 @@ +[net](../../index.md) / [com.drake.net.utils](../index.md) / [okhttp3.OkHttpClient.Builder](index.md) / [setRequestInterceptor](./set-request-interceptor.md) + +# setRequestInterceptor + +`fun Builder.setRequestInterceptor(interceptor: `[`RequestInterceptor`](../../com.drake.net.interceptor/-request-interceptor/index.md)`): ` + +添加轻量级的请求拦截器, 可以在每次请求之前修改参数或者客户端配置 +该拦截器不同于OkHttp的Interceptor无需处理请求动作 + diff --git a/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client/cancel-group.md b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client/cancel-group.md new file mode 100644 index 000000000..498ad5299 --- /dev/null +++ b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client/cancel-group.md @@ -0,0 +1,9 @@ +[net](../../index.md) / [com.drake.net.utils](../index.md) / [okhttp3.OkHttpClient](index.md) / [cancelGroup](./cancel-group.md) + +# cancelGroup + +`fun OkHttpClient.cancelGroup(group: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +取消OkHttp客户端中指定Group的请求 +如果使用的是Net创建的网络请求请使用[com.drake.net.Net.cancelGroup](../../com.drake.net/-net/cancel-group.md) + diff --git a/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client/cancel-id.md b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client/cancel-id.md new file mode 100644 index 000000000..a32e7aea4 --- /dev/null +++ b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client/cancel-id.md @@ -0,0 +1,9 @@ +[net](../../index.md) / [com.drake.net.utils](../index.md) / [okhttp3.OkHttpClient](index.md) / [cancelId](./cancel-id.md) + +# cancelId + +`fun OkHttpClient.cancelId(id: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +取消OkHttp客户端中指定Id的请求 +如果使用的是Net创建的网络请求请使用[com.drake.net.Net.cancelId](../../com.drake.net/-net/cancel-id.md) + diff --git a/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client/index.md b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client/index.md new file mode 100644 index 000000000..cc6c84817 --- /dev/null +++ b/docs/api/net/com.drake.net.utils/okhttp3.-ok-http-client/index.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net.utils](../index.md) / [okhttp3.OkHttpClient](./index.md) + +### Extensions for okhttp3.OkHttpClient + +| Name | Summary | +|---|---| +| [cancelGroup](cancel-group.md) | 取消OkHttp客户端中指定Group的请求 如果使用的是Net创建的网络请求请使用[com.drake.net.Net.cancelGroup](../../com.drake.net/-net/cancel-group.md)`fun OkHttpClient.cancelGroup(group: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [cancelId](cancel-id.md) | 取消OkHttp客户端中指定Id的请求 如果使用的是Net创建的网络请求请使用[com.drake.net.Net.cancelId](../../com.drake.net/-net/cancel-id.md)`fun OkHttpClient.cancelId(id: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | diff --git a/docs/api/net/com.drake.net.utils/androidx.lifecycle.-lifecycle-owner/scope-life.md b/docs/api/net/com.drake.net.utils/scope-life.md similarity index 57% rename from docs/api/net/com.drake.net.utils/androidx.lifecycle.-lifecycle-owner/scope-life.md rename to docs/api/net/com.drake.net.utils/scope-life.md index 3926c7b04..b4a1f99dd 100644 --- a/docs/api/net/com.drake.net.utils/androidx.lifecycle.-lifecycle-owner/scope-life.md +++ b/docs/api/net/com.drake.net.utils/scope-life.md @@ -1,5 +1,5 @@ -[net](../../index.md) / [com.drake.net.utils](../index.md) / [androidx.lifecycle.LifecycleOwner](index.md) / [scopeLife](./scope-life.md) +[net](../index.md) / [com.drake.net.utils](index.md) / [scopeLife](./scope-life.md) # scopeLife -`fun LifecycleOwner.scopeLife(lifeEvent: Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`AndroidScope`](../../com.drake.net.scope/-android-scope/index.md) \ No newline at end of file +`fun LifecycleOwner.scopeLife(lifeEvent: Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`AndroidScope`](../com.drake.net.scope/-android-scope/index.md) \ No newline at end of file diff --git a/docs/api/net/com.drake.net.utils/scope-net-life.md b/docs/api/net/com.drake.net.utils/scope-net-life.md new file mode 100644 index 000000000..c52cfc1c7 --- /dev/null +++ b/docs/api/net/com.drake.net.utils/scope-net-life.md @@ -0,0 +1,19 @@ +[net](../index.md) / [com.drake.net.utils](index.md) / [scopeNetLife](./scope-net-life.md) + +# scopeNetLife + +`fun LifecycleOwner.scopeNetLife(lifeEvent: Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`NetCoroutineScope`](../com.drake.net.scope/-net-coroutine-scope/index.md) + +该函数比scopeNet多了自动取消作用域功能 + +该作用域生命周期跟随LifecycleOwner. 比如传入Activity会默认在[FragmentActivity.onDestroy](#)时取消网络请求. + +### Parameters + +`lifeEvent` - 指定LifecycleOwner处于生命周期下取消网络请求/作用域 + +`dispatcher` - 调度器, 默认运行在[Dispatchers.Main](#)即主线程下 + +**Receiver** +可传入FragmentActivity/AppCompatActivity, 或者其他的实现了LifecycleOwner的类 + diff --git a/docs/api/net/com.drake.net.utils/scope-net.md b/docs/api/net/com.drake.net.utils/scope-net.md index d3b885107..4395f8053 100644 --- a/docs/api/net/com.drake.net.utils/scope-net.md +++ b/docs/api/net/com.drake.net.utils/scope-net.md @@ -4,8 +4,10 @@ `fun scopeNet(dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`NetCoroutineScope`](../com.drake.net.scope/-net-coroutine-scope/index.md) -网络请求的异步作用域 -自动显示错误信息吐司 +该函数比[scope](kotlinx.coroutines.flow.-flow/scope.md)多了以下功能 + +* 在作用域内抛出异常时会被回调的[NetConfig.onError](#)函数中 +* 自动显示错误信息吐司, 可以通过指定[NetConfig.onError](#)来取消或者增加自己的处理 该作用域生命周期跟随整个应用, 注意内存泄漏 diff --git a/docs/api/net/com.drake.net/-net-config/app.md b/docs/api/net/com.drake.net/-net-config/app.md index 568a699f5..423ba5e37 100644 --- a/docs/api/net/com.drake.net/-net-config/app.md +++ b/docs/api/net/com.drake.net/-net-config/app.md @@ -4,8 +4,8 @@ `lateinit var app: `[`Application`](https://developer.android.com/reference/android/app/Application.html) -全局上下文, 一般执行[initNet](../android.app.-application/init-net.md)即可, 无需手动赋值 +全局上下文, 一般执行[initNet](../init-net.md)即可, 无需手动赋值 ### Property -`app` - 全局上下文, 一般执行[initNet](../android.app.-application/init-net.md)即可, 无需手动赋值 \ No newline at end of file +`app` - 全局上下文, 一般执行[initNet](../init-net.md)即可, 无需手动赋值 \ No newline at end of file diff --git a/docs/api/net/com.drake.net/-net-config/converter.md b/docs/api/net/com.drake.net/-net-config/converter.md new file mode 100644 index 000000000..e12e634e6 --- /dev/null +++ b/docs/api/net/com.drake.net/-net-config/converter.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [NetConfig](index.md) / [converter](./converter.md) + +# converter + +`var converter: `[`NetConverter`](../../com.drake.net.convert/-net-converter/index.md) \ No newline at end of file diff --git a/docs/api/net/com.drake.net/-net-config/host.md b/docs/api/net/com.drake.net/-net-config/host.md index c89d27dae..ce6cd9077 100644 --- a/docs/api/net/com.drake.net/-net-config/host.md +++ b/docs/api/net/com.drake.net/-net-config/host.md @@ -2,7 +2,7 @@ # host -`lateinit var host: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) +`var host: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) 全局的域名或者ip(baseUrl) diff --git a/docs/api/net/com.drake.net/-net-config/index.md b/docs/api/net/com.drake.net/-net-config/index.md index 156494940..94aec156a 100644 --- a/docs/api/net/com.drake.net/-net-config/index.md +++ b/docs/api/net/com.drake.net/-net-config/index.md @@ -10,8 +10,13 @@ Net的全局配置 | Name | Summary | |---|---| -| [app](app.md) | 全局上下文, 一般执行[initNet](../android.app.-application/init-net.md)即可, 无需手动赋值`lateinit var app: `[`Application`](https://developer.android.com/reference/android/app/Application.html) | -| [host](host.md) | 全局的域名或者ip(baseUrl)`lateinit var host: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | +| [app](app.md) | 全局上下文, 一般执行[initNet](../init-net.md)即可, 无需手动赋值`lateinit var app: `[`Application`](https://developer.android.com/reference/android/app/Application.html) | +| [converter](converter.md) | `var converter: `[`NetConverter`](../../com.drake.net.convert/-net-converter/index.md) | +| [host](host.md) | 全局的域名或者ip(baseUrl)`var host: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | +| [logEnabled](log-enabled.md) | `var logEnabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | +| [netCalls](net-calls.md) | `var netCalls: `[`ConcurrentLinkedQueue`](https://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html)`` | +| [okHttpClient](ok-http-client.md) | `lateinit var okHttpClient: OkHttpClient` | | [onDialog](on-dialog.md) | 全局加载框`var onDialog: `[`DialogCoroutineScope`](../../com.drake.net.scope/-dialog-coroutine-scope/index.md)`.(FragmentActivity) -> `[`Dialog`](https://developer.android.com/reference/android/app/Dialog.html) | | [onError](on-error.md) | 全局错误处理`var onError: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | | [onStateError](on-state-error.md) | 全局缺省页错误处理`var onStateError: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`.(view: `[`View`](https://developer.android.com/reference/android/view/View.html)`) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [requestInterceptor](request-interceptor.md) | `var requestInterceptor: `[`RequestInterceptor`](../../com.drake.net.interceptor/-request-interceptor/index.md)`?` | diff --git a/docs/api/net/com.drake.net/-net-config/log-enabled.md b/docs/api/net/com.drake.net/-net-config/log-enabled.md new file mode 100644 index 000000000..ecc854960 --- /dev/null +++ b/docs/api/net/com.drake.net/-net-config/log-enabled.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [NetConfig](index.md) / [logEnabled](./log-enabled.md) + +# logEnabled + +`var logEnabled: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net/-net-config/net-calls.md b/docs/api/net/com.drake.net/-net-config/net-calls.md new file mode 100644 index 000000000..e922d2e57 --- /dev/null +++ b/docs/api/net/com.drake.net/-net-config/net-calls.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [NetConfig](index.md) / [netCalls](./net-calls.md) + +# netCalls + +`var netCalls: `[`ConcurrentLinkedQueue`](https://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html)`` \ No newline at end of file diff --git a/docs/api/net/com.drake.net/-net-config/ok-http-client.md b/docs/api/net/com.drake.net/-net-config/ok-http-client.md new file mode 100644 index 000000000..555261c97 --- /dev/null +++ b/docs/api/net/com.drake.net/-net-config/ok-http-client.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [NetConfig](index.md) / [okHttpClient](./ok-http-client.md) + +# okHttpClient + +`lateinit var okHttpClient: OkHttpClient` \ No newline at end of file diff --git a/docs/api/net/com.drake.net/-net-config/request-interceptor.md b/docs/api/net/com.drake.net/-net-config/request-interceptor.md new file mode 100644 index 000000000..54076c762 --- /dev/null +++ b/docs/api/net/com.drake.net/-net-config/request-interceptor.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [NetConfig](index.md) / [requestInterceptor](./request-interceptor.md) + +# requestInterceptor + +`var requestInterceptor: `[`RequestInterceptor`](../../com.drake.net.interceptor/-request-interceptor/index.md)`?` \ No newline at end of file diff --git a/docs/api/net/com.drake.net/-net/add-download-listener.md b/docs/api/net/com.drake.net/-net/add-download-listener.md new file mode 100644 index 000000000..03f9b6d84 --- /dev/null +++ b/docs/api/net/com.drake.net/-net/add-download-listener.md @@ -0,0 +1,16 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [Net](index.md) / [addDownloadListener](./add-download-listener.md) + +# addDownloadListener + +`fun addDownloadListener(id: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`, progressListener: `[`ProgressListener`](../../com.drake.net.request/-progress-listener/index.md)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +监听正在请求的下载进度 + +### Parameters + +`id` - 请求的Id + +**See Also** + +[com.drake.net.request.BaseRequest.setId](../../com.drake.net.request/-base-request/set-id.md) + diff --git a/docs/api/net/com.drake.net/-net/add-upload-listener.md b/docs/api/net/com.drake.net/-net/add-upload-listener.md new file mode 100644 index 000000000..48aff1f63 --- /dev/null +++ b/docs/api/net/com.drake.net/-net/add-upload-listener.md @@ -0,0 +1,16 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [Net](index.md) / [addUploadListener](./add-upload-listener.md) + +# addUploadListener + +`fun addUploadListener(id: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`, progressListener: `[`ProgressListener`](../../com.drake.net.request/-progress-listener/index.md)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +监听正在请求的上传进度 + +### Parameters + +`id` - 请求的Id + +**See Also** + +[com.drake.net.request.BaseRequest.setId](../../com.drake.net.request/-base-request/set-id.md) + diff --git a/docs/api/net/com.drake.net/-net/cancel-all.md b/docs/api/net/com.drake.net/-net/cancel-all.md new file mode 100644 index 000000000..a855cfd6c --- /dev/null +++ b/docs/api/net/com.drake.net/-net/cancel-all.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [Net](index.md) / [cancelAll](./cancel-all.md) + +# cancelAll + +`fun cancelAll(): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +取消全部网络请求 + diff --git a/docs/api/net/com.drake.net/-net/cancel-group.md b/docs/api/net/com.drake.net/-net/cancel-group.md new file mode 100644 index 000000000..4f7e42779 --- /dev/null +++ b/docs/api/net/com.drake.net/-net/cancel-group.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [Net](index.md) / [cancelGroup](./cancel-group.md) + +# cancelGroup + +`fun cancelGroup(group: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +根据分组取消网络请求 + diff --git a/docs/api/net/com.drake.net/-net/cancel-id.md b/docs/api/net/com.drake.net/-net/cancel-id.md new file mode 100644 index 000000000..f8d36463d --- /dev/null +++ b/docs/api/net/com.drake.net/-net/cancel-id.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [Net](index.md) / [cancelId](./cancel-id.md) + +# cancelId + +`fun cancelId(id: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +取消指定的网络请求 + diff --git a/docs/api/net/com.drake.net/-net/delete.md b/docs/api/net/com.drake.net/-net/delete.md new file mode 100644 index 000000000..187a0f41f --- /dev/null +++ b/docs/api/net/com.drake.net/-net/delete.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [Net](index.md) / [delete](./delete.md) + +# delete + +`fun delete(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`BodyRequest`](../../com.drake.net.request/-body-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): ` \ No newline at end of file diff --git a/docs/api/net/com.drake.net/-net/get.md b/docs/api/net/com.drake.net/-net/get.md new file mode 100644 index 000000000..99f75bba8 --- /dev/null +++ b/docs/api/net/com.drake.net/-net/get.md @@ -0,0 +1,15 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [Net](index.md) / [get](./get.md) + +# get + +`fun get(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`UrlRequest`](../../com.drake.net.request/-url-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): ` + +同步网络请求 + +### Parameters + +`path` - 请求路径, 如果其不包含http/https则会自动拼接[NetConfig.host](../-net-config/host.md) + +`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 + +`block` - 函数中可以配置请求参数 \ No newline at end of file diff --git a/docs/api/net/com.drake.net/-net/head.md b/docs/api/net/com.drake.net/-net/head.md new file mode 100644 index 000000000..86f6e22af --- /dev/null +++ b/docs/api/net/com.drake.net/-net/head.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [Net](index.md) / [head](./head.md) + +# head + +`fun head(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`UrlRequest`](../../com.drake.net.request/-url-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): ` \ No newline at end of file diff --git a/docs/api/net/com.drake.net/-net/index.md b/docs/api/net/com.drake.net/-net/index.md new file mode 100644 index 000000000..16b1e9a09 --- /dev/null +++ b/docs/api/net/com.drake.net/-net/index.md @@ -0,0 +1,27 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [Net](./index.md) + +# Net + +`object Net` + +### Functions + +| Name | Summary | +|---|---| +| [addDownloadListener](add-download-listener.md) | 监听正在请求的下载进度`fun addDownloadListener(id: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`, progressListener: `[`ProgressListener`](../../com.drake.net.request/-progress-listener/index.md)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [addUploadListener](add-upload-listener.md) | 监听正在请求的上传进度`fun addUploadListener(id: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`, progressListener: `[`ProgressListener`](../../com.drake.net.request/-progress-listener/index.md)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [cancelAll](cancel-all.md) | 取消全部网络请求`fun cancelAll(): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [cancelGroup](cancel-group.md) | 根据分组取消网络请求`fun cancelGroup(group: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [cancelId](cancel-id.md) | 取消指定的网络请求`fun cancelId(id: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [delete](delete.md) | `fun delete(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`BodyRequest`](../../com.drake.net.request/-body-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): ` | +| [get](get.md) | 同步网络请求`fun get(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`UrlRequest`](../../com.drake.net.request/-url-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): ` | +| [head](head.md) | `fun head(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`UrlRequest`](../../com.drake.net.request/-url-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): ` | +| [options](options.md) | `fun options(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`UrlRequest`](../../com.drake.net.request/-url-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): ` | +| [patch](patch.md) | `fun patch(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`BodyRequest`](../../com.drake.net.request/-body-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): ` | +| [post](post.md) | `fun post(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`BodyRequest`](../../com.drake.net.request/-body-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): ` | +| [put](put.md) | `fun put(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`BodyRequest`](../../com.drake.net.request/-body-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): ` | +| [removeDownloadListener](remove-download-listener.md) | 删除正在请求的下载进度监听器`fun removeDownloadListener(id: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`, progressListener: `[`ProgressListener`](../../com.drake.net.request/-progress-listener/index.md)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [removeUploadListener](remove-upload-listener.md) | 删除正在请求的上传进度监听器`fun removeUploadListener(id: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`, progressListener: `[`ProgressListener`](../../com.drake.net.request/-progress-listener/index.md)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | +| [requestByGroup](request-by-group.md) | 指定分组的请求`fun requestByGroup(group: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`): ` | +| [requestById](request-by-id.md) | 指定Id的请求`fun requestById(id: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`): Request?` | +| [trace](trace.md) | `fun trace(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`UrlRequest`](../../com.drake.net.request/-url-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): ` | diff --git a/docs/api/net/com.drake.net/-net/options.md b/docs/api/net/com.drake.net/-net/options.md new file mode 100644 index 000000000..0fc50eb41 --- /dev/null +++ b/docs/api/net/com.drake.net/-net/options.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [Net](index.md) / [options](./options.md) + +# options + +`fun options(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`UrlRequest`](../../com.drake.net.request/-url-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): ` \ No newline at end of file diff --git a/docs/api/net/com.drake.net/-net/patch.md b/docs/api/net/com.drake.net/-net/patch.md new file mode 100644 index 000000000..174cbc0a1 --- /dev/null +++ b/docs/api/net/com.drake.net/-net/patch.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [Net](index.md) / [patch](./patch.md) + +# patch + +`fun patch(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`BodyRequest`](../../com.drake.net.request/-body-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): ` \ No newline at end of file diff --git a/docs/api/net/com.drake.net/-net/post.md b/docs/api/net/com.drake.net/-net/post.md new file mode 100644 index 000000000..bafd2ee08 --- /dev/null +++ b/docs/api/net/com.drake.net/-net/post.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [Net](index.md) / [post](./post.md) + +# post + +`fun post(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`BodyRequest`](../../com.drake.net.request/-body-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): ` \ No newline at end of file diff --git a/docs/api/net/com.drake.net/-net/put.md b/docs/api/net/com.drake.net/-net/put.md new file mode 100644 index 000000000..aa659fa04 --- /dev/null +++ b/docs/api/net/com.drake.net/-net/put.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [Net](index.md) / [put](./put.md) + +# put + +`fun put(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`BodyRequest`](../../com.drake.net.request/-body-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): ` \ No newline at end of file diff --git a/docs/api/net/com.drake.net/-net/remove-download-listener.md b/docs/api/net/com.drake.net/-net/remove-download-listener.md new file mode 100644 index 000000000..ab5780fd5 --- /dev/null +++ b/docs/api/net/com.drake.net/-net/remove-download-listener.md @@ -0,0 +1,16 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [Net](index.md) / [removeDownloadListener](./remove-download-listener.md) + +# removeDownloadListener + +`fun removeDownloadListener(id: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`, progressListener: `[`ProgressListener`](../../com.drake.net.request/-progress-listener/index.md)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +删除正在请求的下载进度监听器 + +### Parameters + +`id` - 请求的Id + +**See Also** + +[com.drake.net.request.BaseRequest.setId](../../com.drake.net.request/-base-request/set-id.md) + diff --git a/docs/api/net/com.drake.net/-net/remove-upload-listener.md b/docs/api/net/com.drake.net/-net/remove-upload-listener.md new file mode 100644 index 000000000..caeef87be --- /dev/null +++ b/docs/api/net/com.drake.net/-net/remove-upload-listener.md @@ -0,0 +1,16 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [Net](index.md) / [removeUploadListener](./remove-upload-listener.md) + +# removeUploadListener + +`fun removeUploadListener(id: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`, progressListener: `[`ProgressListener`](../../com.drake.net.request/-progress-listener/index.md)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +删除正在请求的上传进度监听器 + +### Parameters + +`id` - 请求的Id + +**See Also** + +[com.drake.net.request.BaseRequest.setId](../../com.drake.net.request/-base-request/set-id.md) + diff --git a/docs/api/net/com.drake.net/-net/request-by-group.md b/docs/api/net/com.drake.net/-net/request-by-group.md new file mode 100644 index 000000000..e6bbe912e --- /dev/null +++ b/docs/api/net/com.drake.net/-net/request-by-group.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [Net](index.md) / [requestByGroup](./request-by-group.md) + +# requestByGroup + +`fun requestByGroup(group: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`): ` + +指定分组的请求 + diff --git a/docs/api/net/com.drake.net/-net/request-by-id.md b/docs/api/net/com.drake.net/-net/request-by-id.md new file mode 100644 index 000000000..a3d16031c --- /dev/null +++ b/docs/api/net/com.drake.net/-net/request-by-id.md @@ -0,0 +1,8 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [Net](index.md) / [requestById](./request-by-id.md) + +# requestById + +`fun requestById(id: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`): Request?` + +指定Id的请求 + diff --git a/docs/api/net/com.drake.net/-net/trace.md b/docs/api/net/com.drake.net/-net/trace.md new file mode 100644 index 000000000..c1bfa8e7a --- /dev/null +++ b/docs/api/net/com.drake.net/-net/trace.md @@ -0,0 +1,5 @@ +[net](../../index.md) / [com.drake.net](../index.md) / [Net](index.md) / [trace](./trace.md) + +# trace + +`fun trace(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`UrlRequest`](../../com.drake.net.request/-url-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): ` \ No newline at end of file diff --git a/docs/api/net/com.drake.net/android.app.-application/index.md b/docs/api/net/com.drake.net/android.app.-application/index.md deleted file mode 100644 index 4cd04a631..000000000 --- a/docs/api/net/com.drake.net/android.app.-application/index.md +++ /dev/null @@ -1,7 +0,0 @@ -[net](../../index.md) / [com.drake.net](../index.md) / [android.app.Application](./index.md) - -### Extensions for android.app.Application - -| Name | Summary | -|---|---| -| [initNet](init-net.md) | 初始化框架`fun `[`Application`](https://developer.android.com/reference/android/app/Application.html)`.initNet(host: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, config: Builder.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | diff --git a/docs/api/net/com.drake.net/android.app.-application/init-net.md b/docs/api/net/com.drake.net/android.app.-application/init-net.md deleted file mode 100644 index 130665fb3..000000000 --- a/docs/api/net/com.drake.net/android.app.-application/init-net.md +++ /dev/null @@ -1,24 +0,0 @@ -[net](../../index.md) / [com.drake.net](../index.md) / [android.app.Application](index.md) / [initNet](./init-net.md) - -# initNet - -`fun `[`Application`](https://developer.android.com/reference/android/app/Application.html)`.initNet(host: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, config: Builder.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) - -初始化框架 - -### Parameters - -`host` - 请求url的主机名 - -`config` - - -进行配置网络请求 - - - -如果想要自动解析数据模型请配置转换器, 可以继承或者参考默认转换器 - -**See Also** - -[com.drake.net.convert.DefaultConvert](../../com.drake.net.convert/-default-convert/index.md) - diff --git a/docs/api/net/com.drake.net/android.content.-context/index.md b/docs/api/net/com.drake.net/android.content.-context/index.md deleted file mode 100644 index d4b87e66c..000000000 --- a/docs/api/net/com.drake.net/android.content.-context/index.md +++ /dev/null @@ -1,7 +0,0 @@ -[net](../../index.md) / [com.drake.net](../index.md) / [android.content.Context](./index.md) - -### Extensions for android.content.Context - -| Name | Summary | -|---|---| -| [syncDownloadImage](sync-download-image.md) | 同步下载图片, 图片宽高要求要么同时指定要么同时不指定 要求依赖 Glide`fun `[`Context`](https://developer.android.com/reference/android/content/Context.html)`.syncDownloadImage(url: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, with: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` = 0, height: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` = 0): `[`File`](https://docs.oracle.com/javase/6/docs/api/java/io/File.html) | diff --git a/docs/api/net/com.drake.net/android.content.-context/sync-download-image.md b/docs/api/net/com.drake.net/android.content.-context/sync-download-image.md deleted file mode 100644 index fda62f306..000000000 --- a/docs/api/net/com.drake.net/android.content.-context/sync-download-image.md +++ /dev/null @@ -1,16 +0,0 @@ -[net](../../index.md) / [com.drake.net](../index.md) / [android.content.Context](index.md) / [syncDownloadImage](./sync-download-image.md) - -# syncDownloadImage - -`fun `[`Context`](https://developer.android.com/reference/android/content/Context.html)`.syncDownloadImage(url: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, with: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` = 0, height: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` = 0): `[`File`](https://docs.oracle.com/javase/6/docs/api/java/io/File.html) - -同步下载图片, 图片宽高要求要么同时指定要么同时不指定 -要求依赖 Glide - -### Parameters - -`url` - 请求图片的绝对路径 - -`with` - 图片宽度 - -`height` - 图片高度 \ No newline at end of file diff --git a/docs/api/net/com.drake.net/com.yanzhenjie.kalle.-kalle-config.-builder/cache-enabled.md b/docs/api/net/com.drake.net/com.yanzhenjie.kalle.-kalle-config.-builder/cache-enabled.md deleted file mode 100644 index 24b8b2c97..000000000 --- a/docs/api/net/com.drake.net/com.yanzhenjie.kalle.-kalle-config.-builder/cache-enabled.md +++ /dev/null @@ -1,13 +0,0 @@ -[net](../../index.md) / [com.drake.net](../index.md) / [com.yanzhenjie.kalle.KalleConfig.Builder](index.md) / [cacheEnabled](./cache-enabled.md) - -# cacheEnabled - -`fun Builder.cacheEnabled(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = NetConfig.app.cacheDir.absolutePath, password: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "cache"): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) - -开启缓存 - -### Parameters - -`path` - 缓存数据库路径 - -`password` - 缓存数据库密码 \ No newline at end of file diff --git a/docs/api/net/com.drake.net/com.yanzhenjie.kalle.-kalle-config.-builder/index.md b/docs/api/net/com.drake.net/com.yanzhenjie.kalle.-kalle-config.-builder/index.md deleted file mode 100644 index a741e53e4..000000000 --- a/docs/api/net/com.drake.net/com.yanzhenjie.kalle.-kalle-config.-builder/index.md +++ /dev/null @@ -1,10 +0,0 @@ -[net](../../index.md) / [com.drake.net](../index.md) / [com.yanzhenjie.kalle.KalleConfig.Builder](./index.md) - -### Extensions for com.yanzhenjie.kalle.KalleConfig.Builder - -| Name | Summary | -|---|---| -| [cacheEnabled](cache-enabled.md) | 开启缓存`fun Builder.cacheEnabled(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = NetConfig.app.cacheDir.absolutePath, password: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "cache"): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | -| [onDialog](on-dialog.md) | 设置使用DialogObserver默认弹出的加载对话框 默认使用系统自带的ProgressDialog`fun Builder.onDialog(block: `[`DialogCoroutineScope`](../../com.drake.net.scope/-dialog-coroutine-scope/index.md)`.(context: FragmentActivity) -> `[`Dialog`](https://developer.android.com/reference/android/app/Dialog.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | -| [onError](on-error.md) | 该函数指定某些Observer的onError中的默认错误信息处理`fun Builder.onError(block: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | -| [onStateError](on-state-error.md) | 该函数指定某些Observer的onError中的默认错误信息处理`fun Builder.onStateError(block: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`.(view: `[`View`](https://developer.android.com/reference/android/view/View.html)`) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | diff --git a/docs/api/net/com.drake.net/com.yanzhenjie.kalle.-kalle-config.-builder/on-dialog.md b/docs/api/net/com.drake.net/com.yanzhenjie.kalle.-kalle-config.-builder/on-dialog.md deleted file mode 100644 index dba655643..000000000 --- a/docs/api/net/com.drake.net/com.yanzhenjie.kalle.-kalle-config.-builder/on-dialog.md +++ /dev/null @@ -1,9 +0,0 @@ -[net](../../index.md) / [com.drake.net](../index.md) / [com.yanzhenjie.kalle.KalleConfig.Builder](index.md) / [onDialog](./on-dialog.md) - -# onDialog - -`fun Builder.onDialog(block: `[`DialogCoroutineScope`](../../com.drake.net.scope/-dialog-coroutine-scope/index.md)`.(context: FragmentActivity) -> `[`Dialog`](https://developer.android.com/reference/android/app/Dialog.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) - -设置使用DialogObserver默认弹出的加载对话框 -默认使用系统自带的ProgressDialog - diff --git a/docs/api/net/com.drake.net/com.yanzhenjie.kalle.-kalle-config.-builder/on-error.md b/docs/api/net/com.drake.net/com.yanzhenjie.kalle.-kalle-config.-builder/on-error.md deleted file mode 100644 index 223c8c285..000000000 --- a/docs/api/net/com.drake.net/com.yanzhenjie.kalle.-kalle-config.-builder/on-error.md +++ /dev/null @@ -1,12 +0,0 @@ -[net](../../index.md) / [com.drake.net](../index.md) / [com.yanzhenjie.kalle.KalleConfig.Builder](index.md) / [onError](./on-error.md) - -# onError - -`fun Builder.onError(block: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) - -该函数指定某些Observer的onError中的默认错误信息处理 - -**See Also** - -[NetConfig.onError](../-net-config/on-error.md) - diff --git a/docs/api/net/com.drake.net/com.yanzhenjie.kalle.-kalle-config.-builder/on-state-error.md b/docs/api/net/com.drake.net/com.yanzhenjie.kalle.-kalle-config.-builder/on-state-error.md deleted file mode 100644 index 9e708445c..000000000 --- a/docs/api/net/com.drake.net/com.yanzhenjie.kalle.-kalle-config.-builder/on-state-error.md +++ /dev/null @@ -1,14 +0,0 @@ -[net](../../index.md) / [com.drake.net](../index.md) / [com.yanzhenjie.kalle.KalleConfig.Builder](index.md) / [onStateError](./on-state-error.md) - -# onStateError - -`fun Builder.onStateError(block: `[`Throwable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`.(view: `[`View`](https://developer.android.com/reference/android/view/View.html)`) -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) - -该函数指定某些Observer的onError中的默认错误信息处理 - -如果不设置默认只有 解析数据错误 | 后台自定义错误 会显示吐司 - -**See Also** - -[NetConfig.onStateError](../-net-config/on-state-error.md) - diff --git a/docs/api/net/com.drake.net/index.md b/docs/api/net/com.drake.net/index.md index 8fa235e3e..740b6d646 100644 --- a/docs/api/net/com.drake.net/index.md +++ b/docs/api/net/com.drake.net/index.md @@ -6,28 +6,17 @@ | Name | Summary | |---|---| +| [Net](-net/index.md) | `object Net` | | [NetConfig](-net-config/index.md) | Net的全局配置`object NetConfig` | ### Extensions for External Classes | Name | Summary | |---|---| -| [android.app.Application](android.app.-application/index.md) | | -| [android.content.Context](android.content.-context/index.md) | | -| [com.yanzhenjie.kalle.KalleConfig.Builder](com.yanzhenjie.kalle.-kalle-config.-builder/index.md) | | | [kotlinx.coroutines.CoroutineScope](kotlinx.coroutines.-coroutine-scope/index.md) | | ### Functions | Name | Summary | |---|---| -| [syncDelete](sync-delete.md) | 同步网络请求`fun syncDelete(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): M` | -| [syncDownload](sync-download.md) | 同步文件下载, 默认Get请求`fun syncDownload(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, dir: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = NetConfig.app.externalCacheDir!!.absolutePath, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, method: RequestMethod = RequestMethod.GET, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | -| [syncDownloadBody](sync-download-body.md) | 同步文件下载, 允许提交请求体方式, 默认Post请求`fun syncDownloadBody(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, dir: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = NetConfig.app.externalCacheDir!!.absolutePath, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, method: RequestMethod = RequestMethod.GET, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | -| [syncGet](sync-get.md) | 同步网络请求`fun syncGet(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): M` | -| [syncHead](sync-head.md) | 同步网络请求`fun syncHead(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): M` | -| [syncOptions](sync-options.md) | 同步网络请求`fun syncOptions(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): M` | -| [syncPatch](sync-patch.md) | 同步网络请求`fun syncPatch(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): M` | -| [syncPost](sync-post.md) | 同步网络请求`fun syncPost(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): M` | -| [syncPut](sync-put.md) | 同步网络请求`fun syncPut(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): M` | -| [syncTrace](sync-trace.md) | 同步网络请求`fun syncTrace(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): M` | +| [initNet](init-net.md) | 初始化框架`fun initNet(host: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "", config: Builder.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`fun initNet(host: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "", config: Builder): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | diff --git a/docs/api/net/com.drake.net/init-net.md b/docs/api/net/com.drake.net/init-net.md new file mode 100644 index 000000000..8c2bfbbc1 --- /dev/null +++ b/docs/api/net/com.drake.net/init-net.md @@ -0,0 +1,25 @@ +[net](../index.md) / [com.drake.net](index.md) / [initNet](./init-net.md) + +# initNet + +`fun initNet(host: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "", config: Builder.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) + +初始化框架 + +### Parameters + +`host` - 请求url的主机名 + +`config` - + +进行配置网络请求 + + + +如果想要自动解析数据模型请配置转换器, 可以继承或者参考默认转换器 + +**See Also** + +[com.drake.net.convert.JSONConvert](../com.drake.net.convert/-j-s-o-n-convert/index.md) + +`fun initNet(host: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = "", config: Builder): `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) \ No newline at end of file diff --git a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-delete.md b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-delete.md index b97b41049..861da7814 100644 --- a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-delete.md +++ b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-delete.md @@ -2,18 +2,4 @@ # Delete -`inline fun CoroutineScope.Delete(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = coroutineContext[CoroutineExceptionHandler], noinline block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): Deferred` - -异步网络请求 - -### Parameters - -`path` - String 请求路径, 非绝对路径会加上[NetConfig.host](../-net-config/host.md)为前缀 - -`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - -`absolutePath` - 请求路径是否是绝对路径 - -`uid` - 表示请求的唯一id, 和[NetCancel.cancel](#)中的uid一致, 一般用于指定取消网络请求的唯一id - -`block` - 函数中可以配置请求参数 \ No newline at end of file +`inline fun CoroutineScope.Delete(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, noinline block: (`[`BodyRequest`](../../com.drake.net.request/-body-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): Deferred` \ No newline at end of file diff --git a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-download-body.md b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-download-body.md deleted file mode 100644 index dbd19065d..000000000 --- a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-download-body.md +++ /dev/null @@ -1,21 +0,0 @@ -[net](../../index.md) / [com.drake.net](../index.md) / [kotlinx.coroutines.CoroutineScope](index.md) / [DownloadBody](./-download-body.md) - -# DownloadBody - -`fun CoroutineScope.DownloadBody(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, dir: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = NetConfig.app.externalCacheDir!!.absolutePath, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, method: RequestMethod = RequestMethod.POST, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = coroutineContext[CoroutineExceptionHandler], block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): Deferred<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>` - -用于提交请求体下载文件(默认POST请求) - -### Parameters - -`path` - 请求路径, 非绝对路径会加上HOST[NetConfig.host](../-net-config/host.md)为前缀 - -`method` - 请求方式, 默认GET - -`dir` - 下载文件存放目录 {默认存在android/data/packageName/cache目录} - -`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - -`absolutePath` - 下载链接是否是绝对路径 - -`block` - 配置请求参数 \ No newline at end of file diff --git a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-download-image.md b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-download-image.md deleted file mode 100644 index 348ad2e81..000000000 --- a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-download-image.md +++ /dev/null @@ -1,16 +0,0 @@ -[net](../../index.md) / [com.drake.net](../index.md) / [kotlinx.coroutines.CoroutineScope](index.md) / [DownloadImage](./-download-image.md) - -# DownloadImage - -`fun CoroutineScope.DownloadImage(url: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, with: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` = -1, height: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` = -1): Deferred<`[`File`](https://docs.oracle.com/javase/6/docs/api/java/io/File.html)`>` - -异步下载图片, 图片宽高要求要么同时指定要么同时不指定 -要求依赖 Glide - -### Parameters - -`url` - 请求图片的绝对路径 - -`with` - 图片宽度 - -`height` - 图片高度 \ No newline at end of file diff --git a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-download.md b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-download.md deleted file mode 100644 index 430141887..000000000 --- a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-download.md +++ /dev/null @@ -1,21 +0,0 @@ -[net](../../index.md) / [com.drake.net](../index.md) / [kotlinx.coroutines.CoroutineScope](index.md) / [Download](./-download.md) - -# Download - -`fun CoroutineScope.Download(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, dir: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = NetConfig.app.externalCacheDir!!.absolutePath, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, method: RequestMethod = RequestMethod.GET, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = coroutineContext[CoroutineExceptionHandler], block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): Deferred<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>` - -用于提交URL体下载文件(默认GET请求) - -### Parameters - -`path` - 请求路径, 非绝对路径会加上HOST[NetConfig.host](../-net-config/host.md)为前缀 - -`method` - 请求方式, 默认GET - -`dir` - 下载文件存放目录 {默认存在android/data/packageName/cache目录} - -`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - -`absolutePath` - 下载链接是否是绝对路径 - -`block` - 请求参数 \ No newline at end of file diff --git a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-get.md b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-get.md index d8b6bdf93..25e2fe247 100644 --- a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-get.md +++ b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-get.md @@ -2,18 +2,14 @@ # Get -`inline fun CoroutineScope.Get(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = coroutineContext[CoroutineExceptionHandler], noinline block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): Deferred` +`inline fun CoroutineScope.Get(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, noinline block: (`[`UrlRequest`](../../com.drake.net.request/-url-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): Deferred` 异步网络请求 ### Parameters -`path` - String 请求路径, 非绝对路径会加上[NetConfig.host](../-net-config/host.md)为前缀 +`path` - 请求路径, 如果其不包含http/https则会自动拼接[NetConfig.host](../-net-config/host.md) -`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - -`absolutePath` - 请求路径是否是绝对路径 - -`uid` - 表示请求的唯一id, 和[NetCancel.cancel](#)中的uid一致, 一般用于指定取消网络请求的唯一id +`tag` - 可以传递对象给Request, 一般用于在拦截器/转换器中进行针对某个接口行为判断 `block` - 函数中可以配置请求参数 \ No newline at end of file diff --git a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-head.md b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-head.md index 017a5e327..fbd782d63 100644 --- a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-head.md +++ b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-head.md @@ -2,18 +2,4 @@ # Head -`inline fun CoroutineScope.Head(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = coroutineContext[CoroutineExceptionHandler], noinline block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): Deferred` - -异步网络请求 - -### Parameters - -`path` - String 请求路径, 非绝对路径会加上[NetConfig.host](../-net-config/host.md)为前缀 - -`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - -`absolutePath` - 请求路径是否是绝对路径 - -`uid` - 表示请求的唯一id, 和[NetCancel.cancel](#)中的uid一致, 一般用于指定取消网络请求的唯一id - -`block` - 函数中可以配置请求参数 \ No newline at end of file +`inline fun CoroutineScope.Head(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, noinline block: (`[`UrlRequest`](../../com.drake.net.request/-url-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): Deferred` \ No newline at end of file diff --git a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-options.md b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-options.md index 449c3d00b..43eeee21a 100644 --- a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-options.md +++ b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-options.md @@ -2,18 +2,4 @@ # Options -`inline fun CoroutineScope.Options(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = coroutineContext[CoroutineExceptionHandler], noinline block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): Deferred` - -异步网络请求 - -### Parameters - -`path` - String 请求路径, 非绝对路径会加上[NetConfig.host](../-net-config/host.md)为前缀 - -`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - -`absolutePath` - 请求路径是否是绝对路径 - -`uid` - 表示请求的唯一id, 和[NetCancel.cancel](#)中的uid一致, 一般用于指定取消网络请求的唯一id - -`block` - 函数中可以配置请求参数 \ No newline at end of file +`inline fun CoroutineScope.Options(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, noinline block: (`[`UrlRequest`](../../com.drake.net.request/-url-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): Deferred` \ No newline at end of file diff --git a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-patch.md b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-patch.md index 5380564e6..9e39f61c9 100644 --- a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-patch.md +++ b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-patch.md @@ -2,18 +2,4 @@ # Patch -`inline fun CoroutineScope.Patch(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = coroutineContext[CoroutineExceptionHandler], noinline block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): Deferred` - -异步网络请求 - -### Parameters - -`path` - String 请求路径, 非绝对路径会加上[NetConfig.host](../-net-config/host.md)为前缀 - -`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - -`absolutePath` - 请求路径是否是绝对路径 - -`uid` - 表示请求的唯一id, 和[NetCancel.cancel](#)中的uid一致, 一般用于指定取消网络请求的唯一id, 和[NetCancel.cancel](#)中的uid一致, 一般用于指定取消网络请求的唯一id - -`block` - 函数中可以配置请求参数 \ No newline at end of file +`inline fun CoroutineScope.Patch(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, noinline block: (`[`BodyRequest`](../../com.drake.net.request/-body-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): Deferred` \ No newline at end of file diff --git a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-post.md b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-post.md index 36d2adc80..ce8f6f6a7 100644 --- a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-post.md +++ b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-post.md @@ -2,18 +2,4 @@ # Post -`inline fun CoroutineScope.Post(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = coroutineContext[CoroutineExceptionHandler], noinline block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): Deferred` - -异步网络请求 - -### Parameters - -`path` - String 请求路径, 非绝对路径会加上[NetConfig.host](../-net-config/host.md)为前缀 - -`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - -`absolutePath` - 请求路径是否是绝对路径 - -`uid` - 表示请求的唯一id, 和[NetCancel.cancel](#)中的uid一致, 一般用于指定取消网络请求的唯一id - -`block` - 函数中可以配置请求参数 \ No newline at end of file +`inline fun CoroutineScope.Post(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, noinline block: (`[`BodyRequest`](../../com.drake.net.request/-body-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): Deferred` \ No newline at end of file diff --git a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-put.md b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-put.md index 83d4220fe..852ae5011 100644 --- a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-put.md +++ b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-put.md @@ -2,18 +2,4 @@ # Put -`inline fun CoroutineScope.Put(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = coroutineContext[CoroutineExceptionHandler], noinline block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): Deferred` - -异步网络请求 - -### Parameters - -`path` - String 请求路径, 非绝对路径会加上[NetConfig.host](../-net-config/host.md)为前缀 - -`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - -`absolutePath` - 请求路径是否是绝对路径 - -`uid` - 表示请求的唯一id, 和[NetCancel.cancel](#)中的uid一致, 一般用于指定取消网络请求的唯一id - -`block` - 函数中可以配置请求参数 \ No newline at end of file +`inline fun CoroutineScope.Put(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, noinline block: (`[`BodyRequest`](../../com.drake.net.request/-body-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): Deferred` \ No newline at end of file diff --git a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-trace.md b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-trace.md index 293f150ae..eb0769ec7 100644 --- a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-trace.md +++ b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-trace.md @@ -2,18 +2,4 @@ # Trace -`inline fun CoroutineScope.Trace(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = coroutineContext[CoroutineExceptionHandler], noinline block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): Deferred` - -异步网络请求 - -### Parameters - -`path` - String 请求路径, 非绝对路径会加上[NetConfig.host](../-net-config/host.md)为前缀 - -`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - -`absolutePath` - 请求路径是否是绝对路径 - -`uid` - 表示请求的唯一id, 和[NetCancel.cancel](#)中的uid一致, 一般用于指定取消网络请求的唯一id - -`block` - 函数中可以配置请求参数 \ No newline at end of file +`inline fun CoroutineScope.Trace(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, noinline block: (`[`UrlRequest`](../../com.drake.net.request/-url-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): Deferred` \ No newline at end of file diff --git a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/index.md b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/index.md index 1bfbbded2..39b4be68e 100644 --- a/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/index.md +++ b/docs/api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/index.md @@ -4,14 +4,11 @@ | Name | Summary | |---|---| -| [Delete](-delete.md) | 异步网络请求`fun CoroutineScope.Delete(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = coroutineContext[CoroutineExceptionHandler], block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): Deferred` | -| [Download](-download.md) | 用于提交URL体下载文件(默认GET请求)`fun CoroutineScope.Download(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, dir: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = NetConfig.app.externalCacheDir!!.absolutePath, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, method: RequestMethod = RequestMethod.GET, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = coroutineContext[CoroutineExceptionHandler], block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): Deferred<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>` | -| [DownloadBody](-download-body.md) | 用于提交请求体下载文件(默认POST请求)`fun CoroutineScope.DownloadBody(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, dir: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = NetConfig.app.externalCacheDir!!.absolutePath, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, method: RequestMethod = RequestMethod.POST, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = coroutineContext[CoroutineExceptionHandler], block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): Deferred<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>` | -| [DownloadImage](-download-image.md) | 异步下载图片, 图片宽高要求要么同时指定要么同时不指定 要求依赖 Glide`fun CoroutineScope.DownloadImage(url: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, with: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` = -1, height: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` = -1): Deferred<`[`File`](https://docs.oracle.com/javase/6/docs/api/java/io/File.html)`>` | -| [Get](-get.md) | 异步网络请求`fun CoroutineScope.Get(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = coroutineContext[CoroutineExceptionHandler], block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): Deferred` | -| [Head](-head.md) | 异步网络请求`fun CoroutineScope.Head(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = coroutineContext[CoroutineExceptionHandler], block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): Deferred` | -| [Options](-options.md) | 异步网络请求`fun CoroutineScope.Options(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = coroutineContext[CoroutineExceptionHandler], block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): Deferred` | -| [Patch](-patch.md) | 异步网络请求`fun CoroutineScope.Patch(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = coroutineContext[CoroutineExceptionHandler], block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): Deferred` | -| [Post](-post.md) | 异步网络请求`fun CoroutineScope.Post(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = coroutineContext[CoroutineExceptionHandler], block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): Deferred` | -| [Put](-put.md) | 异步网络请求`fun CoroutineScope.Put(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = coroutineContext[CoroutineExceptionHandler], block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): Deferred` | -| [Trace](-trace.md) | 异步网络请求`fun CoroutineScope.Trace(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = coroutineContext[CoroutineExceptionHandler], block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): Deferred` | +| [Delete](-delete.md) | `fun CoroutineScope.Delete(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`BodyRequest`](../../com.drake.net.request/-body-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): Deferred` | +| [Get](-get.md) | 异步网络请求`fun CoroutineScope.Get(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`UrlRequest`](../../com.drake.net.request/-url-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): Deferred` | +| [Head](-head.md) | `fun CoroutineScope.Head(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`UrlRequest`](../../com.drake.net.request/-url-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): Deferred` | +| [Options](-options.md) | `fun CoroutineScope.Options(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`UrlRequest`](../../com.drake.net.request/-url-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): Deferred` | +| [Patch](-patch.md) | `fun CoroutineScope.Patch(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`BodyRequest`](../../com.drake.net.request/-body-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): Deferred` | +| [Post](-post.md) | `fun CoroutineScope.Post(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`BodyRequest`](../../com.drake.net.request/-body-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): Deferred` | +| [Put](-put.md) | `fun CoroutineScope.Put(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`BodyRequest`](../../com.drake.net.request/-body-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): Deferred` | +| [Trace](-trace.md) | `fun CoroutineScope.Trace(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: (`[`UrlRequest`](../../com.drake.net.request/-url-request/index.md)`.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)? = null): Deferred` | diff --git a/docs/api/net/com.drake.net/sync-delete.md b/docs/api/net/com.drake.net/sync-delete.md deleted file mode 100644 index 7982b24db..000000000 --- a/docs/api/net/com.drake.net/sync-delete.md +++ /dev/null @@ -1,19 +0,0 @@ -[net](../index.md) / [com.drake.net](index.md) / [syncDelete](./sync-delete.md) - -# syncDelete - -`inline fun syncDelete(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, noinline block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): M` - -同步网络请求 - -### Parameters - -`path` - String 请求路径, 非绝对路径会加上[NetConfig.host](-net-config/host.md)为前缀 - -`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - -`absolutePath` - 请求路径是否是绝对路径 - -`uid` - 表示请求的唯一id, 和[NetCancel.cancel](#)中的uid一致, 一般用于指定取消网络请求的唯一id - -`block` - 函数中可以配置请求参数 \ No newline at end of file diff --git a/docs/api/net/com.drake.net/sync-download-body.md b/docs/api/net/com.drake.net/sync-download-body.md deleted file mode 100644 index 34ac4a280..000000000 --- a/docs/api/net/com.drake.net/sync-download-body.md +++ /dev/null @@ -1,19 +0,0 @@ -[net](../index.md) / [com.drake.net](index.md) / [syncDownloadBody](./sync-download-body.md) - -# syncDownloadBody - -`fun syncDownloadBody(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, dir: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = NetConfig.app.externalCacheDir!!.absolutePath, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, method: RequestMethod = RequestMethod.GET, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) - -同步文件下载, 允许提交请求体方式, 默认Post请求 - -### Parameters - -`path` - String 请求路径, 非绝对路径会加上[NetConfig.host](-net-config/host.md)为前缀 - -`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - -`absolutePath` - 请求路径是否是绝对路径 - -`uid` - 表示请求的唯一id, 和[NetCancel.cancel](#)中的uid一致, 一般用于指定取消网络请求的唯一id - -`block` - 函数中可以配置请求参数 \ No newline at end of file diff --git a/docs/api/net/com.drake.net/sync-download.md b/docs/api/net/com.drake.net/sync-download.md deleted file mode 100644 index 56b155665..000000000 --- a/docs/api/net/com.drake.net/sync-download.md +++ /dev/null @@ -1,19 +0,0 @@ -[net](../index.md) / [com.drake.net](index.md) / [syncDownload](./sync-download.md) - -# syncDownload - -`fun syncDownload(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, dir: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = NetConfig.app.externalCacheDir!!.absolutePath, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, method: RequestMethod = RequestMethod.GET, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) - -同步文件下载, 默认Get请求 - -### Parameters - -`path` - String 请求路径, 非绝对路径会加上[NetConfig.host](-net-config/host.md)为前缀 - -`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - -`absolutePath` - 请求路径是否是绝对路径 - -`uid` - 表示请求的唯一id, 和[NetCancel.cancel](#)中的uid一致, 一般用于指定取消网络请求的唯一id - -`block` - 函数中可以配置请求参数 \ No newline at end of file diff --git a/docs/api/net/com.drake.net/sync-get.md b/docs/api/net/com.drake.net/sync-get.md deleted file mode 100644 index 32c7a2214..000000000 --- a/docs/api/net/com.drake.net/sync-get.md +++ /dev/null @@ -1,19 +0,0 @@ -[net](../index.md) / [com.drake.net](index.md) / [syncGet](./sync-get.md) - -# syncGet - -`inline fun syncGet(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, noinline block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): M` - -同步网络请求 - -### Parameters - -`path` - String 请求路径, 非绝对路径会加上[NetConfig.host](-net-config/host.md)为前缀 - -`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - -`absolutePath` - 请求路径是否是绝对路径 - -`uid` - 表示请求的唯一id, 和[NetCancel.cancel](#)中的uid一致, 一般用于指定取消网络请求的唯一id - -`block` - 函数中可以配置请求参数 \ No newline at end of file diff --git a/docs/api/net/com.drake.net/sync-head.md b/docs/api/net/com.drake.net/sync-head.md deleted file mode 100644 index 29d88497c..000000000 --- a/docs/api/net/com.drake.net/sync-head.md +++ /dev/null @@ -1,19 +0,0 @@ -[net](../index.md) / [com.drake.net](index.md) / [syncHead](./sync-head.md) - -# syncHead - -`inline fun syncHead(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, noinline block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): M` - -同步网络请求 - -### Parameters - -`path` - String 请求路径, 非绝对路径会加上[NetConfig.host](-net-config/host.md)为前缀 - -`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - -`absolutePath` - 请求路径是否是绝对路径 - -`uid` - 表示请求的唯一id, 和[NetCancel.cancel](#)中的uid一致, 一般用于指定取消网络请求的唯一id - -`block` - 函数中可以配置请求参数 \ No newline at end of file diff --git a/docs/api/net/com.drake.net/sync-options.md b/docs/api/net/com.drake.net/sync-options.md deleted file mode 100644 index cc985b4be..000000000 --- a/docs/api/net/com.drake.net/sync-options.md +++ /dev/null @@ -1,19 +0,0 @@ -[net](../index.md) / [com.drake.net](index.md) / [syncOptions](./sync-options.md) - -# syncOptions - -`inline fun syncOptions(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, noinline block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): M` - -同步网络请求 - -### Parameters - -`path` - String 请求路径, 非绝对路径会加上[NetConfig.host](-net-config/host.md)为前缀 - -`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - -`absolutePath` - 请求路径是否是绝对路径 - -`uid` - 表示请求的唯一id, 和[NetCancel.cancel](#)中的uid一致, 一般用于指定取消网络请求的唯一id - -`block` - 函数中可以配置请求参数 \ No newline at end of file diff --git a/docs/api/net/com.drake.net/sync-patch.md b/docs/api/net/com.drake.net/sync-patch.md deleted file mode 100644 index 3efea59e5..000000000 --- a/docs/api/net/com.drake.net/sync-patch.md +++ /dev/null @@ -1,19 +0,0 @@ -[net](../index.md) / [com.drake.net](index.md) / [syncPatch](./sync-patch.md) - -# syncPatch - -`inline fun syncPatch(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, noinline block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): M` - -同步网络请求 - -### Parameters - -`path` - String 请求路径, 非绝对路径会加上[NetConfig.host](-net-config/host.md)为前缀 - -`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - -`absolutePath` - 请求路径是否是绝对路径 - -`uid` - 表示请求的唯一id, 和[NetCancel.cancel](#)中的uid一致, 一般用于指定取消网络请求的唯一id - -`block` - 函数中可以配置请求参数 \ No newline at end of file diff --git a/docs/api/net/com.drake.net/sync-post.md b/docs/api/net/com.drake.net/sync-post.md deleted file mode 100644 index bd34e5075..000000000 --- a/docs/api/net/com.drake.net/sync-post.md +++ /dev/null @@ -1,19 +0,0 @@ -[net](../index.md) / [com.drake.net](index.md) / [syncPost](./sync-post.md) - -# syncPost - -`inline fun syncPost(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, noinline block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): M` - -同步网络请求 - -### Parameters - -`path` - String 请求路径, 非绝对路径会加上[NetConfig.host](-net-config/host.md)为前缀 - -`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - -`absolutePath` - 请求路径是否是绝对路径 - -`uid` - 表示请求的唯一id, 和[NetCancel.cancel](#)中的uid一致, 一般用于指定取消网络请求的唯一id - -`block` - 函数中可以配置请求参数 \ No newline at end of file diff --git a/docs/api/net/com.drake.net/sync-put.md b/docs/api/net/com.drake.net/sync-put.md deleted file mode 100644 index 8d195e9f8..000000000 --- a/docs/api/net/com.drake.net/sync-put.md +++ /dev/null @@ -1,19 +0,0 @@ -[net](../index.md) / [com.drake.net](index.md) / [syncPut](./sync-put.md) - -# syncPut - -`inline fun syncPut(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, noinline block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): M` - -同步网络请求 - -### Parameters - -`path` - String 请求路径, 非绝对路径会加上[NetConfig.host](-net-config/host.md)为前缀 - -`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - -`absolutePath` - 请求路径是否是绝对路径 - -`uid` - 表示请求的唯一id, 和[NetCancel.cancel](#)中的uid一致, 一般用于指定取消网络请求的唯一id - -`block` - 函数中可以配置请求参数 \ No newline at end of file diff --git a/docs/api/net/com.drake.net/sync-trace.md b/docs/api/net/com.drake.net/sync-trace.md deleted file mode 100644 index eabb13d39..000000000 --- a/docs/api/net/com.drake.net/sync-trace.md +++ /dev/null @@ -1,19 +0,0 @@ -[net](../index.md) / [com.drake.net](index.md) / [syncTrace](./sync-trace.md) - -# syncTrace - -`inline fun syncTrace(path: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, tag: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, cache: CacheMode = CacheMode.HTTP, absolutePath: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, uid: `[`Any`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`? = null, noinline block: Api.() -> `[`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` = {}): M` - -同步网络请求 - -### Parameters - -`path` - String 请求路径, 非绝对路径会加上[NetConfig.host](-net-config/host.md)为前缀 - -`tag` - 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - -`absolutePath` - 请求路径是否是绝对路径 - -`uid` - 表示请求的唯一id, 和[NetCancel.cancel](#)中的uid一致, 一般用于指定取消网络请求的唯一id - -`block` - 函数中可以配置请求参数 \ No newline at end of file diff --git a/docs/api/net/index.md b/docs/api/net/index.md index 545c92425..c4b8346eb 100644 --- a/docs/api/net/index.md +++ b/docs/api/net/index.md @@ -4,9 +4,18 @@ | Name | Summary | |---|---| +| [androidx.lifecycle](androidx.lifecycle/index.md) | | | [com.drake.net](com.drake.net/index.md) | | +| [com.drake.net.body](com.drake.net.body/index.md) | | +| [com.drake.net.cache](com.drake.net.cache/index.md) | | +| [com.drake.net.component](com.drake.net.component/index.md) | | | [com.drake.net.convert](com.drake.net.convert/index.md) | | -| [com.drake.net.error](com.drake.net.error/index.md) | | +| [com.drake.net.exception](com.drake.net.exception/index.md) | | +| [com.drake.net.interceptor](com.drake.net.interceptor/index.md) | | +| [com.drake.net.interfaces](com.drake.net.interfaces/index.md) | | +| [com.drake.net.log](com.drake.net.log/index.md) | | +| [com.drake.net.request](com.drake.net.request/index.md) | | +| [com.drake.net.response](com.drake.net.response/index.md) | | | [com.drake.net.scope](com.drake.net.scope/index.md) | | | [com.drake.net.tag](com.drake.net.tag/index.md) | | | [com.drake.net.time](com.drake.net.time/index.md) | | diff --git a/docs/api/net/package-list b/docs/api/net/package-list index acdc05cd2..01683650e 100644 --- a/docs/api/net/package-list +++ b/docs/api/net/package-list @@ -1,46 +1,82 @@ $dokka.format:gfm $dokka.linkExtension:md -$dokka.location:com.drake.net$Delete(kotlinx.coroutines.CoroutineScope, kotlin.String, kotlin.Any, com.yanzhenjie.kalle.simple.cache.CacheMode, kotlin.Boolean, kotlin.Any, kotlin.Function1((com.yanzhenjie.kalle.simple.SimpleBodyRequest.Api, kotlin.Unit)))com.drake.net/kotlinx.coroutines.-coroutine-scope/-delete.md -$dokka.location:com.drake.net$Download(kotlinx.coroutines.CoroutineScope, kotlin.String, kotlin.String, kotlin.Any, kotlin.Boolean, com.yanzhenjie.kalle.RequestMethod, kotlin.Any, kotlin.Function1((com.yanzhenjie.kalle.download.UrlDownload.Api, kotlin.Unit)))com.drake.net/kotlinx.coroutines.-coroutine-scope/-download.md -$dokka.location:com.drake.net$DownloadBody(kotlinx.coroutines.CoroutineScope, kotlin.String, kotlin.String, kotlin.Any, kotlin.Boolean, com.yanzhenjie.kalle.RequestMethod, kotlin.Any, kotlin.Function1((com.yanzhenjie.kalle.download.BodyDownload.Api, kotlin.Unit)))com.drake.net/kotlinx.coroutines.-coroutine-scope/-download-body.md -$dokka.location:com.drake.net$DownloadImage(kotlinx.coroutines.CoroutineScope, kotlin.String, kotlin.Int, kotlin.Int)com.drake.net/kotlinx.coroutines.-coroutine-scope/-download-image.md -$dokka.location:com.drake.net$Get(kotlinx.coroutines.CoroutineScope, kotlin.String, kotlin.Any, com.yanzhenjie.kalle.simple.cache.CacheMode, kotlin.Boolean, kotlin.Any, kotlin.Function1((com.yanzhenjie.kalle.simple.SimpleUrlRequest.Api, kotlin.Unit)))com.drake.net/kotlinx.coroutines.-coroutine-scope/-get.md -$dokka.location:com.drake.net$Head(kotlinx.coroutines.CoroutineScope, kotlin.String, kotlin.Any, com.yanzhenjie.kalle.simple.cache.CacheMode, kotlin.Boolean, kotlin.Any, kotlin.Function1((com.yanzhenjie.kalle.simple.SimpleUrlRequest.Api, kotlin.Unit)))com.drake.net/kotlinx.coroutines.-coroutine-scope/-head.md -$dokka.location:com.drake.net$Options(kotlinx.coroutines.CoroutineScope, kotlin.String, kotlin.Any, com.yanzhenjie.kalle.simple.cache.CacheMode, kotlin.Boolean, kotlin.Any, kotlin.Function1((com.yanzhenjie.kalle.simple.SimpleUrlRequest.Api, kotlin.Unit)))com.drake.net/kotlinx.coroutines.-coroutine-scope/-options.md -$dokka.location:com.drake.net$Patch(kotlinx.coroutines.CoroutineScope, kotlin.String, kotlin.Any, com.yanzhenjie.kalle.simple.cache.CacheMode, kotlin.Boolean, kotlin.Any, kotlin.Function1((com.yanzhenjie.kalle.simple.SimpleBodyRequest.Api, kotlin.Unit)))com.drake.net/kotlinx.coroutines.-coroutine-scope/-patch.md -$dokka.location:com.drake.net$Post(kotlinx.coroutines.CoroutineScope, kotlin.String, kotlin.Any, com.yanzhenjie.kalle.simple.cache.CacheMode, kotlin.Boolean, kotlin.Any, kotlin.Function1((com.yanzhenjie.kalle.simple.SimpleBodyRequest.Api, kotlin.Unit)))com.drake.net/kotlinx.coroutines.-coroutine-scope/-post.md -$dokka.location:com.drake.net$Put(kotlinx.coroutines.CoroutineScope, kotlin.String, kotlin.Any, com.yanzhenjie.kalle.simple.cache.CacheMode, kotlin.Boolean, kotlin.Any, kotlin.Function1((com.yanzhenjie.kalle.simple.SimpleBodyRequest.Api, kotlin.Unit)))com.drake.net/kotlinx.coroutines.-coroutine-scope/-put.md -$dokka.location:com.drake.net$Trace(kotlinx.coroutines.CoroutineScope, kotlin.String, kotlin.Any, com.yanzhenjie.kalle.simple.cache.CacheMode, kotlin.Boolean, kotlin.Any, kotlin.Function1((com.yanzhenjie.kalle.simple.SimpleUrlRequest.Api, kotlin.Unit)))com.drake.net/kotlinx.coroutines.-coroutine-scope/-trace.md -$dokka.location:com.drake.net$cacheEnabled(com.yanzhenjie.kalle.KalleConfig.Builder, kotlin.String, kotlin.String)com.drake.net/com.yanzhenjie.kalle.-kalle-config.-builder/cache-enabled.md -$dokka.location:com.drake.net$initNet(android.app.Application, kotlin.String, kotlin.Function1((com.yanzhenjie.kalle.KalleConfig.Builder, kotlin.Unit)))com.drake.net/android.app.-application/init-net.md -$dokka.location:com.drake.net$onDialog(com.yanzhenjie.kalle.KalleConfig.Builder, kotlin.Function2((com.drake.net.scope.DialogCoroutineScope, androidx.fragment.app.FragmentActivity, android.app.Dialog)))com.drake.net/com.yanzhenjie.kalle.-kalle-config.-builder/on-dialog.md -$dokka.location:com.drake.net$onError(com.yanzhenjie.kalle.KalleConfig.Builder, kotlin.Function1((kotlin.Throwable, kotlin.Unit)))com.drake.net/com.yanzhenjie.kalle.-kalle-config.-builder/on-error.md -$dokka.location:com.drake.net$onStateError(com.yanzhenjie.kalle.KalleConfig.Builder, kotlin.Function2((kotlin.Throwable, android.view.View, kotlin.Unit)))com.drake.net/com.yanzhenjie.kalle.-kalle-config.-builder/on-state-error.md -$dokka.location:com.drake.net$syncDownloadImage(android.content.Context, kotlin.String, kotlin.Int, kotlin.Int)com.drake.net/android.content.-context/sync-download-image.md -$dokka.location:com.drake.net.error$NetCancellationException(kotlinx.coroutines.CoroutineScope, kotlin.String)com.drake.net.error/kotlinx.coroutines.-coroutine-scope/-net-cancellation-exception.md +$dokka.location:com.drake.net$Delete(kotlinx.coroutines.CoroutineScope, kotlin.String, kotlin.Any, kotlin.Function1((com.drake.net.request.BodyRequest, kotlin.Unit)))com.drake.net/kotlinx.coroutines.-coroutine-scope/-delete.md +$dokka.location:com.drake.net$Get(kotlinx.coroutines.CoroutineScope, kotlin.String, kotlin.Any, kotlin.Function1((com.drake.net.request.UrlRequest, kotlin.Unit)))com.drake.net/kotlinx.coroutines.-coroutine-scope/-get.md +$dokka.location:com.drake.net$Head(kotlinx.coroutines.CoroutineScope, kotlin.String, kotlin.Any, kotlin.Function1((com.drake.net.request.UrlRequest, kotlin.Unit)))com.drake.net/kotlinx.coroutines.-coroutine-scope/-head.md +$dokka.location:com.drake.net$Options(kotlinx.coroutines.CoroutineScope, kotlin.String, kotlin.Any, kotlin.Function1((com.drake.net.request.UrlRequest, kotlin.Unit)))com.drake.net/kotlinx.coroutines.-coroutine-scope/-options.md +$dokka.location:com.drake.net$Patch(kotlinx.coroutines.CoroutineScope, kotlin.String, kotlin.Any, kotlin.Function1((com.drake.net.request.BodyRequest, kotlin.Unit)))com.drake.net/kotlinx.coroutines.-coroutine-scope/-patch.md +$dokka.location:com.drake.net$Post(kotlinx.coroutines.CoroutineScope, kotlin.String, kotlin.Any, kotlin.Function1((com.drake.net.request.BodyRequest, kotlin.Unit)))com.drake.net/kotlinx.coroutines.-coroutine-scope/-post.md +$dokka.location:com.drake.net$Put(kotlinx.coroutines.CoroutineScope, kotlin.String, kotlin.Any, kotlin.Function1((com.drake.net.request.BodyRequest, kotlin.Unit)))com.drake.net/kotlinx.coroutines.-coroutine-scope/-put.md +$dokka.location:com.drake.net$Trace(kotlinx.coroutines.CoroutineScope, kotlin.String, kotlin.Any, kotlin.Function1((com.drake.net.request.UrlRequest, kotlin.Unit)))com.drake.net/kotlinx.coroutines.-coroutine-scope/-trace.md +$dokka.location:com.drake.net.body$addListener(okhttp3.RequestBody, java.util.concurrent.ConcurrentLinkedQueue((com.drake.net.request.ProgressListener)))com.drake.net.body/okhttp3.-request-body/add-listener.md +$dokka.location:com.drake.net.body$addListener(okhttp3.ResponseBody, okhttp3.Request)com.drake.net.body/okhttp3.-response-body/add-listener.md +$dokka.location:com.drake.net.exception$NetCancellationException(kotlinx.coroutines.CoroutineScope, kotlin.String)com.drake.net.exception/kotlinx.coroutines.-coroutine-scope/-net-cancellation-exception.md +$dokka.location:com.drake.net.request$FORM#okhttp3.MediaType.Companioncom.drake.net.request/okhttp3.-media-type/-f-o-r-m.md +$dokka.location:com.drake.net.request$GIF#okhttp3.MediaType.Companioncom.drake.net.request/okhttp3.-media-type/-g-i-f.md +$dokka.location:com.drake.net.request$HTML#okhttp3.MediaType.Companioncom.drake.net.request/okhttp3.-media-type/-h-t-m-l.md +$dokka.location:com.drake.net.request$IMG#okhttp3.MediaType.Companioncom.drake.net.request/okhttp3.-media-type/-i-m-g.md +$dokka.location:com.drake.net.request$JPEG#okhttp3.MediaType.Companioncom.drake.net.request/okhttp3.-media-type/-j-p-e-g.md +$dokka.location:com.drake.net.request$JSON#okhttp3.MediaType.Companioncom.drake.net.request/okhttp3.-media-type/-j-s-o-n.md +$dokka.location:com.drake.net.request$MP4#okhttp3.MediaType.Companioncom.drake.net.request/okhttp3.-media-type/-m-p4.md +$dokka.location:com.drake.net.request$PNG#okhttp3.MediaType.Companioncom.drake.net.request/okhttp3.-media-type/-p-n-g.md +$dokka.location:com.drake.net.request$TXT#okhttp3.MediaType.Companioncom.drake.net.request/okhttp3.-media-type/-t-x-t.md +$dokka.location:com.drake.net.request$URLENCODED#okhttp3.MediaType.Companioncom.drake.net.request/okhttp3.-media-type/-u-r-l-e-n-c-o-d-e-d.md +$dokka.location:com.drake.net.request$XML#okhttp3.MediaType.Companioncom.drake.net.request/okhttp3.-media-type/-x-m-l.md +$dokka.location:com.drake.net.request$converter(okhttp3.Request)com.drake.net.request/okhttp3.-request/converter.md +$dokka.location:com.drake.net.request$downloadConflictRename(okhttp3.Request)com.drake.net.request/okhttp3.-request/download-conflict-rename.md +$dokka.location:com.drake.net.request$downloadFileDir(okhttp3.Request)com.drake.net.request/okhttp3.-request/download-file-dir.md +$dokka.location:com.drake.net.request$downloadFileNameDecode(okhttp3.Request)com.drake.net.request/okhttp3.-request/download-file-name-decode.md +$dokka.location:com.drake.net.request$downloadListeners(okhttp3.Request)com.drake.net.request/okhttp3.-request/download-listeners.md +$dokka.location:com.drake.net.request$downloadMd5Verify(okhttp3.Request)com.drake.net.request/okhttp3.-request/download-md5-verify.md +$dokka.location:com.drake.net.request$downloadTempFile(okhttp3.Request)com.drake.net.request/okhttp3.-request/download-temp-file.md +$dokka.location:com.drake.net.request$fileName(okhttp3.Request)com.drake.net.request/okhttp3.-request/file-name.md +$dokka.location:com.drake.net.request$group(okhttp3.Request)com.drake.net.request/okhttp3.-request/group.md +$dokka.location:com.drake.net.request$id(okhttp3.Request)com.drake.net.request/okhttp3.-request/id.md +$dokka.location:com.drake.net.request$label(okhttp3.Request)com.drake.net.request/okhttp3.-request/label.md +$dokka.location:com.drake.net.request$setConverter(okhttp3.Request.Builder, com.drake.net.convert.NetConverter)com.drake.net.request/okhttp3.-request.-builder/set-converter.md +$dokka.location:com.drake.net.request$setGroup(okhttp3.Request.Builder, kotlin.Any)com.drake.net.request/okhttp3.-request.-builder/set-group.md +$dokka.location:com.drake.net.request$setId(okhttp3.Request.Builder, kotlin.Any)com.drake.net.request/okhttp3.-request.-builder/set-id.md +$dokka.location:com.drake.net.request$setLabel(okhttp3.Request.Builder, com.drake.net.request.setLabel.T)com.drake.net.request/okhttp3.-request.-builder/set-label.md +$dokka.location:com.drake.net.request$tag(okhttp3.Request, kotlin.String)com.drake.net.request/okhttp3.-request/tag.md +$dokka.location:com.drake.net.request$uploadListeners(okhttp3.Request)com.drake.net.request/okhttp3.-request/upload-listeners.md +$dokka.location:com.drake.net.response$file(okhttp3.Response)com.drake.net.response/okhttp3.-response/file.md +$dokka.location:com.drake.net.response$fileName(okhttp3.Response)com.drake.net.response/okhttp3.-response/file-name.md $dokka.location:com.drake.net.transform$transform(kotlinx.coroutines.Deferred((com.drake.net.transform.transform.T)), kotlin.Function1((com.drake.net.transform.transform.T, com.drake.net.transform.transform.R)))com.drake.net.transform/kotlinx.coroutines.-deferred/transform.md -$dokka.location:com.drake.net.utils$fastest(kotlinx.coroutines.CoroutineScope, kotlin.Array((com.drake.net.transform.DeferredTransform((com.drake.net.utils.fastest.T, com.drake.net.utils.fastest.R)))))com.drake.net.utils/kotlinx.coroutines.-coroutine-scope/fastest.md -$dokka.location:com.drake.net.utils$fastest(kotlinx.coroutines.CoroutineScope, kotlin.Array((kotlinx.coroutines.Deferred((com.drake.net.utils.fastest.T)))))com.drake.net.utils/kotlinx.coroutines.-coroutine-scope/fastest.md -$dokka.location:com.drake.net.utils$fastest(kotlinx.coroutines.CoroutineScope, kotlin.collections.List((com.drake.net.transform.DeferredTransform((com.drake.net.utils.fastest.T, com.drake.net.utils.fastest.R)))))com.drake.net.utils/kotlinx.coroutines.-coroutine-scope/fastest.md -$dokka.location:com.drake.net.utils$fastest(kotlinx.coroutines.CoroutineScope, kotlin.collections.List((kotlinx.coroutines.Deferred((com.drake.net.utils.fastest.T)))))com.drake.net.utils/kotlinx.coroutines.-coroutine-scope/fastest.md -$dokka.location:com.drake.net.utils$foreach(android.database.Cursor, kotlin.Function1((android.database.Cursor, kotlin.Unit)))com.drake.net.utils/android.database.-cursor/foreach.md -$dokka.location:com.drake.net.utils$getSavedModel(androidx.fragment.app.Fragment)com.drake.net.utils/androidx.fragment.app.-fragment/get-saved-model.md -$dokka.location:com.drake.net.utils$getSavedModel(androidx.fragment.app.FragmentActivity)com.drake.net.utils/androidx.fragment.app.-fragment-activity/get-saved-model.md -$dokka.location:com.drake.net.utils$getViewModel(androidx.lifecycle.ViewModelStoreOwner)com.drake.net.utils/androidx.lifecycle.-view-model-store-owner/get-view-model.md -$dokka.location:com.drake.net.utils$listen(kotlinx.coroutines.flow.Flow((kotlin.collections.List((com.drake.net.utils.listen.T)))), androidx.lifecycle.LifecycleOwner, androidx.lifecycle.Lifecycle.Event, kotlinx.coroutines.CoroutineDispatcher, kotlin.Function1((kotlin.collections.List((com.drake.net.utils.listen.T)), kotlin.Unit)))com.drake.net.utils/kotlinx.coroutines.flow.-flow/listen.md -$dokka.location:com.drake.net.utils$observe(androidx.lifecycle.LifecycleOwner, androidx.lifecycle.LiveData((com.drake.net.utils.observe.M)), kotlin.Function1((com.drake.net.utils.observe.M, kotlin.Unit)))com.drake.net.utils/androidx.lifecycle.-lifecycle-owner/observe.md +$dokka.location:com.drake.net.utils$cancelGroup(okhttp3.OkHttpClient, kotlin.Any)com.drake.net.utils/okhttp3.-ok-http-client/cancel-group.md +$dokka.location:com.drake.net.utils$cancelId(okhttp3.OkHttpClient, kotlin.Any)com.drake.net.utils/okhttp3.-ok-http-client/cancel-id.md +$dokka.location:com.drake.net.utils$debounce(android.widget.EditText, kotlin.Long)com.drake.net.utils/android.widget.-edit-text/debounce.md +$dokka.location:com.drake.net.utils$fastest(kotlinx.coroutines.CoroutineScope, kotlin.collections.List((com.drake.net.transform.DeferredTransform((com.drake.net.utils.fastest.T, com.drake.net.utils.fastest.R)))), kotlin.Any)com.drake.net.utils/kotlinx.coroutines.-coroutine-scope/fastest.md +$dokka.location:com.drake.net.utils$fastest(kotlinx.coroutines.CoroutineScope, kotlin.collections.List((kotlinx.coroutines.Deferred((com.drake.net.utils.fastest.T)))), kotlin.Any)com.drake.net.utils/kotlinx.coroutines.-coroutine-scope/fastest.md +$dokka.location:com.drake.net.utils$isValid#kotlin.Stringcom.drake.net.utils/kotlin.-string/is-valid.md +$dokka.location:com.drake.net.utils$isValid(kotlin.String, kotlin.Function1((kotlin.String, kotlin.Unit)))com.drake.net.utils/kotlin.-string/is-valid.md +$dokka.location:com.drake.net.utils$listen(kotlinx.coroutines.flow.Flow((com.drake.net.utils.listen.T)), androidx.lifecycle.LifecycleOwner, androidx.lifecycle.Lifecycle.Event, kotlinx.coroutines.CoroutineDispatcher, kotlin.coroutines.SuspendFunction2((kotlinx.coroutines.CoroutineScope, com.drake.net.utils.listen.T, kotlin.Unit)))com.drake.net.utils/kotlinx.coroutines.flow.-flow/listen.md +$dokka.location:com.drake.net.utils$md5(java.io.File)com.drake.net.utils/java.io.-file/md5.md +$dokka.location:com.drake.net.utils$onDialog(okhttp3.OkHttpClient.Builder, kotlin.Function2((com.drake.net.scope.DialogCoroutineScope, androidx.fragment.app.FragmentActivity, android.app.Dialog)))com.drake.net.utils/okhttp3.-ok-http-client.-builder/on-dialog.md +$dokka.location:com.drake.net.utils$onError(okhttp3.OkHttpClient.Builder, kotlin.Function1((kotlin.Throwable, kotlin.Unit)))com.drake.net.utils/okhttp3.-ok-http-client.-builder/on-error.md +$dokka.location:com.drake.net.utils$onStateError(okhttp3.OkHttpClient.Builder, kotlin.Function2((kotlin.Throwable, android.view.View, kotlin.Unit)))com.drake.net.utils/okhttp3.-ok-http-client.-builder/on-state-error.md $dokka.location:com.drake.net.utils$scope(com.drake.brv.PageRefreshLayout, kotlinx.coroutines.CoroutineDispatcher, kotlin.coroutines.SuspendFunction1((kotlinx.coroutines.CoroutineScope, kotlin.Unit)))com.drake.net.utils/com.drake.brv.-page-refresh-layout/scope.md $dokka.location:com.drake.net.utils$scope(com.drake.statelayout.StateLayout, kotlinx.coroutines.CoroutineDispatcher, kotlin.coroutines.SuspendFunction1((kotlinx.coroutines.CoroutineScope, kotlin.Unit)))com.drake.net.utils/com.drake.statelayout.-state-layout/scope.md -$dokka.location:com.drake.net.utils$scope(kotlinx.coroutines.flow.Flow((com.drake.net.utils.scope.T)), androidx.lifecycle.LifecycleOwner, androidx.lifecycle.Lifecycle.Event, kotlinx.coroutines.CoroutineDispatcher, kotlin.coroutines.SuspendFunction1((com.drake.net.utils.scope.T, kotlin.Unit)))com.drake.net.utils/kotlinx.coroutines.flow.-flow/scope.md +$dokka.location:com.drake.net.utils$scope(kotlinx.coroutines.flow.Flow((com.drake.net.utils.scope.T)), androidx.lifecycle.LifecycleOwner, androidx.lifecycle.Lifecycle.Event, kotlinx.coroutines.CoroutineDispatcher, kotlin.coroutines.SuspendFunction2((kotlinx.coroutines.CoroutineScope, com.drake.net.utils.scope.T, kotlin.Unit)))com.drake.net.utils/kotlinx.coroutines.flow.-flow/scope.md $dokka.location:com.drake.net.utils$scopeDialog(androidx.fragment.app.Fragment, android.app.Dialog, kotlin.Boolean, kotlinx.coroutines.CoroutineDispatcher, kotlin.coroutines.SuspendFunction1((kotlinx.coroutines.CoroutineScope, kotlin.Unit)))com.drake.net.utils/androidx.fragment.app.-fragment/scope-dialog.md $dokka.location:com.drake.net.utils$scopeDialog(androidx.fragment.app.FragmentActivity, android.app.Dialog, kotlin.Boolean, kotlinx.coroutines.CoroutineDispatcher, kotlin.coroutines.SuspendFunction1((kotlinx.coroutines.CoroutineScope, kotlin.Unit)))com.drake.net.utils/androidx.fragment.app.-fragment-activity/scope-dialog.md $dokka.location:com.drake.net.utils$scopeLife(androidx.fragment.app.Fragment, androidx.lifecycle.Lifecycle.Event, kotlinx.coroutines.CoroutineDispatcher, kotlin.coroutines.SuspendFunction1((kotlinx.coroutines.CoroutineScope, kotlin.Unit)))com.drake.net.utils/androidx.fragment.app.-fragment/scope-life.md -$dokka.location:com.drake.net.utils$scopeLife(androidx.lifecycle.LifecycleOwner, androidx.lifecycle.Lifecycle.Event, kotlinx.coroutines.CoroutineDispatcher, kotlin.coroutines.SuspendFunction1((kotlinx.coroutines.CoroutineScope, kotlin.Unit)))com.drake.net.utils/androidx.lifecycle.-lifecycle-owner/scope-life.md $dokka.location:com.drake.net.utils$scopeNetLife(androidx.fragment.app.Fragment, androidx.lifecycle.Lifecycle.Event, kotlinx.coroutines.CoroutineDispatcher, kotlin.coroutines.SuspendFunction1((kotlinx.coroutines.CoroutineScope, kotlin.Unit)))com.drake.net.utils/androidx.fragment.app.-fragment/scope-net-life.md -$dokka.location:com.drake.net.utils$scopeNetLife(androidx.lifecycle.LifecycleOwner, androidx.lifecycle.Lifecycle.Event, kotlinx.coroutines.CoroutineDispatcher, kotlin.coroutines.SuspendFunction1((kotlinx.coroutines.CoroutineScope, kotlin.Unit)))com.drake.net.utils/androidx.lifecycle.-lifecycle-owner/scope-net-life.md +$dokka.location:com.drake.net.utils$setConverter(okhttp3.OkHttpClient.Builder, com.drake.net.convert.NetConverter)com.drake.net.utils/okhttp3.-ok-http-client.-builder/set-converter.md +$dokka.location:com.drake.net.utils$setHost(okhttp3.OkHttpClient.Builder, kotlin.String)com.drake.net.utils/okhttp3.-ok-http-client.-builder/set-host.md +$dokka.location:com.drake.net.utils$setLog(okhttp3.OkHttpClient.Builder, kotlin.Boolean)com.drake.net.utils/okhttp3.-ok-http-client.-builder/set-log.md +$dokka.location:com.drake.net.utils$setRequestInterceptor(okhttp3.OkHttpClient.Builder, com.drake.net.interceptor.RequestInterceptor)com.drake.net.utils/okhttp3.-ok-http-client.-builder/set-request-interceptor.md +androidx.lifecycle com.drake.net +com.drake.net.body +com.drake.net.cache +com.drake.net.component com.drake.net.convert -com.drake.net.error +com.drake.net.exception +com.drake.net.interceptor +com.drake.net.interfaces +com.drake.net.log +com.drake.net.request +com.drake.net.response com.drake.net.scope com.drake.net.tag com.drake.net.time diff --git a/docs/auto-dialog.md b/docs/auto-dialog.md index 3ae8e1865..7f479d3c8 100644 --- a/docs/auto-dialog.md +++ b/docs/auto-dialog.md @@ -26,7 +26,7 @@ scopeDialog { === "初始化" ```kotlin - initNet("http://182.92.97.186/") { + initNet("http://github.com/") { onDialog { // lambda返回一个Dialog对象 ProgressDialog(it).apply { // it 为 FragmentActivity setMessage("正在努力请求中") diff --git a/docs/cancel.md b/docs/cancel.md index 5605f4dde..4cc970ae1 100644 --- a/docs/cancel.md +++ b/docs/cancel.md @@ -6,7 +6,7 @@ Net取消协程作用域自动取消内部网络请求, 也支持任意位置取 ```kotlin downloadScope = scopeNetLife { // 下载文件 - Download("download", requireContext().filesDir.path).await() + val file = Get("download").await() } downloadScope.cancel() // 取消下载 @@ -15,7 +15,7 @@ downloadScope.cancel() // 取消下载 ## 任意位置取消 -发起请求的时候要求定义一个`UID`用于指定网络请求, 然后在需要的地方使用单例对象`NetCancel`取消请求. +发起请求的时候要求定义一个`Id`用于指定网络请求, 然后在需要的地方使用单例对象`Net.cancelId`取消请求. 创建请求 ```kotlin @@ -24,24 +24,16 @@ scopeNetLife { } ``` -然后根据uid取消网络请求 +然后根据Id取消网络请求 ```kotlin -NetCancel.cancel("请求用户信息") -``` +Net.cancelId("请求用户信息") -
+Net.cancelGroup("请求分组名称") // 设置分组 +``` -> 需要注意的是一旦为网络请求设置UID你就无法在作用域执行完毕自动取消网络请求了, 因为自动取消的原理就是使用作用域 -的上下文错误处理器来作为UID +如果你要问我请求的Group和Id有什么区别, 其实本质上两者基本上没区别, 只是为了适配不同场景下使用. +
-```kotlin hl_lines="6" -inline fun CoroutineScope.Get( - path: String, - tag: Any? = null, - cache: CacheMode = CacheMode.HTTP, - absolutePath: Boolean = false, - uid: Any? = coroutineContext[CoroutineExceptionHandler], - noinline block: SimpleUrlRequest.Api.() -> Unit = {} -): Deferred = async(Dispatchers.IO) -``` \ No newline at end of file +> 需要注意的是一旦为网络请求设置分组`setGroup`你就无法在作用域执行完毕自动取消网络请求了, 因为自动取消的原理就是使用作用域 +的上下文来作为Group \ No newline at end of file diff --git a/docs/config.md b/docs/config.md index 254d0f38b..281909539 100644 --- a/docs/config.md +++ b/docs/config.md @@ -1,35 +1,59 @@ -全局配置推荐在Application中设置 -```kotlin -class App : Application() { - override fun onCreate() { - super.onCreate() - - // http://182.92.97.186/ 这是接口全局域名, 可以使用NetConfig.host读写 - initNet("http://182.92.97.186/") { - - // 大括号内部都是可选项配置 - - converter(MoshiConvert()) // 转换器 - cacheEnabled() // 开启缓存 - setLogRecord(BuildConfig.DEBUG) // 日志记录器 - logEnabled = BuildConfig.DEBUG // LogCat异常日志 - addHeader("键" ,"值") // 全局请求头 - setHeader("覆盖键" ,"值") // 全局请求头, 键相同会覆盖 - addParam("键" ,"值") // 全局参数 +全局配置建议在Application中设置 + +=== "普通初始化" + + ```kotlin + class App : Application() { + override fun onCreate() { + super.onCreate() + + // http://google.com/ 这是接口全局域名, 可以使用NetConfig.host进行单独的修改 + + initNet("http://github.com/") { + setLog(BuildConfig.DEBUG) // 日志记录器 + setConverter(GsonConvert()) // 转换器 + } } } -} -``` + ``` -> 假设全局参数属于动态获取的, 应当使用拦截器, 在拦截器里面添加 +=== "OkHttpClient.Builder" -initNet 作用域内可选函数 + ```kotlin + class App : Application() { + override fun onCreate() { + super.onCreate() - + // http://google.com/ 这是接口全局域名, 可以使用NetConfig.host进行单独的修改 + val okHttpClientBuilder = OkHttpClient.Builder() + .setLog(BuildConfig.DEBUG) + .setConverter(GsonConvert()) + .addInterceptor(LogRecordInterceptor(BuildConfig.DEBUG)) + + initNet("http://github.com/", okHttpClientBuilder) + } + } + ``` + +> 配置都是可选项, 不是不初始化就不能使用 + +在initNet函数作用域中的this属于`OkHttpClient.Builder()`, 可以配置任何OkHttp参数选项 + +| 函数 | 描述 | +|-|-| +| setLog | 日志 | +| setHost | 全局域名, 和initNet("Host")函数中的第一个参数等效 | +| setConverter | [转换器](converter.md) | +| setRequestInterceptor | [请求拦截器](interceptor.md) | +| onError | [全局错误处理](error-handle.md) | +| onStateError | [全局缺省页错误处理](error-handle.md) | +| onDialog | [全局对话框](auto-dialog.md) | ## 动态配置 -单例对象[NetConfig](api/net/com.drake.net/-net-config/index.md)存储了初始化时的配置, 可以后期动态读写. +单例[NetConfig](api/net/com.drake.net/-net-config/index.md)存储了初始化时的配置, 可以后期动态读写. + +例如Retrofit的动态`BaseURL`功能就可以直接修改`NetConfig.host` -例如Retrofit的`baseUrl`功能就可以直接修改`NetConfig.host` + diff --git a/docs/convert-data-field.md b/docs/convert-data-field.md new file mode 100644 index 000000000..a903404fe --- /dev/null +++ b/docs/convert-data-field.md @@ -0,0 +1,93 @@ + +## 转换完整的JSON + +一般的解析过程是以下 + +1) 后端返回的JSON数据 + +```json +{ + "code":200, + "msg":"错误信息", + "data": { + "name": "彭于晏" + } +} +``` + +2) 创建数据模型 + +```kotlin +data class UserInfo ( + var code:Int, + var msg:String, + var data:Info, +) { + +} +``` + +3) 发起网络请求 + +```kotlin +scopeNetLife { + val data = Get("/list").await().data +} +``` + +## 仅转换Data字段 + +这样每次都要`await().data`才是你要的`data`对象. 有些人就想省略直接不写code和msg, 希望直接返回data. 那么在转换器里面就只解析data字段即可 + +简化数据对象 + +```kotlin +data class Info (var name:String) +``` + +转换器只解析data字段 + +```kotlin +class GsonConvert : JSONConvert(code = "code", message = "msg", success = "200") { + private val gson = GsonBuilder().serializeNulls().create() + + override fun String.parseBody(succeed: Type): S? { + val data = JSONObject(this).getString("data") + return gson.fromJson(data, succeed) + } +} +``` + +使用简化的数据对象作为泛型 + +```kotlin +scopeNetLife { + val data = Get("/list").await().data +} +``` + +## 使用泛型数据对象 + +这种方式在Retrofit中经常被使用到, 可能某些人比较习惯 + +数据对象 + +```kotlin +// 数据对象的基类 +open class BaseResult { + var code: Int = 0 + var msg: String = "" + var data: T? = null +} + +class Result(var request_method: String) : BaseResult() +``` + +使用泛型 + +```kotlin +scopeNetLife { + val data = Get("api").await().request_method +} +``` + diff --git a/docs/convert-json-array.md b/docs/convert-json-array.md new file mode 100644 index 000000000..44fd80696 --- /dev/null +++ b/docs/convert-json-array.md @@ -0,0 +1,91 @@ +首先我们知道Net可以通过泛型指定返回的数据类型 + +```kotlin +scopeNetLife { + tv_fragment.text = Post("api").await() +} +``` + +如果是你解析的JSON对象中包含集合, 这种情况完全无需考虑. 直接解析JSON数组字段-data 才会存在以上的问题 + +```json +{ + "code":200, + "msg":"错误信息", + "data": [ + { "name": "彭于晏" }, + { "name": "彭于晏" }, + { "name": "彭于晏" } + ] +} +``` + +如果后端直接返回JSON数组 + +```json +[ + { "name": "彭于晏" }, + { "name": "彭于晏" }, + { "name": "彭于晏" } +] +``` + +你们可能会这么写 + +```kotlin +scopeNetLife { + tv_fragment.text = Post>("api").await() +} +``` + +> 但是由于Java的泛型擦除机制, 这么会发生异常无法转换成正确的数据返回 + + +解决办法 + +1. 泛型使用Array替换List +2. 泛型使用String, 然后写扩展函数转换下 + +## 使用Array + +```kotlin +scopeNetLife { + val arr = Post>("api").await() + arr.toMutableList() // 如果你就是要求集合, 可以使用函数将数组转换成集合 +} +``` + +## 使用扩展函数 + +我们可以直接使用String创建一个扩展函数 + + +### 1. 定义解析函数 + +创建一个顶层函数(即在类之外的函数, 直接存在kt文件中) + +FastJSON解析库演示 + +```kotlin +inline fun String.toJsonArray(): MutableList { + return JSON.parseArray(this, T::class.java) +} +``` + +Gson解析库演示 + +```kotlin +inline fun String.toJsonArray(): MutableList { + return Gson().fromJson(this, TypeToken.getParameterized(List::class.java, T::class.java).type) +} +``` + +### 2. 使用 + +```kotlin +scopeNetLife { + val listData = Post("/list").await().toJsonArray() +} +``` + +> 该扩展函数太简单我就不加入到框架中了, 大家复制粘贴下就OK了 \ No newline at end of file diff --git a/docs/convert.md b/docs/converter.md similarity index 55% rename from docs/convert.md rename to docs/converter.md index 992a8ad80..7dae2dee8 100644 --- a/docs/convert.md +++ b/docs/converter.md @@ -1,6 +1,6 @@ 如果你想要网络请求直接返回对应的Bean或者说POJO类你就要创建自定义的转换器, 来使用JSON解析框架处理你的数据(当然你可能是使用的protocol等其他数据格式) -在Net中转换器([Convert](https://github.com/liangjingkanji/Net/blob/master/kalle/src/main/java/com/yanzhenjie/kalle/simple/Converter.kt))负责数据解析的工作, 自定义转换器即实现Convert接口即可 +在Net中转换器NetConverter负责数据解析的工作, 自定义转换器即实现NetConverter接口即可 > 你的业务可能需要请求参数加密或者拼接一串特殊含义的参数, 或者响应信息需要解密. 请不要尝试封装Post或者Get等请求函数(这是蠢材做法), 自定义拦截器和转换器可以应对任何项目需求. @@ -12,7 +12,7 @@ ## 创建转换器 -一般情况我们可以直接继承[DefaultConvert](api/net/com.drake.net.convert/-default-convert/index.md) +一般情况我们可以直接继承JSONConvert(因为一般接口使用的是JSON返回) === "Gson" ```kotlin @@ -56,7 +56,6 @@ | success | 即`成功码`的值等于指定时才算网络请求成功 |
- > 注意解析器(Gson或者Moshi)的对象记得定义为类成员, 这样可以不会导致每次解析都要创建一个新的对象, 减少内存消耗
@@ -66,15 +65,15 @@ === "全局" ```kotlin hl_lines="2" - initNet("http://182.92.97.186/") { - converter(JsonConvert()) + initNet("http://github.com/") { + setConverter(GsonConvert()) } ``` === "单例" ```kotlin hl_lines="3" scopeNetLife { tv_fragment.text = Get("api"){ - convert(JsonConvert()) + converter = JsonConvert() }.await() } ``` @@ -82,47 +81,74 @@ ## 自定义转换器 -[DefaultConvert](https://github.com/liangjingkanji/Net/blob/master/net/src/main/java/com/drake/net/convert/DefaultConvert.kt) 实际上也只是实现Convert接口的一个抽象类 +通过实现`NetConverter`接口可以编写自己的逻辑网络请求返回的数据, `NetConvert.DEFAULT`为默认的转换器支持返回File/String/Response等 -> 当你对DefaultConvert有更多需求或者功能扩展的话可以重写DefaultConvert的`convert`函数, 或直接实现Convert接口 +```kotlin +val DEFAULT = object : NetConverter { + + override fun onConvert( + succeed: Type, + response: Response + ): R? { + return when (succeed) { + String::class.java -> response.body?.string() as R + ByteString::class.java -> response.body?.byteString() as R + ByteArray::class.java -> response.body?.bytes() as R + Response::class.java -> response as R + File::class.java -> response.file() as R + else -> throw ConvertException( + response, + "The default converter does not support this type" + ) + } + } +} +``` + +框架中自带一个`JSONConverter`可以作为参考或者直接使用. 其可以转换JSON数据. 源码如下 ```kotlin -abstract class DefaultConvert( +abstract class JSONConvert( val success: String = "0", val code: String = "code", val message: String = "msg" -) : Converter { - - override fun convert( - succeed: Type, - request: Request, - response: Response, - cache: Boolean - ): S? { - val body = response.body().string() - response.log = body // 日志记录响应信息 - val code = response.code() - when { - code in 200..299 -> { // 请求成功 - val jsonObject = JSONObject(body) // 获取JSON中后端定义的错误码和错误信息 - if (jsonObject.getString(this.code) == success) { // 对比后端自定义错误码 - return if (succeed === String::class.java) body as S else body.parseBody(succeed) - } else { // 错误码匹配失败, 开始写入错误异常 - throw ResponseException(code, jsonObject.getString(message), request, body) +) : NetConverter { + + override fun onConvert(succeed: Type, response: Response): R? { + try { + return NetConverter.DEFAULT.onConvert(succeed, response) + } catch (e: ConvertException) { + val body = response.body?.string() ?: return null + val code = response.code + when { + code in 200..299 -> { // 请求成功 + if (succeed === String::class.java) return body as R + val jsonObject = JSONObject(body) // 获取JSON中后端定义的错误码和错误信息 + if (jsonObject.getString(this.code) == success) { // 对比后端自定义错误码 + return body.parseBody(succeed) + } else { // 错误码匹配失败, 开始写入错误异常 + throw ResponseException(response, jsonObject.getString(message)) + } } + code in 400..499 -> throw RequestParamsException(response) // 请求参数错误 + code >= 500 -> throw ServerResponseException(response) // 服务器异常错误 + else -> throw ConvertException(response) } - code in 400..499 -> throw RequestParamsException(code, request) // 请求参数错误 - code >= 500 -> throw ServerResponseException(code, request) // 服务器异常错误 - else -> throw ParseError(request) } } + /** + * 反序列化JSON + * + * @param succeed JSON对象的类型 + * @receiver 原始字符串 + */ abstract fun String.parseBody(succeed: Type): S? } ``` -DefaultConvert对于的核心逻辑 +JSONConvert的核心逻辑 1. 判断服务器错误码 1. 判断后端自定义错误码 diff --git a/docs/css/extra.css b/docs/css/extra.css index 00f46b1ff..91be4bd1c 100644 --- a/docs/css/extra.css +++ b/docs/css/extra.css @@ -36,10 +36,9 @@ /*字体渲染*/ @font-face{ - font-family: 'JetBrains Mono'; - src: local('JetBrains Mono'), - url('https://raw.githubusercontent.com/JetBrains/JetBrainsMono/master/fonts/webfonts/JetBrainsMono-Regular.woff2') format('woff2'), - url('https://raw.githubusercontent.com/JetBrains/JetBrainsMono/master/fonts/ttf/JetBrainsMono-Regular.ttf') format('truetype'); + font-family: 'PT Code'; + src: local('PT Code'), + url('https://raw.githubusercontent.com/liangjingkanji/PTCode/master/font/PTCode-Regular.ttf') format('truetype'); font-weight: normal; font-style: normal; } @@ -47,13 +46,16 @@ -webkit-font-feature-settings: "liga" on, "calt" on; -webkit-font-smoothing: subpixel-antialiased; text-rendering: optimizeLegibility; - font-family: 'JetBrains Mono' !important; + font-family: 'PT Code' !important; text-shadow: #33333333 0px 0px 1px !important; } /*布局*/ +.md-content { + max-width: 49.5rem; +} .md-grid { - max-width: 120em !important; + max-width: 80rem; } /*表格*/ diff --git a/docs/download-file.md b/docs/download-file.md index 325c93b51..bce73ffb7 100644 --- a/docs/download-file.md +++ b/docs/download-file.md @@ -2,33 +2,36 @@ ```kotlin scopeNetLife { - Download("download", requireContext().filesDir.path).await() + val file = Get("download").await() } ``` +Download函数一调用就会开始执行下载文件请求, 然后`await`则会等待下载文件完成然后返回一个File对象 + +下载文件的配置选项 -这里演示一个包含下载进度监听的 ```kotlin scopeNetLife { - val filePath = Download("download", requireContext().filesDir.path) { - // 下载进度回调 - onProgress { progress, byteCount, speed -> - // 进度条 - seek.progress = progress - - // 格式化显示单位 - val downloadSize = Formatter.formatFileSize(requireContext(), byteCount) - val downloadSpeed = Formatter.formatFileSize(requireContext(), speed) - - // 显示下载信息 - tv_progress.text = "下载进度: $progress% 已下载: $downloadSize 下载速度: $downloadSpeed" - } - }.await() + val file = + Get("https://download.sublimetext.com/Sublime%20Text%20Build%203211.dmg") { + setDownloadFileName("net.apk") + setDownloadDir(requireContext().filesDir) + setDownloadMd5Verify() + }.await() } ``` -Download函数一调用就会开始执行下载文件请求, 然后`await`则会等待下载文件完成然后返回一个文件下载完成后的地址, 示例中即`filePath`. - +配置选项 + +| 函数 | 描述 | +|-|-| +| setDownloadFileName | 下载的文件名称 | +| setDownloadDir | 下载保存的目录 | +| setDownloadMd5Verify | 下载是否开启MD5校验, 如果服务器返回 "Content-MD5"响应头和制定路径已经存在的文件MD5相同是否直接返回File, 不会重新下载 | +| setDownloadFileNameConflict | 下载文件名如果在指定路径下存在同名会自动重新命名, 例如`file_name(1).apk` | +| setDownloadFileNameDecode | 文件名称是否使用URL解码, 例如下载的文件名如果是中文, 服务器传输给你的会是被URL编码的字符串. 你使用URL解码后才是可读的中文名称 | +| setDownloadTempFile | 下载是否使用临时文件, 避免下载失败后覆盖同名文件或者无法判别是否已下载完整, 仅在下载完整以后才会显示为原有文件名 | +| addDownloadListener | 下载进度监听器, 具体介绍在[进度监听](progress.md)中 | > 不使用`await`函数则下载报错也不会被Net捕捉到, 将会被忽略, 使用await则会触发Net的错误处理, 终止当前作用域(scope)内其他网络请求, 被Net全局错误处理捕获 diff --git a/docs/download-image.md b/docs/download-image.md deleted file mode 100644 index 7097e8f2b..000000000 --- a/docs/download-image.md +++ /dev/null @@ -1,16 +0,0 @@ -下载图片需要依赖[Glide](https://github.com/bumptech/glide) - -这个下载图片函数`DownloadImage`和下载文件函数`Download`不同在于他可以裁剪图片 - -```kotlin -scopeDialog { - val file = DownloadImage(NetConfig.host + "download/img", 100, 100).await() - val uri = Uri.fromFile(file) - iv_img.setImageURI(uri) -} -``` -
- -DownloadImage的第一个参数Url不会包含`baseUrl`, 所以你可以看到我手动`NetConfig.host + "download/img"`. - -> 这是因为一般项目设计中图片都是单独与服务器之外的地址, 例如CDN图床, 所以默认不自动拼接baseUrl \ No newline at end of file diff --git a/docs/enqueue-request.md b/docs/enqueue-request.md new file mode 100644 index 000000000..59af3ec0d --- /dev/null +++ b/docs/enqueue-request.md @@ -0,0 +1,46 @@ +Net支持OkHttp的原有的队列请求 -- `enqueue` + +> 队列属于接口回调请求, 由于其代码复杂, 非特殊情况下还是建议使用协程发起请求 + +```kotlin +Net.post("api").enqueue(object : Callback { + override fun onFailure(call: Call, e: IOException) { + } + + override fun onResponse(call: Call, response: Response) { + } +}) +``` + +## NetCallback + +原始的Callback是没有任何数据转换和全局错误功能的. 这里可以使用NetCallback + +```kotlin +Net.post("api") { + param("password", "Net123") +}.enqueue(object : NetCallback() { + override fun onSuccess(call: Call, data: String) { + tv_fragment.text = data + } +}) +``` + +NetCallback相较于Callback的特性 + +1. 可以指定泛型数据转换 +2. 新增三个回调函数: onSuccess/onFailure/onComplete +3. 以上三个回调函数都运行在主线程 + +|请求函数|描述| +|-|-| +|Net.get|标准Http请求方法| +|Net.post|标准Http请求方法| +|Net.head|标准Http请求方法| +|Net.options|标准Http请求方法| +|Net.trace|标准Http请求方法| +|Net.delete|标准Http请求方法| +|Net.put|标准Http请求方法| +|Net.patch|标准Http请求方法| + + diff --git a/docs/global-error-handle.md b/docs/error-handle.md similarity index 79% rename from docs/global-error-handle.md rename to docs/error-handle.md index 97a657656..a317de91c 100644 --- a/docs/global-error-handle.md +++ b/docs/error-handle.md @@ -51,25 +51,20 @@ catch里面的`it`属于异常对象, 这里列举可能存在的异常 | 异常 | 描述 | |-|-| -| NetworkError | 无网络 | -| URLError | 地址错误 | -| HostError | 域名错误 | -| ConnectTimeoutError | 连接超时 | -| ReadTimeoutError | 读取超时 | -| DownloadError | 下载异常 | -| NoCacheError | 没有缓存 | -| ParseError | 解析错误, `Convert`中发生的未捕获异常都算解析错误 | +| NetworkingException | 无网络 | +| URLParseException | 地址错误 | +| UnknownHostException | 域名错误 | +| NetSocketTimeoutException | 连接超时 | +| DownloadFileException | 下载文件异常 | +| ConvertException | 解析错误, `NetConvert`中发生的未捕获异常都算解析错误 | | RequestParamsException | 请求参数错误 `400 - 499` 范围内错误码 | | ServerResponseException | 服务器错误 `500 - 599` 范围内错误码 | -| ExecutionException | 加载图片异常等 | -| NullPointerException | 空指针, 一般是在作用域内操作一个空的对象 | -| ConnectException | 连接异常 | -| WriteException | 写入异常 | -| ReadException | 读取异常 | | ResponseException | 响应异常, 这里属于后端返回的错误码和其定义的成功码不匹配 | -| NetException | 网络异常, 未知的网络异常, 一般情况应当继承他来创建自定义的网络异常 | +| NullPointerException | 空指针, 一般是在作用域内操作一个空的对象 | +| NoCacheException | 没有缓存 | +| NetException | 未知的网络异常, 一般情况应当继承他来创建自定义的网络异常 | -假设你重写`DefaultConvert`可以改变异常发生的条件, 当然你在转换器或者拦截器中抛出任何异常都会被捕获或者全局处理, 这里你可以自定义你的异常 +假设你重写`NetConverter`可以改变异常发生的条件, 当然你在转换器或者拦截器中抛出任何异常都会被捕获或者全局处理, 这里你可以自定义你的异常 ## 覆盖默认错误处理 @@ -80,8 +75,9 @@ catch里面的`it`属于异常对象, 这里列举可能存在的异常 源码位于: `NetConfig` - + +缺省页的错误处理是单独的: `onStateError` ### 2) 仅覆盖错误信息 diff --git a/docs/exception-track.md b/docs/exception-track.md index 6936b9e2f..e9a4cd190 100644 --- a/docs/exception-track.md +++ b/docs/exception-track.md @@ -1,7 +1,6 @@ -Net对于网络发送的异常追踪非常详细, 不仅是网络的还是异步任务的异常处理都非常独到 +Net中网络请求导致的异常都会在LogCat中打印, 同时被全局的NetConfig的onError拦截到 -
-> 只有网络错误就会在LogCat打印出异常信息, 并且跟随其地址信息 +> Net的异常对象通常会携带Request或者Response对象. 可以精准定位到请求信息 演示访问一个不存在的请求路径(但是URL存在) @@ -12,21 +11,21 @@ scopeNetLife { } ``` -查看LogCat +查看LogCat可以看到异常堆栈信息 - + 这属于请求参数错误404, 将会打印出错误码以及请求的URL. -
-同时任何网络请求错误都将在LogCat查看, 并且Convert(转换器)和Interceptor(拦截器)中都可以通过`request/response`获取请求/响应的信息. ### 关闭日志 在初始化时候可以关闭日志打印 ```kotlin -initNet("http://182.92.97.186/") { - logEnabled = true // 默认即为true +initNet("http://github.com/") { + setLog(false) // 关闭日志 } -``` \ No newline at end of file +``` + +或者设置字段`NetConfig.logEnabled`的值 \ No newline at end of file diff --git a/docs/https.md b/docs/https.md new file mode 100644 index 000000000..34e5f3107 --- /dev/null +++ b/docs/https.md @@ -0,0 +1,68 @@ +Https访问主要就是证书配置问题, Net可以使用OkHttp一切函数组件, 且简化证书配置流程 + +> OkHttp如何配置证书, Net就可以如何配置证书 + +## 使用CA证书 + +Https如果是使用的CA颁发的证书, 不需要任何配置Net可以直接访问 + +```kotlin +scopeNetLife { + tv_fragment.text = Get("https://github.com/").await() +} +``` + +## 信任所有证书 + +信任所有证书可以解决无法访问私有证书的Https地址问题, 但是这么做就失去了使用证书的含义, 不建议此做法 + +=== "全局配置" + + ```kotlin + initNet("https://www.google.com/"){ + trustSSLCertificate() // 信任所有证书 + } + ``` +=== "单例配置" + + ```kotlin + scopeNetLife { + Get("https://github.com/"){ + setClient { + trustSSLCertificate() + } + }.await() + } + ``` + +## 导入证书 + +私有证书可以放到任何位置, 只要能读取到`InputStream`流对象即可 + +=== "全局配置" + + ```kotlin + initNet("http://github.com/") { + val privateCertificate = resources.assets.open("https.certificate") + setSSLCertificate(privateCertificate) + } + ``` + +=== "单例配置" + + ```kotlin + scopeNetLife { + Get("https://github.com/") { + setClient { + val privateCertificate = resources.assets.open("https.certificate") // 这里的证书是放到应用的资产目录下 + setSSLCertificate(privateCertificate) + } + }.await() + } + ``` + + + + + + diff --git a/docs/index.md b/docs/index.md index d4b40a477..a773ffe38 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,4 +1,10 @@ -Net使用协程发起网络, 但是即使不会协程也可以使用该框架 +本框架使用OkHttp作为请求内核, 使用Kotlin语言扩展OkHttp的函数设计 + +
+

非常欢迎共同贡献代码

+
+ +Net支持使用协程发起网络, 当然即使不会协程也可以使用该框架.
这里演示发起网络`请求百度网站`内容的三个步骤 @@ -70,14 +76,9 @@ scopeNetLife { // 创建作用域 |请求函数|描述| |-|-| -|`param`|请求体参数| -|`path`|路径| -|`urlParam`|Url参数| -|`file`|上传文件| -|`binary`|二进制| -|`binaries`|多个二进制| -|`body`|自定义请求体| +|`param`|支持基础类型/文件/RequestBody/Part| |`json`|请求参数为JSONObject/JsonArray/String| +|`setQuery`|Url参数, 如果当前请求的Url请求则该函数等效于`param`函数| @@ -128,9 +129,10 @@ scopeNetLife { // 创建作用域 } ``` -对于某些可能JSON请求参数存在固定值, 可以考虑继承JsonBody来扩展出自己的新的Body(), 然后使用`body`函数传入请求中. +对于某些可能JSON请求参数存在固定值: -> JsonBody实际上也是继承自StringBody +1. 可以考虑继承RequestBody来扩展出自己的新的Body(), 然后使用`param`函数传入请求中. +2. 定义拦截器 ## RESTFUL @@ -188,37 +190,15 @@ private fun OPTIONS() { ## 函数 -### 异步请求 -即会在IO线程执行网络请求, 要求在作用域内执行 +即会在IO线程执行网络请求, 要求在协程作用域内执行 -|异步请求函数|描述| -|-|-| -| [Get](api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-get.md)|标准REST FUL| -| [Post](api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-post.md)|标准REST FUL| -| [Head](api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-head.md)|标准REST FUL| -| [Options](api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-options.md)|标准REST FUL| -| [Trace](api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-trace.md)|标准REST FUL| -| [Delete](api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-delete.md)|标准REST FUL| -| [Put](api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-put.md)|标准REST FUL| -| [Patch](api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-patch.md)|标准REST FUL| -| [Download](api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-download.md)|下载文件(默认Get)| -| [DownloadBody](api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-download-body.md)|下载文件(默认Post, 附带请求体)| -| [DownloadImage](api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-download-image.md)|下载图片(可指定图片大小), 如果使用要求依赖Glide| - -### 同步请求 - -即在当前线程执行, 会阻塞当前线程 - -|同步请求函数|描述| +|请求函数|描述| |-|-| -|syncGet|标准REST FUL| -|syncPost|标准REST FUL| -|syncHead|标准REST FUL| -|syncOptions|标准REST FUL| -|syncTrace|标准REST FUL| -|syncDelete|标准REST FUL| -|syncPut|标准REST FUL| -|syncPatch|标准REST FUL| -|syncDownload|下载文件(默认Get)| -|syncDownloadBody|下载文件(默认Post, 附带请求体)| -|syncDownloadImage|下载图片(可指定图片大小), 如果使用要求依赖Glide| \ No newline at end of file +| [Get](api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-get.md)|标准Http请求方法| +| [Post](api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-post.md)|标准Http请求方法| +| [Head](api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-head.md)|标准Http请求方法| +| [Options](api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-options.md)|标准Http请求方法| +| [Trace](api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-trace.md)|标准Http请求方法| +| [Delete](api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-delete.md)|标准Http请求方法| +| [Put](api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-put.md)|标准Http请求方法| +| [Patch](api/net/com.drake.net/kotlinx.coroutines.-coroutine-scope/-patch.md)|标准Http请求方法| \ No newline at end of file diff --git a/docs/interceptor.md b/docs/interceptor.md index 71d5deca0..b5400df00 100644 --- a/docs/interceptor.md +++ b/docs/interceptor.md @@ -1,7 +1,7 @@ -拦截器一般用于修改请求的参数, Net拦截器和Okhttp使用方式一样 +拦截器(Interceptor)一般用于修改请求的参数或者进行请求转发/重试. Net就是使用的OkHttp的拦截器. 所以支持市面上的所有OkHttp拦截器组件库
-> 你的业务可能需要请求参数加密或者拼接一串特殊含义的参数, 或者响应信息需要解密. 请不要尝试封装Post或者Get等请求函数(这是蠢材做法), 自定义拦截器和转换器可以应对任何项目需求. +> 你的业务可能需要请求参数加密或者拼接一串特殊含义的参数, 或者响应信息需要解密. 请不要一上来就封装Post或者Get等请求函数(这是愚蠢的做法), 自定义拦截器和转换器可以应对任何项目需求. ```kotlin @@ -9,22 +9,28 @@ class App : Application() { override fun onCreate() { super.onCreate() - initNet("http://182.92.97.186/") { + initNet("http://github.com/") { addInterceptor { chain -> chain.proceed(chain.request()) } } } } ``` -添加多个拦截器 -```kotlin -class App : Application() { - override fun onCreate() { - super.onCreate() +## 请求拦截器 + +RequestInterceptor属于轻量级的请求拦截器, 在每次请求的时候该拦截器都会被触发. 一般用于添加全局的参数和请求头 - initNet("http://182.92.97.186/") { - addInterceptors(RedirectInterceptor(), LogInterceptor()) +初始化时添加请求拦截器的示例代码 + +```kotlin +initNet("http://github.com/") { + setRequestInterceptor(object : RequestInterceptor { + override fun interceptor(request: BaseRequest) { + request.param("client", "Net") + request.setHeader("token", "123456") } - } + }) } -``` \ No newline at end of file +``` + +可以看到`setRequestInterceptor`是set开头. 仅支持一个请求拦截器, 不像`addInterceptor`支持多个请求拦截器 \ No newline at end of file diff --git a/docs/log-recorder.md b/docs/log-recorder.md index ce11146a8..ffb01d499 100644 --- a/docs/log-recorder.md +++ b/docs/log-recorder.md @@ -1,6 +1,6 @@ -一般网络请求都会选择在LogCat打印网络日志信息, 但是AndroidStudio的LogCat超长文本会被切割, 甚至发生不完整的情况, 而且容易和其他日志掺杂, 导致可读性差. +一般网络请求都会选择在LogCat打印网络日志信息, 但LogCat日志可读性差, 甚至不完整 -Net扩展`Okhttp Profiler`插件支持更好的日志拦截信息, 支持加密的请求和响应信息 +Net扩展`Okhttp Profiler`插件支持更好的网络日志输出, 支持加密的请求和响应信息 ## 安装插件 @@ -20,10 +20,9 @@ Net扩展`Okhttp Profiler`插件支持更好的日志拦截信息, 支持加密 ### 3) 初始化 -```kotlin hl_lines="3" -initNet("http://182.92.97.186/") { - converter(JsonConvert()) // 转换器 - setLogRecord(true) // 开启日志记录功能 +```kotlin hl_lines="2" +initNet("http://github.com/") { + addInterceptor(LogRecordInterceptor(BuildConfig.DEBUG)) } ``` @@ -39,61 +38,18 @@ initNet("http://182.92.97.186/") { | 清空 | 清空记录 | -### 响应字符串解密 - -假设你使用的是`DefaultConvert`或者没有使用转换器直接返回String则无需多余处理, 如果覆写或者直接实现的`Convert`, 请确保`result.logResponseBody`被赋值 -```kotlin hl_lines="16" -@Suppress("UNCHECKED_CAST") -abstract class DefaultConvert( - val success: String = "0", - val code: String = "code", - val message: String = "msg" -) : Converter { - - override fun convert( - succeed: Type, - request: Request, - response: Response, - cache: Boolean - ): S? { - val body = response.body().string() - response.log = body // 将字符串响应赋值给response.log - // .... 其他操作 - } -} -```
-> 假设后端返回的加密数据, 可以为`response.log`赋值解密后的字符串
- - -### 请求参数加密 +## 单例禁用 -假设请求参数为加密后的字符串请在拦截器中为日志记录器赋值请求参数字符串 - -```kotlin hl_lines="5" -class NetInterceptor : Interceptor { - override fun intercept(chain: Chain): Response { - val request = chain.request() - - request.log = "解密后的请求参数字符串" - - return chain.proceed(request) - } +```kotlin +scopeNetLife { + tv_fragment.text = Get("api") { + setLogRecord(false) // 为当前请求禁用日志记录 + }.await() } ``` -
- -响应和请求都可以设置日志信息, 以在插件中查看 - -| 函数 | 描述 | -|-|-| -| request.log | 请求的日志信息, 默认是params | -| response.log | 响应的日志信息, 默认为空 | - - - ## LogCat冗余日志过滤 实际上Net的网络日志还是会被打印到LogCat, 然后通过插件捕捉显示. diff --git a/docs/okhttp-client.md b/docs/okhttp-client.md new file mode 100644 index 000000000..5952cf980 --- /dev/null +++ b/docs/okhttp-client.md @@ -0,0 +1,47 @@ +每个请求都会存在一个客户端对象(OkHttpClient) + +Net在全局维护了一个OkHttpClient对象, 在NetConfig.okHttpClient的字段 + +```kotlin +object NetConfig { + var okHttpClient: OkHttpClient +} +``` + +同时每次可以创建一个新的客户端来发起请求区别于全局配置 + +## 全局OkHttpClient + +```kotlin +initNet("http://43.128.31.195/") { + // 此处this即为OkHttpClient.Builder +} +``` + + +## 单例OkHttpClient + +每个请求可能存在独立的OkHttpClient配置, 我们可以单例配置客户端选项 + +1. 在全局的OkHttpClient配置基础下修改 + +```kotlin +scopeNetLife { + tv_response.text = Get("https://github.com/") { + setClient { + // 此处this即为OkHttpClient.Builder + trustCertificate() + } + }.await() +} +``` + +2. 完全重新创建一个OkHttpClient, 一般情况不推荐重新创建一个OkHttpClient, 因为一个新的OkHttpClient会重新创建线程池/连接池等造成内存消耗等 + +```kotlin +scopeNetLife { + tv_response.text = Get("https://github.com/") { + okHttpClient = OkHttpClient.Builder().build() + }.await() +} +``` \ No newline at end of file diff --git a/docs/parallel.md b/docs/parallel.md index e494632aa..7e7501ac4 100644 --- a/docs/parallel.md +++ b/docs/parallel.md @@ -1,8 +1,6 @@ Net在2.0开始引入协程来支持并发和异步, 虽然很多网络框架支持协程, 但是Net对于协程生命周期的控制算得上是独有. 并且Net不仅仅网络请求, 其也支持创建任何异步任务. -
- > 这里的`同时/并发/并行`统称为并发(具体是不是并行不需要开发者来考虑)
diff --git a/docs/parse-list.md b/docs/parse-list.md deleted file mode 100644 index 9d0f31e11..000000000 --- a/docs/parse-list.md +++ /dev/null @@ -1,108 +0,0 @@ -一般的解析过程是以下 - -1) 后端返回的JSON数据 - -```json -{ - "code":200, - "msg":"错误信息", - "data": { - "name": "彭于晏" - } -} -``` - -2) 创建数据模型 - -```kotlin -data class UserInfo ( - var code:Int, - var msg:String, - var data:Info, -) { - data class Info (var name:String) -} -``` - -3) 发起网络请求 - -```kotlin -scopeNetLife { - val data = Get("/list").await().data -} -``` - -这样每次都要`await().data`才是你要的`data`对象. 有些人就想省略直接不写code和msg, 希望直接返回data. - -这样的确可以, 但是面临一个问题, 部分后端开发可能让data直接为JSON数组. - -例如这种格式 - -```json -{ - "code":200, - "msg":"错误信息", - "data": [ - { "name": "彭于晏" }, - { "name": "吴彦祖" }, - { "name": "金城武" } - ] -} -``` - -由于Java的类型擦除机制, List的泛型在运行时将被擦除, 导致Gson或者FastJson等无法解析出正确的List数据 - -> 在Net的未来版本`3.0`中将支持直接返回List/Map/Pair等, 无需任何处理, 泛型是什么就返回什么 - -所以这样的代码将报错 -```kotlin -scopeNetLife { - val data = Get>("/list").await().data -} -``` - -这里我推荐的解决方式是, 针对会data会为JSON数组的情况, 我们可以直接使用String创建一个扩展函数 - -### 1) 摘取字段 - -你要保证`await()`返回的只有data的值, 而不是完整Json, 因为Json字符串必须和数据类字段匹配才能解析成功(这是解析JSON的常识和网络请求无关)
- -重写`convert`函数, 让转换器仅返回`data` - - - -### 2) 定义解析函数 - -创建一个顶层函数(即在类之外的函数, 直接存在kt文件中) -```kotlin -inline fun String.toJsonArray(): MutableList { - return JSON.parseArray(this, T::class.java) -} -``` - -`JSON.parseArray`这是FastJson的函数, 如果你使用的是Gson可以使用 - -```kotlin -inline fun String.toJsonArray(): MutableList { - return Gson().fromJson(this, TypeToken.getParameterized(List::class.java, T::class.java).type) -} -``` - -### 2) 创建数据类 - -```kotlin -data class Info (var name:String) -``` - -### 3) 使用 - -```kotlin -scopeNetLife { - val listData = Post("/list").await().toJsonArray() - listData[0] -} -``` -
- -> 这样的优点是扩展方便, 整体清晰. 毕竟不是每个接口的data都可能是JSON数组, 而且这样还支持List嵌套(JSON数组嵌套)
- 该扩展函数太简单我就不加入到框架中了, 大家复制粘贴下就OK了 \ No newline at end of file diff --git a/docs/progress.md b/docs/progress.md new file mode 100644 index 000000000..3713fea31 --- /dev/null +++ b/docs/progress.md @@ -0,0 +1,87 @@ +Net支持上传/下载的进度监听, 且具备完善的进度信息 + + +## 上传进度监听 + +```kotlin +scopeNetLife { + Post("https://download.sublimetext.com/Sublime%20Text%20Build%203211.dmg") { + param("file", assetsFile()) + addUploadListener(object : ProgressListener() { + override fun onProgress(p: Progress) { + seek.post { + seek.progress = p.progress() + tv_progress.text = + "上传进度: ${p.progress()}% 上传速度: ${p.speedSize()} " + + "\n\n文件大小: ${p.totalSize()} 已上传: ${p.currentSize()} 剩余大小: ${p.remainSize()}" + + "\n\n已使用时间: ${p.useTime()} 剩余时间: ${p.remainTime()}" + } + } + }) + }.await() +} +``` + + + +## 下载进度监听 + +```kotlin +scopeNetLife { + val file = + Get("https://download.sublimetext.com/Sublime%20Text%20Build%203211.dmg") { + setDownloadFileName("net.apk") + setDownloadDir(requireContext().filesDir) + + addDownloadListener(object : ProgressListener() { + override fun onProgress(p: Progress) { + seek?.post { + val progress = p.progress() + seek.progress = progress + tv_progress.text = + "下载进度: $progress% 下载速度: ${p.speedSize()} " + + "\n\n文件大小: ${p.totalSize()} 已下载: ${p.currentSize()} 剩余大小: ${p.remainSize()}" + + "\n\n已使用时间: ${p.useTime()} 剩余时间: ${p.remainTime()}" + } + } + }) + }.await() +} +``` + +> 无论是上传还是下载的进度监听不仅仅是泛型为File对象才有效, 任何请求/响应都会被监听到进度 + + +## 监听器 + +通过继承`ProgressListener`抽象类实现监听进度信息. 进度信息为`Progress`对象 + +### 进度间隔时间 + +ProgressListener的构造参数`interval`控制触发进度监听器的间隔时间, 默认是500毫秒. 毕竟进度监听不需要太频繁的调用影响性能. + +### 进度信息 + +| 函数 | 描述 | +|-|-| +| currentBytes | 已完成字节数 | +| totalBytes | 全局字节数 | +| intervalBytes | 监听器间隔时间内的完成字节数 | +| intervalTime | 监听器的间隔时间 | +| startElapsedRealtime | 开始下载时间(该时间值开机到现在的毫秒数) | +| speedBytes | 每秒下载字节数 | +| progress | 进度, 1-100 | +| finish | 此次下载/上传是否完成 | +| useTimeSeconds | 已经使用时间, 单位秒 | +| remainTimeSeconds | 估算的剩余时间, 单位秒 | + +同时提供了一系列字符串格式函数, 都是返回已经添加好单位 + +| 函数 | 描述 | +|-|-| +| currentSize | 已完成大小, 格式为: `120kB` 或者 `1.5MB` | +| totalSize | 全部大小 | +| remainSize | 剩余大小 | +| speedSize | 每秒下载大小 | +| useTime | 已使用时间, 格式为: `01:23:04` | +| remainTime | 估算的剩余时间, 格式为: `01:23:04` | diff --git a/docs/read-cache.md b/docs/read-cache.md index 69eb96df2..54e23468d 100644 --- a/docs/read-cache.md +++ b/docs/read-cache.md @@ -3,7 +3,7 @@ Net_v2基于[Kalle](https://github.com/yanzhenjie/Kalle)开发, 支持Kalle的9 缓存模式要求在初始化的时候开启 ```kotlin -initNet("http://182.92.97.186/") { +initNet("http://github.com/") { cacheEnabled() // 开启缓存 } ``` diff --git a/docs/request-params.md b/docs/request-params.md new file mode 100644 index 000000000..91d071f97 --- /dev/null +++ b/docs/request-params.md @@ -0,0 +1,36 @@ +在Net中都是使用的其框架内部创建的`Request`创建请求 + +涉及到请求参数的类只有两个类和一个抽象父类 + +```kotlin +BaseRequest + |- UrlRequest + |- BodyRequest +``` + + +根据请求方法不同使用的Request也不同 + +```kotlin +GET, HEAD, OPTIONS, TRACE, // Url request +POST, DELETE, PUT, PATCH // Body request +``` + +代码示例 + +```kotlin +scopeNetLife { + Get("api") { + // this 即为 UrlRequest + }.await + + Post("api") { + // this 即为 BodyRequest + }.await +} +``` + +关于具体函数希望阅读源码. Net源码全部有文档注释, 以及函数结构分组 + + + diff --git a/docs/scope.md b/docs/scope.md index ee44ed5a0..92ffb1c17 100644 --- a/docs/scope.md +++ b/docs/scope.md @@ -51,7 +51,7 @@ scope { | 函数 | 描述 | |-|-| -| catch | 作用域被`catch`则不会被传递到全局异常处理回调中: [全局处理异常](global-error-handle.md), 除非使用`handleError`再次传递给全局 | +| catch | 作用域被`catch`则不会被传递到全局异常处理回调中: [全局处理异常](error-handle.md), 除非使用`handleError`再次传递给全局 | | finally | 同样可以获取到异常对象, 且不影响全局异常回调处理 | diff --git a/docs/sync-request.md b/docs/sync-request.md new file mode 100644 index 000000000..b45cefacb --- /dev/null +++ b/docs/sync-request.md @@ -0,0 +1,24 @@ +Net支持在当前线程执行, 会阻塞当前线程的同步请求 -- `execute` + +这里介绍的是不使用协程的同步请求. 由于Android主线程不允许发起网络请求, 这里我们得随便创建一个子线程才可以开发起同步请求 + +```kotlin +thread { + tv_fragment?.text = Net.post("api").execute() +} +``` + +> 同步请求应用场景一般是在拦截器中使用, 拦截器默认是子线程 + +作用域具体介绍可以看[创建作用域](scope.md) + +|请求函数|描述| +|-|-| +|Net.get|标准Http请求方法| +|Net.post|标准Http请求方法| +|Net.head|标准Http请求方法| +|Net.options|标准Http请求方法| +|Net.trace|标准Http请求方法| +|Net.delete|标准Http请求方法| +|Net.put|标准Http请求方法| +|Net.patch|标准Http请求方法| diff --git a/docs/tag.md b/docs/tag.md index 512dff633..500d3ea22 100644 --- a/docs/tag.md +++ b/docs/tag.md @@ -1,6 +1,7 @@ -Net支持的`标签`功能, 其标签能够贯穿网络请求的生命周期 +Net的标签完美的扩展的OkHttp的标签功能 +
-在拦截器(Interceptor)或者转换器(Convert)中都可以通过`request.tag()`获取到标签 +在拦截器(Interceptor)或者转换器(NetConvert)中都可以通过`request.tag(name)`获取到标签对象 ## 标签使用 @@ -8,19 +9,17 @@ Net支持的`标签`功能, 其标签能够贯穿网络请求的生命周期 ### 1) 设置标签 ```kotlin hl_lines="2" scopeNetLife { - tv_fragment.text = Get("api", tag = RESPONSE).await() + tv_fragment.text = Get("api", "我是一个标签").await() } ``` ### 2) 拦截器中获取标签 ```kotlin hl_lines="4" -class NetInterceptor : Interceptor { +class MyInterceptor : Interceptor { override fun intercept(chain: Chain): Response { - val request = chain.request() - - if (request.tag() == RESPONSE) { - // 可以打印响应体或者其他逻辑 + request.tag()?.let { + // 获取标签做任何事 } return chain.proceed(request) } @@ -29,72 +28,48 @@ class NetInterceptor : Interceptor { ### 3) 转换器中获取标签 -```kotlin hl_lines="10" -class JsonConvert : DefaultConvert(code = "code", message = "msg", success = "200") { - - override fun convert(succeed: Type, - failed: Type, - request: Request, - response: Response, - result: Result) { - super.convert(succeed, failed, request, response, result) +```kotlin hl_lines="4" +class MyConvert : NetConvert { - if (request.tag() == RESPONSE) { // 判断标签 - // 执行你的逻辑 + override fun onConvert( succeed: Type, response: Response ): R? { + response.request.tag()?.let{ + // 获取标签做任何事 } } - - override fun String.parseBody(succeed: Type): S? { - return Moshi.Builder().build().adapter(succeed).fromJson(this) - } } ``` +
+我们通过Request的函数可以设置和读取标签 -## 多标签 -创建一个类继承TAG, 即可通过加减符号来添加多标签 +| 函数 | 描述 | +|-|-| +| setTag | 设置标签 | +| tag | 读取标签 | -上面例子使用的`RESPONSE`就是一个示例 -```kotlin -/** - * 响应体打印标签 - */ -object RESPONSE : TAG() - -/** - * 请求参数打印标签 - */ -object REQUEST : TAG() -``` -1) 设置标签 +## 设置多个标签 ```kotlin scopeNetLife { - tv_fragment.text = Get("api", tag = RESPONSE + REQUEST).await() + Get("api"){ + setTag("person", Person()) // 使用Request.tag("person")获取 + setTag(User()) // 使用Request.tag()直接获取 + }.await() } ``` -2) 判断包含标签 +得到标签 -```kotlin hl_lines="7 10" -class NetInterceptor : Interceptor { +```kotlin hl_lines="4" +class MyInterceptor : Interceptor { override fun intercept(chain: Chain): Response { val request = chain.request() - - val tag = request.tag() as TAG - - if (tag.contains(REQUEST)) { - // 可以打印响应体或者其他逻辑 - } - if (tag.contains(RESPONSE)) { - // 可以打印请求体或者其他逻辑 + request.tag("person")?.let { + // it既为Person对象 } return chain.proceed(request) } } -``` -
- -> RESPONSE 和 REQUEST 已经在Net框架中存在, 可以直接使用 \ No newline at end of file +``` \ No newline at end of file diff --git a/docs/updates.md b/docs/updates.md index 926214ba7..5d8844c61 100644 --- a/docs/updates.md +++ b/docs/updates.md @@ -1,3 +1,10 @@ +## 3.0 +1. 重构代码, 提升稳定性和安全性. +2. 支持OkHttp的所有函数/组件, 可独立升级OkHttp版本 +3. 更加强大的下载功能 +4. 所有IO读写使用OKIO +5. 更加优雅的函数设计 + ## 2.3.15 [json]请求体支持Map和Pair参数 diff --git a/docs/upload-file.md b/docs/upload-file.md index fde443e5b..b4453ce7e 100644 --- a/docs/upload-file.md +++ b/docs/upload-file.md @@ -3,40 +3,9 @@ ```kotlin scopeNetLife { Post("upload", requireContext().cacheDir.path) { - file("fileName", getFile()) + file("fileName", assetsFile()) }.await() } ``` -这里演示上传一个包含上传进度监听的文件 - -```kotlin -scopeNetLife { - Post("upload") { - - val saveFile = getFile() - val form = FormBody.newBuilder().file("file", saveFile).build() - - form.onProgress { origin, progress -> - - seek.progress = progress // 进度条 - - // 格式化显示单位 - val downloadSize = - android.text.format.Formatter.formatFileSize(requireContext(), 23) - val downloadSpeed = - android.text.format.Formatter.formatFileSize(requireContext(), 23) - - // 显示下载信息 - tv_progress.text = "上传进度: $progress% 已下载: $downloadSize 下载速度: $downloadSpeed" - } - - body(form) - - }.await() -} -``` - -
- -> 普通字段接口请求也可以通过这种方式监听上传参数进度 \ No newline at end of file +使用`addUploadListener`添加上传进度监听器, 监听上传进度具体介绍在[进度监听](progress.md)中 diff --git a/docs/view-model.md b/docs/view-model.md new file mode 100644 index 000000000..92f4176f0 --- /dev/null +++ b/docs/view-model.md @@ -0,0 +1,34 @@ +Net支持在ViewModel中创建网络请求/异步任务, 并且在ViewModel被销毁时自动取消 + + +## 使用 +和一般网络请求没有区别, 在ViewModel中使用函数`scopeLife/scopeNetLife`这两个函数创建作用域即可, 具体介绍看[作用域](scope.md) + + +```kotlin +class UserViewModel : ViewModel() { + + // 用户信息 + var userInfo: MutableLiveData = MutableLiveData() + + /** + * 拉取用户信息, 会自动通知页面更新, 同时页面销毁会自动取消网络请求 + */ + fun fetchUserInfo() = scopeNetLife { + userInfo.value = Get("api").await() + } +} +``` + + +1. 建议ViewModel+LiveData使用 +2. 如果你不想写很多监听LiveData的冗余代码建议使用ViewModel+LiveData+DataBinding +3. 如果你业务和UI本身就是分离. 实际上非重量级数据请求可以直接在Activity/Fragment中进行请求更加方便 +4. ViewModel这个类本质是属于防止数据意外销毁, 但是我们编写应用常常固定竖屏或者页面重新加载网络也是没有问题的. +我不认为每个页面都应当编写一个ViewModel. +5. DataBinding双向数据绑定才是MVVM的核心 +6. 具体使用期请查看Demo中的示例代码 + +
+ + diff --git a/gradle.properties b/gradle.properties index c5dc8b2fd..9b84de476 100644 --- a/gradle.properties +++ b/gradle.properties @@ -34,3 +34,5 @@ android.useAndroidX=true android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official +kotlin.incremental=false + diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2e519b1df..869f038c4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip diff --git a/kalle/.gitignore b/kalle/.gitignore deleted file mode 100644 index 42afabfd2..000000000 --- a/kalle/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/kalle/build.gradle b/kalle/build.gradle deleted file mode 100644 index b46163727..000000000 --- a/kalle/build.gradle +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' - -apply plugin: 'com.github.dcendents.android-maven' -group='com.github.liangjingkanji' - -android { - compileSdkVersion 30 - defaultConfig { - minSdkVersion 9 - targetSdkVersion 30 - } -} -dependencies { - implementation "androidx.core:core-ktx:1.3.2" - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" -} -repositories { - mavenCentral() -} \ No newline at end of file diff --git a/kalle/src/main/AndroidManifest.xml b/kalle/src/main/AndroidManifest.xml deleted file mode 100644 index 1431a47f6..000000000 --- a/kalle/src/main/AndroidManifest.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/BaseContent.java b/kalle/src/main/java/com/yanzhenjie/kalle/BaseContent.java deleted file mode 100644 index 3a89b6747..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/BaseContent.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -import com.yanzhenjie.kalle.util.ProgressOutputStream; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.concurrent.Executor; - -/** - * Created by Zhenjie Yan on 2018/2/11. - */ -public abstract class BaseContent implements Content { - - private ProgressBar mProgressBar; - - public void onProgress(ProgressBar progressBar) { - this.mProgressBar = new AsyncProgressBar<>(progressBar); - } - - @Override - public final void writeTo(OutputStream writer) throws IOException { - if (mProgressBar != null) { - onWrite(new ProgressOutputStream<>(writer, (T) this, mProgressBar)); - } else { - onWrite(writer); - } - } - - /** - * Content body data. - */ - protected abstract void onWrite(OutputStream writer) throws IOException; - - private static class AsyncProgressBar implements ProgressBar { - - private final ProgressBar mProgressBar; - private final Executor mExecutor; - - public AsyncProgressBar(ProgressBar bar) { - this.mProgressBar = bar; - this.mExecutor = Kalle.getConfig().getMainExecutor(); - } - - @Override - public void progress(final T origin, final int progress) { - mExecutor.execute(new Runnable() { - @Override - public void run() { - mProgressBar.progress(origin, progress); - } - }); - } - } - -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/Binary.java b/kalle/src/main/java/com/yanzhenjie/kalle/Binary.java deleted file mode 100644 index a377f0c1c..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/Binary.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -/** - *

File interface. All the methods are called in thread.

- * Created in Oct 12, 2015 4:44:07 PM. - */ -public interface Binary extends Content { - - /** - * Gets the name of Binary. - */ - String name(); -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/BodyRequest.java b/kalle/src/main/java/com/yanzhenjie/kalle/BodyRequest.java deleted file mode 100644 index 2a5567c46..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/BodyRequest.java +++ /dev/null @@ -1,383 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -import org.json.JSONArray; -import org.json.JSONObject; - -import java.io.File; -import java.util.List; -import java.util.Map; - -import kotlin.Pair; - -/** - * Created by Zhenjie Yan on 2018/2/13. - */ -public class BodyRequest extends Request { - - private final Url mUrl; - private final RequestBody mBody; - private final Params mParams; - - protected BodyRequest(Api api) { - super(api); - this.mUrl = api.mUrlBuilder.build(); - this.mParams = api.mParams.build(); - this.mBody = api.mBody == null ? (mParams.hasBinary() ? mParams.toFormBody() : mParams.toUrlBody()) : api.mBody; - } - - public static BodyRequest.Builder newBuilder(String url, RequestMethod method) { - return newBuilder(Url.newBuilder(url).build(), method); - } - - public static BodyRequest.Builder newBuilder(Url url, RequestMethod method) { - return new BodyRequest.Builder(url, method); - } - - /** - * @deprecated use {@link #newBuilder(Url, RequestMethod)} instead. - */ - @Deprecated - public static BodyRequest.Builder newBuilder(Url.Builder url, RequestMethod method) { - return newBuilder(url.build(), method); - } - - @Override - public Url url() { - return mUrl; - } - - @Override - public Params copyParams() { - return mParams; - } - - /** - * Get the define body to send. - */ - @Override - public RequestBody body() { - return mBody; - } - - public static class Api> extends Request.Api { - - private Url.Builder mUrlBuilder; - - private Params.Builder mParams; - private RequestBody mBody; - - protected Api(Url url, RequestMethod method) { - super(method); - this.mUrlBuilder = url.builder(); - this.mParams = Params.newBuilder(); - - this.mParams.add(Kalle.getConfig().getParams()); - } - - @Override - public T path(int value) { - mUrlBuilder.addPath(value); - return (T) this; - } - - @Override - public T path(long value) { - mUrlBuilder.addPath(value); - return (T) this; - } - - @Override - public T path(boolean value) { - mUrlBuilder.addPath(value); - return (T) this; - } - - @Override - public T path(char value) { - mUrlBuilder.addPath(value); - return (T) this; - } - - @Override - public T path(double value) { - mUrlBuilder.addPath(value); - return (T) this; - } - - @Override - public T path(float value) { - mUrlBuilder.addPath(value); - return (T) this; - } - - @Override - public T path(String value) { - mUrlBuilder.addPath(value); - return (T) this; - } - - /** - * Add parameter to url. - */ - public T urlParam(String key, int value) { - mUrlBuilder.addQuery(key, value); - return (T) this; - } - - /** - * Add parameter to url. - */ - public T urlParam(String key, long value) { - mUrlBuilder.addQuery(key, value); - return (T) this; - } - - /** - * Add parameter to url. - */ - public T urlParam(String key, boolean value) { - mUrlBuilder.addQuery(key, value); - return (T) this; - } - - /** - * Add parameter to url. - */ - public T urlParam(String key, char value) { - mUrlBuilder.addQuery(key, value); - return (T) this; - } - - /** - * Add parameter to url. - */ - public T urlParam(String key, double value) { - mUrlBuilder.addQuery(key, value); - return (T) this; - } - - /** - * Add parameter to url. - */ - public T urlParam(String key, float value) { - mUrlBuilder.addQuery(key, value); - return (T) this; - } - - /** - * Add parameter to url. - */ - public T urlParam(String key, short value) { - mUrlBuilder.addQuery(key, value); - return (T) this; - } - - /** - * Add parameter to url. - */ - public T urlParam(String key, String value) { - mUrlBuilder.addQuery(key, value); - return (T) this; - } - - /** - * Add parameter to url. - */ - public T urlParam(String key, List values) { - mUrlBuilder.addQuery(key, values); - return (T) this; - } - - /** - * Add parameters to url. - */ - public T urlParam(Params params) { - mUrlBuilder.addQuery(params); - return (T) this; - } - - /** - * Set parameter to url. - */ - public T setUrlParam(Params params) { - mUrlBuilder.setQuery(params); - return (T) this; - } - - @Override - public T param(String key, int value) { - return param(key, Integer.toString(value)); - } - - @Override - public T param(String key, long value) { - mParams.add(key, value); - return (T) this; - } - - @Override - public T param(String key, boolean value) { - mParams.add(key, value); - return (T) this; - } - - @Override - public T param(String key, char value) { - mParams.add(key, value); - return (T) this; - } - - @Override - public T param(String key, double value) { - mParams.add(key, value); - return (T) this; - } - - @Override - public T param(String key, float value) { - mParams.add(key, value); - return (T) this; - } - - @Override - public T param(String key, short value) { - mParams.add(key, value); - return (T) this; - } - - @Override - public T param(String key, String value) { - mParams.add(key, value); - return (T) this; - } - - @Override - public T param(String key, List values) { - mParams.add(key, values); - return (T) this; - } - - /** - * Add parameters to body. - */ - public T params(Params params) { - mParams.add(params); - return (T) this; - } - - /** - * Set parameters to body. - */ - public T setParams(Params params) { - mParams.set(params); - return (T) this; - } - - @Override - public T removeParam(String key) { - mParams.remove(key); - return (T) this; - } - - @Override - public T clearParams() { - mParams.clear(); - return (T) this; - } - - /** - * Add several file parameters. - */ - public T file(String key, File file) { - mParams.file(key, file); - return (T) this; - } - - /** - * Add files parameter. - */ - public T files(String key, List files) { - mParams.files(key, files); - return (T) this; - } - - /** - * Add binary parameter. - */ - public T binary(String key, Binary binary) { - mParams.binary(key, binary); - return (T) this; - } - - /** - * Add several binary parameters. - */ - public T binaries(String key, List binaries) { - mParams.binaries(key, binaries); - return (T) this; - } - - /** - * Set request body. - */ - public T body(RequestBody body) { - this.mBody = body; - return (T) this; - } - - /** - * Set JSON request body. - */ - public T json(JSONObject json) { - this.mBody = new JsonBody(json); - return (T) this; - } - - public T json(JSONArray json) { - this.mBody = new JsonBody(json); - return (T) this; - } - - public T json(Pair... json) { - this.mBody = new JsonBody(json); - return (T) this; - } - - public T json(Map json) { - this.mBody = new JsonBody(json); - return (T) this; - } - - public T json(String json) { - this.mBody = new JsonBody(json); - return (T) this; - } - } - - public static class Builder extends BodyRequest.Api { - - private Builder(Url url, RequestMethod method) { - super(url, method); - } - - public BodyRequest build() { - return new BodyRequest(this); - } - } - -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/Content.java b/kalle/src/main/java/com/yanzhenjie/kalle/Content.java deleted file mode 100644 index 6bb31118c..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/Content.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * Created by Zhenjie Yan on 2018/2/11. - */ -public interface Content { - - /** - * Returns the length of the content. - */ - long contentLength(); - - /** - * Get the type of the content. - */ - String contentType(); - - /** - * Content data. - */ - void writeTo(OutputStream writer) throws IOException; -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/FileBinary.java b/kalle/src/main/java/com/yanzhenjie/kalle/FileBinary.java deleted file mode 100644 index 9858e15cf..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/FileBinary.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -import android.text.TextUtils; -import android.webkit.MimeTypeMap; - -import com.yanzhenjie.kalle.util.IOUtils; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - *

- * A default implementation of Binary. - * All the methods are called in Son thread. - *

- * Created in Oct 17, 2015 12:40:54 PM. - */ -public class FileBinary extends BaseContent implements Binary { - - private File mFile; - - public FileBinary(File file) { - this.mFile = file; - } - - @Override - public long contentLength() { - return mFile.length(); - } - - @Override - public String name() { - return mFile.getName(); - } - - @Override - public String contentType() { - String fileName = mFile.getName(); - String extension = MimeTypeMap.getFileExtensionFromUrl(fileName); - String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); - if (TextUtils.isEmpty(mimeType)) mimeType = Headers.VALUE_APPLICATION_STREAM; - return mimeType; - } - - - @Override - protected void onWrite(OutputStream writer) throws IOException { - InputStream stream = new FileInputStream(mFile); - IOUtils.write(stream, writer); - IOUtils.closeQuietly(stream); - } -} diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/FileBody.java b/kalle/src/main/java/com/yanzhenjie/kalle/FileBody.java deleted file mode 100644 index 78f0aaf8f..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/FileBody.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -import android.text.TextUtils; -import android.webkit.MimeTypeMap; - -import com.yanzhenjie.kalle.util.IOUtils; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * Created by Zhenjie Yan on 2018/2/13. - */ -public class FileBody extends BaseContent implements RequestBody { - - private final File mFile; - - public FileBody(File file) { - this.mFile = file; - } - - @Override - public long contentLength() { - return mFile.length(); - } - - @Override - public String contentType() { - String fileName = mFile.getName(); - String extension = MimeTypeMap.getFileExtensionFromUrl(fileName); - String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); - if (TextUtils.isEmpty(mimeType)) mimeType = Headers.VALUE_APPLICATION_STREAM; - return mimeType; - } - - - @Override - protected void onWrite(OutputStream writer) throws IOException { - InputStream reader = new FileInputStream(mFile); - IOUtils.write(reader, writer); - IOUtils.closeQuietly(reader); - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/FormBody.java b/kalle/src/main/java/com/yanzhenjie/kalle/FormBody.java deleted file mode 100644 index 7774f0b68..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/FormBody.java +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -import android.text.TextUtils; - -import com.yanzhenjie.kalle.util.IOUtils; -import com.yanzhenjie.kalle.util.LengthOutputStream; - -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; -import java.nio.charset.Charset; -import java.util.List; -import java.util.Set; - -import static com.yanzhenjie.kalle.Headers.VALUE_APPLICATION_FORM; - -/** - * Created by Zhenjie Yan on 2018/2/9. - */ -public class FormBody extends BaseContent implements RequestBody { - - private final Charset mCharset; - private final String mContentType; - private final Params mParams; - private String mBoundary; - - private FormBody(Builder builder) { - this.mCharset = builder.mCharset == null ? Kalle.getConfig().getCharset() : builder.mCharset; - this.mContentType = TextUtils.isEmpty(builder.mContentType) ? VALUE_APPLICATION_FORM : builder.mContentType; - this.mParams = builder.mParams.build(); - this.mBoundary = createBoundary(); - } - - public static Builder newBuilder() { - return new Builder(); - } - - private static String createBoundary() { - StringBuilder sb = new StringBuilder("-------FormBoundary"); - for (int t = 1; t < 12; t++) { - long time = System.currentTimeMillis() + t; - if (time % 3L == 0L) { - sb.append((char) (int) time % '\t'); - } else if (time % 3L == 1L) { - sb.append((char) (int) (65L + time % 26L)); - } else { - sb.append((char) (int) (97L + time % 26L)); - } - } - return sb.toString(); - } - - /** - * Copy parameters from form body. - */ - public Params copyParams() { - return mParams; - } - - @Override - public long contentLength() { - LengthOutputStream stream = new LengthOutputStream(); - try { - onWrite(stream); - } catch (IOException ignored) { - } - return stream.getLength(); - } - - @Override - public String contentType() { - return mContentType + "; boundary=" + mBoundary; - } - - @Override - protected void onWrite(OutputStream writer) throws IOException { - Set keys = mParams.keySet(); - for (String key : keys) { - List values = mParams.get(key); - for (Object value : values) { - if (value instanceof String) { - writeFormString(writer, key, (String) value); - } else if (value instanceof Binary) { - writeFormBinary(writer, key, (Binary) value); - } - } - } - - IOUtils.write(writer, "\r\n", mCharset); - IOUtils.write(writer, "--" + mBoundary + "--\r\n", mCharset); - } - - private void writeFormString(OutputStream writer, String key, String value) throws IOException { - IOUtils.write(writer, "--" + mBoundary + "\r\n", mCharset); - IOUtils.write(writer, "Content-Disposition: form-data; name=\"" + key + "\"", mCharset); - IOUtils.write(writer, "\r\n\r\n", mCharset); - IOUtils.write(writer, value, mCharset); - IOUtils.write(writer, "\r\n", mCharset); - } - - private void writeFormBinary(OutputStream writer, String key, Binary value) throws IOException { - IOUtils.write(writer, "--" + mBoundary + "\r\n", mCharset); - IOUtils.write(writer, "Content-Disposition: form-data; name=\"" + key + "\"", mCharset); - IOUtils.write(writer, "; filename=\"" + value.name() + "\"", mCharset); - IOUtils.write(writer, "\r\n", mCharset); - IOUtils.write(writer, "Content-Type: " + value.contentType() + "\r\n\r\n", mCharset); - if (writer instanceof LengthOutputStream) { - ((LengthOutputStream) writer).write(value.contentLength()); - } else { - value.writeTo(writer); - } - IOUtils.write(writer, "\r\n", mCharset); - } - - public static class Builder { - - private Charset mCharset; - private String mContentType; - private Params.Builder mParams; - - private Builder() { - this.mParams = Params.newBuilder(); - } - - /** - * Data charset. - */ - public Builder charset(Charset charset) { - this.mCharset = charset; - return this; - } - - /** - * Content type. - */ - public Builder contentType(String contentType) { - this.mContentType = contentType; - return this; - } - - /** - * Add parameter. - */ - public Builder param(String key, int value) { - mParams.add(key, value); - return this; - } - - /** - * Add parameter. - */ - public Builder param(String key, long value) { - mParams.add(key, value); - return this; - } - - /** - * Add parameter. - */ - public Builder param(String key, boolean value) { - mParams.add(key, value); - return this; - } - - /** - * Add parameter. - */ - public Builder param(String key, char value) { - mParams.add(key, value); - return this; - } - - /** - * Add parameter. - */ - public Builder param(String key, double value) { - mParams.add(key, value); - return this; - } - - /** - * Add parameter. - */ - public Builder param(String key, float value) { - mParams.add(key, value); - return this; - } - - /** - * Add parameter. - */ - public Builder param(String key, short value) { - mParams.add(key, value); - return this; - } - - /** - * Add parameter. - */ - public Builder param(String key, CharSequence value) { - mParams.add(key, value); - return this; - } - - /** - * Add parameter. - */ - public Builder param(String key, String value) { - mParams.add(key, value); - return this; - } - - /** - * Add parameters. - */ - public Builder param(String key, List values) { - mParams.add(key, values); - return this; - } - - /** - * Add parameters. - */ - public Builder params(Params params) { - mParams.add(params); - return this; - } - - /** - * Add several file parameters. - */ - public Builder file(String key, File file) { - mParams.file(key, file); - return this; - } - - /** - * Add files parameter. - */ - public Builder files(String key, List files) { - mParams.files(key, files); - return this; - } - - /** - * Add binary parameter. - */ - public Builder binary(String key, Binary binary) { - mParams.binary(key, binary); - return this; - } - - /** - * Add several binary parameters. - */ - public Builder binaries(String key, List binaries) { - mParams.binaries(key, binaries); - return this; - } - - /** - * Remove parameters. - */ - public Builder removeParam(String key) { - mParams.remove(key); - return this; - } - - /** - * Clear parameters. - */ - public Builder clearParams() { - mParams.clear(); - return this; - } - - public FormBody build() { - return new FormBody(this); - } - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/Headers.java b/kalle/src/main/java/com/yanzhenjie/kalle/Headers.java deleted file mode 100644 index 304add2a4..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/Headers.java +++ /dev/null @@ -1,515 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -import android.os.Build; -import android.text.TextUtils; - -import com.yanzhenjie.kalle.util.ListMap; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.net.HttpCookie; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.TimeZone; -import java.util.TreeMap; - -/** - *

- * Http header. - *

- * Created in Jan 10, 2016 2:29:42 PM. - */ -public class Headers extends ListMap { - - public static final String TIME_FORMAT_HTTP = "EEE, dd MMM y HH:mm:ss 'GMT'"; - public static final TimeZone TIME_ZONE_GMT = TimeZone.getTimeZone("GMT"); - - public static final String KEY_ACCEPT = "Accept"; - public static final String VALUE_ACCEPT_ALL = "*/*"; - public static final String KEY_ACCEPT_ENCODING = "Accept-Encoding"; - public static final String VALUE_ACCEPT_ENCODING = "gzip, deflate"; - public static final String KEY_ACCEPT_LANGUAGE = "Accept-Language"; - public static final String VALUE_ACCEPT_LANGUAGE = getLanguage(); - public static final String KEY_ACCEPT_RANGE = "Accept-Range"; - public static final String KEY_COOKIE = "Cookie"; - public static final String KEY_CONTENT_DISPOSITION = "Content-Disposition"; - public static final String KEY_CONTENT_ENCODING = "Content-Encoding"; - public static final String KEY_CONTENT_LENGTH = "Content-Length"; - public static final String KEY_CONTENT_RANGE = "Content-Range"; - public static final String KEY_CONTENT_TYPE = "Content-Type"; - public static final String VALUE_APPLICATION_URLENCODED = "application/x-www-form-urlencoded"; - public static final String VALUE_APPLICATION_FORM = "multipart/form-data"; - public static final String VALUE_APPLICATION_STREAM = "application/octet-stream"; - public static final String VALUE_APPLICATION_JSON = "application/json"; - public static final String VALUE_APPLICATION_XML = "application/xml"; - public static final String KEY_CACHE_CONTROL = "Cache-Control"; - public static final String KEY_CONNECTION = "Connection"; - public static final String VALUE_KEEP_ALIVE = "keep-alive"; - public static final String VALUE_CLOSE = "close"; - public static final String KEY_DATE = "Date"; - public static final String KEY_EXPIRES = "Expires"; - public static final String KEY_E_TAG = "ETag"; - public static final String KEY_HOST = "Host"; - public static final String KEY_IF_MODIFIED_SINCE = "If-Modified-Since"; - public static final String KEY_IF_NONE_MATCH = "If-None-Match"; - public static final String KEY_LAST_MODIFIED = "Last-Modified"; - public static final String KEY_LOCATION = "Location"; - public static final String KEY_RANGE = "Range"; - public static final String KEY_SET_COOKIE = "Set-Cookie"; - public static final String KEY_USER_AGENT = "User-Agent"; - public static final String VALUE_USER_AGENT = getUserAgent(); - - public Headers() { - super(new TreeMap>(new Comparator() { - @Override - public int compare(String o1, String o2) { - return o1.compareTo(o2); - } - })); - } - - /** - * Format to Hump-shaped words. - */ - public static String formatKey(String key) { - if (TextUtils.isEmpty(key)) return null; - - key = key.toLowerCase(Locale.ENGLISH); - String[] words = key.split("-"); - - StringBuilder builder = new StringBuilder(); - for (String word : words) { - String first = word.substring(0, 1); - String end = word.substring(1); - builder.append(first.toUpperCase(Locale.ENGLISH)).append(end).append("-"); - } - if (builder.length() > 0) { - builder.deleteCharAt(builder.lastIndexOf("-")); - } - return builder.toString(); - } - - /** - * From the json format String parsing out the {@code Map>} data. - */ - public static Headers fromJSONString(String jsonString) throws JSONException { - Headers headers = new Headers(); - JSONObject jsonObject = new JSONObject(jsonString); - Iterator keySet = jsonObject.keys(); - while (keySet.hasNext()) { - String key = keySet.next(); - String value = jsonObject.optString(key); - JSONArray values = new JSONArray(value); - for (int i = 0; i < values.length(); i++) { - headers.add(key, values.optString(i)); - } - } - return headers; - } - - /** - * Into a json format string. - */ - public static String toJSONString(Headers headers) { - JSONObject jsonObject = new JSONObject(); - Set>> entrySet = headers.entrySet(); - for (Map.Entry> entry : entrySet) { - String key = entry.getKey(); - List values = entry.getValue(); - JSONArray value = new JSONArray(values); - try { - jsonObject.put(key, value); - } catch (JSONException ignored) { - } - } - return jsonObject.toString(); - } - - /** - * Into a single key-value map. - */ - public static Map getRequestHeaders(Headers headers) { - Map headerMap = new LinkedHashMap<>(); - for (Map.Entry> entry : headers.entrySet()) { - String key = entry.getKey(); - List value = entry.getValue(); - String trueValue = TextUtils.join("; ", value); - headerMap.put(key, trueValue); - } - return headerMap; - } - - /** - * All the cookies in header information. - */ - public static List getHttpCookieList(Headers headers) { - List cookies = new ArrayList<>(); - for (String key : headers.keySet()) { - if (key.equalsIgnoreCase(KEY_SET_COOKIE)) { - List cookieValues = headers.get(key); - for (String cookieStr : cookieValues) { - cookies.addAll(HttpCookie.parse(cookieStr)); - } - } - } - return cookies; - } - - /** - * A value of the header information. - * - * @param content like {@code text/html;charset=utf-8}. - * @param key like {@code charset}. - * @param defaultValue list {@code utf-8}. - * @return If you have a value key, you will return the parsed value if you don't return the default value. - */ - public static String parseSubValue(String content, String key, String defaultValue) { - if (!TextUtils.isEmpty(content) && !TextUtils.isEmpty(key)) { - StringTokenizer stringTokenizer = new StringTokenizer(content, ";"); - while (stringTokenizer.hasMoreElements()) { - String valuePair = stringTokenizer.nextToken(); - int index = valuePair.indexOf('='); - if (index > 0) { - String name = valuePair.substring(0, index).trim(); - if (key.equalsIgnoreCase(name)) { - defaultValue = valuePair.substring(index + 1).trim(); - break; - } - } - } - } - return defaultValue; - } - - /** - * Parse the time in GMT format to milliseconds. - */ - public static long formatGMTToMillis(String gmtTime) throws ParseException { - SimpleDateFormat formatter = new SimpleDateFormat(TIME_FORMAT_HTTP, Locale.US); - formatter.setTimeZone(TIME_ZONE_GMT); - Date date = formatter.parse(gmtTime); - return date.getTime(); - } - - /** - * Parse the time in milliseconds to GMT format. - */ - public static String formatMillisToGMT(long milliseconds) { - Date date = new Date(milliseconds); - SimpleDateFormat simpleDateFormat = new SimpleDateFormat(TIME_FORMAT_HTTP, Locale.US); - simpleDateFormat.setTimeZone(TIME_ZONE_GMT); - return simpleDateFormat.format(date); - } - - /** - * Analysis the headers of the cache is valid time. - * - * @param headers http headers header. - * @return Time corresponding milliseconds. - */ - public static long analysisCacheExpires(Headers headers) { - final long now = System.currentTimeMillis(); - - long maxAge = 0; - long staleWhileRevalidate = 0; - - String cacheControl = headers.getCacheControl(); - if (!TextUtils.isEmpty(cacheControl)) { - StringTokenizer tokens = new StringTokenizer(cacheControl, ","); - while (tokens.hasMoreTokens()) { - String token = tokens.nextToken().trim().toLowerCase(Locale.getDefault()); - if ((token.equals("no-cache") || token.equals("no-store"))) { - return 0; - } else if (token.startsWith("max-age=")) { - maxAge = Long.parseLong(token.substring(8)) * 1000L; - } else if (token.startsWith("must-revalidate")) { - // If must-revalidate, It must be from the server to validate expired. - return 0; - } else if (token.startsWith("stale-while-revalidate=")) { - staleWhileRevalidate = Long.parseLong(token.substring(23)) * 1000L; - } - } - } - - long localExpire = now;// Local expires time of cache. - - // Have CacheControl. - if (!TextUtils.isEmpty(cacheControl)) { - localExpire += maxAge; - if (staleWhileRevalidate > 0) { - localExpire += staleWhileRevalidate; - } - - return localExpire; - } - - final long expires = headers.getExpires(); - final long date = headers.getDate(); - - // If the server through control the cache Expires. - if (expires > date) { - return now + expires - date; - } - return 0; - } - - /** - * Get language. - */ - public static String getLanguage() { - Locale locale = Locale.getDefault(); - String language = locale.getLanguage(); - String country = locale.getCountry(); - StringBuilder builder = new StringBuilder(language); - if (!TextUtils.isEmpty(country)) - builder.append('-').append(country).append(',').append(language); - return builder.toString(); - } - - /** - * Get User-Agent. - */ - public static String getUserAgent() { - String webUserAgent = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/534.30 (KHTML, like Gecko) Version/5.0 %sSafari/534.30"; - - StringBuffer buffer = new StringBuffer(); - buffer.append(Build.VERSION.RELEASE).append("; "); - - Locale locale = Locale.getDefault(); - String language = locale.getLanguage(); - if (TextUtils.isEmpty(language)) { - buffer.append(language.toLowerCase(locale)); - final String country = locale.getCountry(); - if (!TextUtils.isEmpty(country)) { - buffer.append("-"); - buffer.append(country.toLowerCase(locale)); - } - } else { - buffer.append("en"); - } - if ("REL".equals(Build.VERSION.CODENAME)) { - if (Build.MODEL.length() > 0) { - buffer.append("; "); - buffer.append(Build.MODEL); - } - } - if (Build.ID.length() > 0) { - buffer.append(" Api/"); - buffer.append(Build.ID); - } - return String.format(webUserAgent, buffer, "Mobile "); - } - - @Override - public void add(String key, String value) { - if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(value)) - super.add(formatKey(key), value); - } - - @Override - public void set(String key, String value) { - if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(value)) - super.set(formatKey(key), value); - } - - @Override - public void add(String key, List values) { - if (!TextUtils.isEmpty(key) && !values.isEmpty()) - super.add(formatKey(key), values); - } - - @Override - public void set(String key, List values) { - if (!TextUtils.isEmpty(key) && !values.isEmpty()) - super.set(formatKey(key), values); - } - - public void add(Headers headers) { - for (Map.Entry> entry : headers.entrySet()) { - String key = entry.getKey(); - List values = entry.getValue(); - for (String value : values) { - add(key, value); - } - } - } - - @Override - public List remove(String key) { - return super.remove(formatKey(key)); - } - - @Override - public List get(String key) { - return super.get(formatKey(key)); - } - - @Override - public String getFirst(String key) { - return super.getFirst(formatKey(key)); - } - - @Override - public boolean containsKey(String key) { - return super.containsKey(formatKey(key)); - } - - /** - * Replace all. - */ - public void set(Headers headers) { - for (Map.Entry> entry : headers.entrySet()) { - set(entry.getKey(), entry.getValue()); - } - } - - /** - * {@value #KEY_CACHE_CONTROL}. - * - * @return CacheControl. - */ - public String getCacheControl() { - List cacheControls = get(KEY_CACHE_CONTROL); - if (cacheControls == null) cacheControls = Collections.emptyList(); - return TextUtils.join(",", cacheControls); - } - - /** - * {@value KEY_CONTENT_DISPOSITION}. - * - * @return {@value KEY_CONTENT_DISPOSITION}. - */ - public String getContentDisposition() { - return getFirst(KEY_CONTENT_DISPOSITION); - } - - /** - * {@value #KEY_CONTENT_ENCODING}. - * - * @return ContentEncoding. - */ - public String getContentEncoding() { - return getFirst(KEY_CONTENT_ENCODING); - } - - /** - * {@value #KEY_CONTENT_LENGTH}. - * - * @return ContentLength. - */ - public long getContentLength() { - String contentLength = getFirst(KEY_CONTENT_LENGTH); - if (TextUtils.isEmpty(contentLength)) contentLength = "0"; - return Long.parseLong(contentLength); - } - - /** - * {@value #KEY_CONTENT_TYPE}. - * - * @return ContentType. - */ - public String getContentType() { - return getFirst(KEY_CONTENT_TYPE); - } - - /** - * {@value #KEY_CONTENT_RANGE}. - * - * @return ContentRange. - */ - public String getContentRange() { - return getFirst(KEY_CONTENT_RANGE); - } - - /** - * {@value #KEY_DATE}. - * - * @return Date. - */ - public long getDate() { - return getDateField(KEY_DATE); - } - - /** - * {@value #KEY_E_TAG}. - * - * @return ETag. - */ - public String getETag() { - return getFirst(KEY_E_TAG); - } - - /** - * {@value #KEY_EXPIRES}. - * - * @return Expiration. - */ - public long getExpires() { - return getDateField(KEY_EXPIRES); - } - - /** - * {@value #KEY_LAST_MODIFIED}. - * - * @return LastModified. - */ - public long getLastModified() { - return getDateField(KEY_LAST_MODIFIED); - } - - /** - * {@value #KEY_LOCATION}. - * - * @return Location. - */ - public String getLocation() { - return getFirst(KEY_LOCATION); - } - - /** - *

- * Returns the date value in milliseconds since 1970.1.1, 00:00h corresponding to the header field field. The - * defaultValue will be returned if no such field can be found in the headers header. - *

- * - * @param key the header field name. - * @return the header field represented in milliseconds since January 1, 1970 GMT. - */ - private long getDateField(String key) { - String value = getFirst(key); - if (!TextUtils.isEmpty(value)) - try { - return formatGMTToMillis(value); - } catch (ParseException ignored) { - } - return 0; - } -} diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/JsonBody.kt b/kalle/src/main/java/com/yanzhenjie/kalle/JsonBody.kt deleted file mode 100644 index 4fe84c74c..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/JsonBody.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle - -import org.json.JSONArray -import org.json.JSONObject -import java.nio.charset.Charset - -class JsonBody @JvmOverloads constructor( - body: String, - charset: Charset = Kalle.getConfig().charset -) : StringBody(body, charset, Headers.VALUE_APPLICATION_JSON) { - constructor(body: JSONObject) : this(body.toString()) - constructor(body: JSONArray) : this(body.toString()) - constructor(body: Map) : this(JSONObject(body)) - constructor(vararg body: Pair) : this(body.toMap()) -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/Kalle.java b/kalle/src/main/java/com/yanzhenjie/kalle/Kalle.java deleted file mode 100644 index 0897b034c..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/Kalle.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -import android.util.Log; - -import com.yanzhenjie.kalle.download.BodyDownload; -import com.yanzhenjie.kalle.download.UrlDownload; -import com.yanzhenjie.kalle.simple.SimpleBodyRequest; -import com.yanzhenjie.kalle.simple.SimpleUrlRequest; - -public final class Kalle { - - private static KalleConfig sConfig; - - private Kalle() { - } - - public static KalleConfig getConfig() { - setConfig(null); - return sConfig; - } - - public static void setConfig(KalleConfig config) { - if (sConfig == null) { - synchronized (KalleConfig.class) { - if (sConfig == null) - sConfig = config == null ? KalleConfig.newBuilder().build() : config; - else Log.w("Kalle", new IllegalStateException("Only allowed to configure once.")); - } - } - } - - public static SimpleUrlRequest.Api get(String url) { - return SimpleUrlRequest.newApi(Url.newBuilder(url).build(), RequestMethod.GET); - } - - public static SimpleUrlRequest.Api get(Url url) { - return SimpleUrlRequest.newApi(url, RequestMethod.GET); - } - - public static SimpleUrlRequest.Api head(String url) { - return SimpleUrlRequest.newApi(Url.newBuilder(url).build(), RequestMethod.HEAD); - } - - public static SimpleUrlRequest.Api head(Url url) { - return SimpleUrlRequest.newApi(url, RequestMethod.HEAD); - } - - public static SimpleUrlRequest.Api options(String url) { - return SimpleUrlRequest.newApi(Url.newBuilder(url).build(), RequestMethod.OPTIONS); - } - - public static SimpleUrlRequest.Api options(Url url) { - return SimpleUrlRequest.newApi(url, RequestMethod.OPTIONS); - } - - public static SimpleUrlRequest.Api trace(String url) { - return SimpleUrlRequest.newApi(Url.newBuilder(url).build(), RequestMethod.TRACE); - } - - public static SimpleUrlRequest.Api trace(Url url) { - return SimpleUrlRequest.newApi(url, RequestMethod.TRACE); - } - - public static SimpleBodyRequest.Api post(String url) { - return SimpleBodyRequest.newApi(Url.newBuilder(url).build(), RequestMethod.POST); - } - - public static SimpleBodyRequest.Api post(Url url) { - return SimpleBodyRequest.newApi(url, RequestMethod.POST); - } - - public static SimpleBodyRequest.Api put(String url) { - return SimpleBodyRequest.newApi(Url.newBuilder(url).build(), RequestMethod.PUT); - } - - public static SimpleBodyRequest.Api put(Url url) { - return SimpleBodyRequest.newApi(url, RequestMethod.PUT); - } - - public static SimpleBodyRequest.Api patch(String url) { - return SimpleBodyRequest.newApi(Url.newBuilder(url).build(), RequestMethod.PATCH); - } - - public static SimpleBodyRequest.Api patch(Url url) { - return SimpleBodyRequest.newApi(url, RequestMethod.PATCH); - } - - public static SimpleBodyRequest.Api delete(String url) { - return SimpleBodyRequest.newApi(Url.newBuilder(url).build(), RequestMethod.DELETE); - } - - public static SimpleBodyRequest.Api delete(Url url) { - return SimpleBodyRequest.newApi(url, RequestMethod.DELETE); - } - - public static class Download { - - public static UrlDownload.Api get(String url) { - return UrlDownload.newApi(Url.newBuilder(url).build(), RequestMethod.GET); - } - - public static UrlDownload.Api get(Url url) { - return UrlDownload.newApi(url, RequestMethod.GET); - } - - public static UrlDownload.Api head(String url) { - return UrlDownload.newApi(Url.newBuilder(url).build(), RequestMethod.HEAD); - } - - public static UrlDownload.Api head(Url url) { - return UrlDownload.newApi(url, RequestMethod.HEAD); - } - - public static UrlDownload.Api options(String url) { - return UrlDownload.newApi(Url.newBuilder(url).build(), RequestMethod.OPTIONS); - } - - public static UrlDownload.Api options(Url url) { - return UrlDownload.newApi(url, RequestMethod.OPTIONS); - } - - public static UrlDownload.Api trace(String url) { - return UrlDownload.newApi(Url.newBuilder(url).build(), RequestMethod.TRACE); - } - - public static UrlDownload.Api trace(Url url) { - return UrlDownload.newApi(url, RequestMethod.TRACE); - } - - public static BodyDownload.Api post(String url) { - return BodyDownload.newApi(Url.newBuilder(url).build(), RequestMethod.POST); - } - - public static BodyDownload.Api post(Url url) { - return BodyDownload.newApi(url, RequestMethod.POST); - } - - public static BodyDownload.Api put(String url) { - return BodyDownload.newApi(Url.newBuilder(url).build(), RequestMethod.PUT); - } - - public static BodyDownload.Api put(Url url) { - return BodyDownload.newApi(url, RequestMethod.PUT); - } - - public static BodyDownload.Api patch(String url) { - return BodyDownload.newApi(Url.newBuilder(url).build(), RequestMethod.PATCH); - } - - public static BodyDownload.Api patch(Url url) { - return BodyDownload.newApi(url, RequestMethod.PATCH); - } - - public static BodyDownload.Api delete(String url) { - return BodyDownload.newApi(Url.newBuilder(url).build(), RequestMethod.DELETE); - } - - public static BodyDownload.Api delete(Url url) { - return BodyDownload.newApi(url, RequestMethod.DELETE); - } - } -} diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/KalleConfig.java b/kalle/src/main/java/com/yanzhenjie/kalle/KalleConfig.java deleted file mode 100644 index a89786fd0..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/KalleConfig.java +++ /dev/null @@ -1,363 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -import com.yanzhenjie.kalle.connect.ConnectFactory; -import com.yanzhenjie.kalle.connect.Interceptor; -import com.yanzhenjie.kalle.connect.Network; -import com.yanzhenjie.kalle.cookie.CookieStore; -import com.yanzhenjie.kalle.recorder.LogRecorder; -import com.yanzhenjie.kalle.simple.Converter; -import com.yanzhenjie.kalle.simple.cache.CacheStore; -import com.yanzhenjie.kalle.ssl.SSLUtils; -import com.yanzhenjie.kalle.urlconnect.URLConnectionFactory; -import com.yanzhenjie.kalle.util.MainExecutor; -import com.yanzhenjie.kalle.util.WorkExecutor; - -import java.net.Proxy; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.Executor; -import java.util.concurrent.TimeUnit; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLSocketFactory; - -import static com.yanzhenjie.kalle.Headers.KEY_ACCEPT; -import static com.yanzhenjie.kalle.Headers.KEY_ACCEPT_ENCODING; -import static com.yanzhenjie.kalle.Headers.KEY_ACCEPT_LANGUAGE; -import static com.yanzhenjie.kalle.Headers.KEY_CONNECTION; -import static com.yanzhenjie.kalle.Headers.KEY_CONTENT_TYPE; -import static com.yanzhenjie.kalle.Headers.KEY_USER_AGENT; -import static com.yanzhenjie.kalle.Headers.VALUE_ACCEPT_ALL; -import static com.yanzhenjie.kalle.Headers.VALUE_ACCEPT_ENCODING; -import static com.yanzhenjie.kalle.Headers.VALUE_ACCEPT_LANGUAGE; -import static com.yanzhenjie.kalle.Headers.VALUE_APPLICATION_URLENCODED; -import static com.yanzhenjie.kalle.Headers.VALUE_KEEP_ALIVE; -import static com.yanzhenjie.kalle.Headers.VALUE_USER_AGENT; - -/** - *

Initialize the save parameters.

- * Created by Zhenjie Yan on 2017/6/14. - */ -public final class KalleConfig { - - private final Executor mWorkExecutor; - private final Executor mMainExecutor; - private final Charset mCharset; - private final Headers mHeaders; - private final Proxy mProxy; - private final SSLSocketFactory mSSLSocketFactory; - private final HostnameVerifier mHostnameVerifier; - private final int mConnectTimeout; - private final int mReadTimeout; - private final Params mParams; - private final CacheStore mCacheStore; - private final Network mNetwork; - private final ConnectFactory mConnectFactory; - private final CookieStore mCookieStore; - private final List mInterceptors; - private final Converter mConverter; - - private KalleConfig(Builder builder) { - this.mWorkExecutor = builder.mWorkExecutor == null ? new WorkExecutor() : builder.mWorkExecutor; - this.mMainExecutor = builder.mMainExecutor == null ? new MainExecutor() : builder.mMainExecutor; - - this.mCharset = builder.mCharset == null ? Charset.defaultCharset() : builder.mCharset; - this.mHeaders = builder.mHeaders; - this.mProxy = builder.mProxy; - this.mSSLSocketFactory = builder.mSSLSocketFactory == null ? SSLUtils.SSL_SOCKET_FACTORY : builder.mSSLSocketFactory; - this.mHostnameVerifier = builder.mHostnameVerifier == null ? SSLUtils.HOSTNAME_VERIFIER : builder.mHostnameVerifier; - this.mConnectTimeout = builder.mConnectTimeout <= 0 ? 10000 : builder.mConnectTimeout; - this.mReadTimeout = builder.mReadTimeout <= 0 ? 10000 : builder.mReadTimeout; - this.mParams = builder.mParams.build(); - - this.mCacheStore = builder.mCacheStore == null ? CacheStore.DEFAULT : builder.mCacheStore; - - this.mNetwork = builder.mNetwork == null ? Network.DEFAULT : builder.mNetwork; - this.mConnectFactory = builder.mConnectFactory == null ? URLConnectionFactory.newBuilder().build() : builder.mConnectFactory; - this.mCookieStore = builder.mCookieStore == null ? CookieStore.DEFAULT : builder.mCookieStore; - this.mInterceptors = Collections.unmodifiableList(builder.mInterceptors); - - this.mConverter = builder.mConverter == null ? Converter.DEFAULT : builder.mConverter; - } - - public static Builder newBuilder() { - return new Builder(); - } - - public Executor getWorkExecutor() { - return mWorkExecutor; - } - - public Executor getMainExecutor() { - return mMainExecutor; - } - - public Charset getCharset() { - return mCharset; - } - - public Headers getHeaders() { - return mHeaders; - } - - public Proxy getProxy() { - return mProxy; - } - - public SSLSocketFactory getSSLSocketFactory() { - return mSSLSocketFactory; - } - - public HostnameVerifier getHostnameVerifier() { - return mHostnameVerifier; - } - - public int getConnectTimeout() { - return mConnectTimeout; - } - - public int getReadTimeout() { - return mReadTimeout; - } - - public Params getParams() { - return mParams; - } - - public CacheStore getCacheStore() { - return mCacheStore; - } - - public Network getNetwork() { - return mNetwork; - } - - public ConnectFactory getConnectFactory() { - return mConnectFactory; - } - - public CookieStore getCookieStore() { - return mCookieStore; - } - - public List getInterceptor() { - return mInterceptors; - } - - public Converter getConverter() { - return mConverter; - } - - public final static class Builder { - - private Executor mWorkExecutor; - private Executor mMainExecutor; - - private Charset mCharset; - private Headers mHeaders; - private Proxy mProxy; - private SSLSocketFactory mSSLSocketFactory; - private HostnameVerifier mHostnameVerifier; - private int mConnectTimeout; - private int mReadTimeout; - private Params.Builder mParams; - - private CacheStore mCacheStore; - - private Network mNetwork; - private ConnectFactory mConnectFactory; - private CookieStore mCookieStore; - private List mInterceptors; - - private Converter mConverter; - - private Builder() { - this.mHeaders = new Headers(); - this.mParams = Params.newBuilder(); - this.mInterceptors = new ArrayList<>(); - - mHeaders.set(KEY_ACCEPT, VALUE_ACCEPT_ALL); - mHeaders.set(KEY_ACCEPT_ENCODING, VALUE_ACCEPT_ENCODING); - mHeaders.set(KEY_CONTENT_TYPE, VALUE_APPLICATION_URLENCODED); - mHeaders.set(KEY_CONNECTION, VALUE_KEEP_ALIVE); - mHeaders.set(KEY_USER_AGENT, VALUE_USER_AGENT); - mHeaders.set(KEY_ACCEPT_LANGUAGE, VALUE_ACCEPT_LANGUAGE); - } - - /** - * Set global work thread executor. - */ - public Builder workThreadExecutor(Executor executor) { - this.mWorkExecutor = executor; - return this; - } - - /** - * Set global main thread executor. - */ - public Builder mainThreadExecutor(Executor executor) { - this.mMainExecutor = executor; - return this; - } - - /** - * 是否开启日志记录器 - */ - public Builder setLogRecord(boolean enabled) { - LogRecorder.setEnabled(enabled); - return this; - } - - /** - * Global charset. - */ - public Builder charset(Charset charset) { - this.mCharset = charset; - return this; - } - - /** - * Add the global header. - */ - public Builder addHeader(String key, String value) { - mHeaders.add(key, value); - return this; - } - - /** - * Set the global header. - */ - public Builder setHeader(String key, String value) { - mHeaders.set(key, value); - return this; - } - - /** - * Global proxy. - */ - public Builder proxy(Proxy proxy) { - this.mProxy = proxy; - return this; - } - - /** - * Global ssl socket factory. - */ - public Builder sslSocketFactory(SSLSocketFactory sslSocketFactory) { - this.mSSLSocketFactory = sslSocketFactory; - return this; - } - - /** - * Global hostname verifier. - */ - public Builder hostnameVerifier(HostnameVerifier hostnameVerifier) { - this.mHostnameVerifier = hostnameVerifier; - return this; - } - - /** - * Global connection timeout. - */ - public Builder connectionTimeout(int timeout, TimeUnit timeUnit) { - long time = timeUnit.toMillis(timeout); - this.mConnectTimeout = (int) Math.min(time, Integer.MAX_VALUE); - return this; - } - - /** - * Global readResponse timeout. - */ - public Builder readTimeout(int timeout, TimeUnit timeUnit) { - long time = timeUnit.toMillis(timeout); - this.mReadTimeout = (int) Math.min(time, Integer.MAX_VALUE); - return this; - } - - /** - * Add the global param. - */ - public Builder addParam(String key, String value) { - mParams.add(key, value); - return this; - } - - /** - * Global cache store. - */ - public Builder cacheStore(CacheStore cacheStore) { - this.mCacheStore = cacheStore; - return this; - } - - /** - * Global network. - */ - public Builder network(Network network) { - this.mNetwork = network; - return this; - } - - /** - * Global cookie store. - */ - public Builder connectFactory(ConnectFactory factory) { - this.mConnectFactory = factory; - return this; - } - - /** - * Global cookie store. - */ - public Builder cookieStore(CookieStore cookieStore) { - this.mCookieStore = cookieStore; - return this; - } - - /** - * Add the global interceptor. - */ - public Builder addInterceptor(Interceptor interceptor) { - this.mInterceptors.add(interceptor); - return this; - } - - /** - * Add the global interceptor. - */ - public Builder addInterceptors(List interceptors) { - this.mInterceptors.addAll(interceptors); - return this; - } - - /** - * The converter. - */ - public Builder converter(Converter converter) { - this.mConverter = converter; - return this; - } - - public KalleConfig build() { - return new KalleConfig(this); - } - } - -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/NetCancel.kt b/kalle/src/main/java/com/yanzhenjie/kalle/NetCancel.kt deleted file mode 100644 index 3b71db9bf..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/NetCancel.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle - -import java.util.concurrent.ConcurrentHashMap - -object NetCancel { - - private val cancellerMap = ConcurrentHashMap() - - /** - * 添加一个网络请求取消者用于取消网络 - * - * @param uid target request. - * @param canceller canceller. - */ - @Synchronized - fun add(uid: Any?, canceller: Canceller) { - uid ?: return - cancellerMap[canceller] = uid - } - - /** - * 删除网络请求ID - * - * @param uid target request. - */ - @Synchronized - fun remove(uid: Any?) { - uid ?: return - val iterator = cancellerMap.iterator() - while (iterator.hasNext()) { - if (iterator.next().value == uid) iterator.remove() - } - } - - /** - * 取消网络请求 - * - * @param uid 网络请求的ID - */ - @Synchronized - fun cancel(uid: Any?) { - uid ?: return - val iterator = cancellerMap.iterator() - while (iterator.hasNext()) { - val next = iterator.next() - if (uid == next.value) { - iterator.remove() - next.key.cancel() - } - } - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/Params.java b/kalle/src/main/java/com/yanzhenjie/kalle/Params.java deleted file mode 100644 index 67a59864f..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/Params.java +++ /dev/null @@ -1,324 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -import android.net.Uri; -import android.text.TextUtils; - -import java.io.File; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Created by Zhenjie Yan on 2018/2/23. - */ -public class Params { - - private final Map> mMap; - - private Params(Builder builder) { - this.mMap = builder.mMap; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Get parameters by key. - * - * @param key key. - * @return if the key does not exist, it may be null. - */ - public List get(String key) { - return mMap.get(key); - } - - /** - * Get the first value of the key. - * - * @param key key. - * @return if the key does not exist, it may be null. - */ - public Object getFirst(String key) { - List values = mMap.get(key); - if (values != null && values.size() > 0) return values.get(0); - return null; - } - - /** - * Get {@link Set} view of the parameters. - * - * @return a set view of the mappings. - * @see Map#entrySet() - */ - public Set>> entrySet() { - return mMap.entrySet(); - } - - /** - * Get {@link Set} view of the keys. - * - * @return a set view of the keys. - * @see Map#keySet() - */ - public Set keySet() { - return mMap.keySet(); - } - - /** - * No parameters. - * - * @return true if there are no key-values pairs. - * @see Map#isEmpty() - */ - public boolean isEmpty() { - return mMap.isEmpty(); - } - - /** - * Parameters contains the key. - * - * @param key key. - * @return true if there contains the key. - */ - public boolean containsKey(String key) { - return mMap.containsKey(key); - } - - /** - * Does it contain {@link Binary}. - */ - public boolean hasBinary() { - for (Map.Entry> entry : entrySet()) { - List values = entry.getValue(); - if (values.size() > 0) { - for (Object value : values) if (value instanceof Binary) return true; - } - } - return false; - } - - /** - * Convert to {@link UrlBody} - */ - public UrlBody toUrlBody() { - return UrlBody.newBuilder().params(this).build(); - } - - /** - * Convert to {@link FormBody} - */ - public FormBody toFormBody() { - return FormBody.newBuilder().params(this).build(); - } - - /** - * ReBuilder. - */ - public Builder builder() { - Map> map = new LinkedHashMap<>(); - for (Map.Entry> entry : mMap.entrySet()) { - map.put(entry.getKey(), new ArrayList<>(entry.getValue())); - } - return new Builder(map); - } - - @Override - public String toString() { - return toString(false); - } - - public String toString(boolean encode) { - StringBuilder builder = new StringBuilder(); - Set keySet = keySet(); - for (String key : keySet) { - List values = get(key); - for (Object value : values) { - if (value instanceof CharSequence) { - String textValue = encode ? Uri.encode(value.toString()) : value.toString(); - builder.append("&").append(key).append("=").append(textValue); - } - } - } - if (builder.length() > 0) builder.deleteCharAt(0); - return builder.toString(); - } - - public static class Builder { - - private Map> mMap; - - private Builder() { - this.mMap = new LinkedHashMap<>(); - } - - private Builder(Map> map) { - this.mMap = map; - } - - /** - * Add parameter. - */ - public Builder add(String key, int value) { - return add(key, Integer.toString(value)); - } - - /** - * Add parameter. - */ - public Builder add(String key, long value) { - return add(key, Long.toString(value)); - } - - /** - * Add parameter. - */ - public Builder add(String key, boolean value) { - return add(key, Boolean.toString(value)); - } - - /** - * Add parameter. - */ - public Builder add(String key, char value) { - return add(key, String.valueOf(value)); - } - - /** - * Add parameter. - */ - public Builder add(String key, double value) { - return add(key, Double.toString(value)); - } - - /** - * Add parameter. - */ - public Builder add(String key, float value) { - return add(key, Float.toString(value)); - } - - /** - * Add parameter. - */ - public Builder add(String key, short value) { - return add(key, Integer.toString(value)); - } - - /** - * Add parameter. - */ - public Builder add(String key, CharSequence value) { - return add(key, (Object) value); - } - - /** - * Add parameters. - */ - public Builder add(String key, List values) { - for (String value : values) add(key, value); - return this; - } - - /** - * Add parameter. - */ - private Builder add(String key, Object value) { - if (!TextUtils.isEmpty(key)) { - if (!mMap.containsKey(key)) { - mMap.put(key, new ArrayList<>(1)); - } - if (value == null) value = ""; - if (value instanceof File) value = new FileBinary((File) value); - mMap.get(key).add(value); - } - return this; - } - - /** - * Add parameters. - */ - public Builder add(Params params) { - for (Map.Entry> entry : params.entrySet()) { - String key = entry.getKey(); - List valueList = entry.getValue(); - for (Object value : valueList) add(key, value); - } - return this; - } - - /** - * Add parameters. - */ - public Builder set(Params params) { - return clear().add(params); - } - - /** - * Add a file parameter. - */ - public Builder file(String key, File file) { - return add(key, file); - } - - /** - * Add several file parameters. - */ - public Builder files(String key, List files) { - for (File file : files) add(key, file); - return this; - } - - /** - * Add binary parameter. - */ - public Builder binary(String key, Binary binary) { - return add(key, binary); - } - - /** - * Add several binary parameters. - */ - public Builder binaries(String key, List binaries) { - for (Binary binary : binaries) binary(key, binary); - return this; - } - - /** - * Remove parameters by key. - */ - public Builder remove(String key) { - mMap.remove(key); - return this; - } - - /** - * Remove all parameters. - */ - public Builder clear() { - mMap.clear(); - return this; - } - - public Params build() { - return new Params(this); - } - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/ProgressBar.java b/kalle/src/main/java/com/yanzhenjie/kalle/ProgressBar.java deleted file mode 100644 index ceea29290..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/ProgressBar.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -/** - * Created by Zhenjie Yan on 2018/2/11. - */ -public interface ProgressBar { - /** - * Progress has changed. - */ - void progress(T origin, int progress); -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/Request.java b/kalle/src/main/java/com/yanzhenjie/kalle/Request.java deleted file mode 100644 index c623bfe11..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/Request.java +++ /dev/null @@ -1,391 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -import com.yanzhenjie.kalle.recorder.LogRecorder; - -import java.net.Proxy; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLSocketFactory; - -/** - * Created in Nov 4, 2015 8:28:50 AM. - */ -public abstract class Request { - - private final RequestMethod mMethod; - private final Headers mHeaders; - private final Proxy mProxy; - private final SSLSocketFactory mSSLSocketFactory; - private final HostnameVerifier mHostnameVerifier; - private final int mConnectTimeout; - private final int mReadTimeout; - private final Object mTag; - private final Object uid; - private String location; - private String logId = LogRecorder.generateId(); - private String log; - private long timeMillis = System.currentTimeMillis(); - - /** - * 请求Id, 每个请求都有独一无二的Id - */ - public String logId() { - return logId; - } - - /** - * 请求开始时间 - */ - public long getTimeMillis() { - return timeMillis; - } - - /** - * 请求体 - */ - public String getLog() { - if (log == null) { - RequestBody body = body(); - if (body instanceof StringBody) { - return body.toString(); - } else { - return copyParams().toString(); - } - } else return log; - } - - /** - * 设置一个请求体, 默认使用copyParams() - */ - public void setLog(String log) { - this.log = log; - } - - /** - * 一个表示请求的地址值, 因为某些接口可能存在无法通过Url来判断请求地址(例如通过参数区分接口), 这个时候可以通过location来为开发者标识 - * 默认使用Request.url() - */ - public void location(String location) { - this.location = location; - } - - /** - * 一个表示请求的地址值 - */ - public String location() { - if (location != null) { - return location; - } else return url().toString(); - } - - protected > Request(Api api) { - this.mMethod = api.mMethod; - this.mHeaders = api.mHeaders; - - this.mProxy = api.mProxy; - this.mSSLSocketFactory = api.mSSLSocketFactory; - this.mHostnameVerifier = api.mHostnameVerifier; - this.mConnectTimeout = api.mConnectTimeout; - this.mReadTimeout = api.mReadTimeout; - this.mTag = api.mTag; - this.uid = api.uid; - } - - /** - * Get url. - */ - public abstract Url url(); - - /** - * Get params. - */ - public abstract Params copyParams(); - - /** - * Get request body. - */ - public abstract RequestBody body(); - - /** - * Get method. - */ - public RequestMethod method() { - return mMethod; - } - - /** - * Get headers. - */ - public Headers headers() { - return mHeaders; - } - - /** - * Get proxy server. - */ - public Proxy proxy() { - return mProxy; - } - - /** - * Get SSLSocketFactory. - */ - public SSLSocketFactory sslSocketFactory() { - return mSSLSocketFactory; - } - - /** - * Get the HostnameVerifier. - */ - public HostnameVerifier hostnameVerifier() { - return mHostnameVerifier; - } - - /** - * Get the connection timeout time, Unit is a millisecond. - */ - public int connectTimeout() { - return mConnectTimeout; - } - - /** - * Get the readResponse timeout time, Unit is a millisecond. - */ - public int readTimeout() { - return mReadTimeout; - } - - /** - * Get tag. - */ - public Object tag() { - return mTag; - } - - public Object uid() { - return uid; - } - - public static abstract class Api> { - - private final RequestMethod mMethod; - private final Headers mHeaders = new Headers(); - private Proxy mProxy = Kalle.getConfig().getProxy(); - private SSLSocketFactory mSSLSocketFactory = Kalle.getConfig().getSSLSocketFactory(); - private HostnameVerifier mHostnameVerifier = Kalle.getConfig().getHostnameVerifier(); - private int mConnectTimeout = Kalle.getConfig().getConnectTimeout(); - private int mReadTimeout = Kalle.getConfig().getReadTimeout(); - private Object mTag; - private Object uid; - - protected Api(RequestMethod method) { - this.mMethod = method; - this.mHeaders.add(Kalle.getConfig().getHeaders()); - } - - /** - * Overlay path. - */ - public abstract T path(int value); - - /** - * Overlay path. - */ - public abstract T path(long value); - - /** - * Overlay path. - */ - public abstract T path(boolean value); - - /** - * Overlay path. - */ - public abstract T path(char value); - - /** - * Overlay path. - */ - public abstract T path(double value); - - /** - * Overlay path. - */ - public abstract T path(float value); - - /** - * Overlay path. - */ - public abstract T path(String value); - - /** - * Add a new header. - */ - public T addHeader(String key, String value) { - mHeaders.add(key, value); - return (T) this; - } - - /** - * If the target key exists, replace it, if not, add. - */ - public T setHeader(String key, String value) { - mHeaders.set(key, value); - return (T) this; - } - - /** - * Set headers. - */ - public T setHeaders(Headers headers) { - mHeaders.set(headers); - return (T) this; - } - - /** - * Remove the key from the information. - */ - public T removeHeader(String key) { - mHeaders.remove(key); - return (T) this; - } - - /** - * Remove all header. - */ - public T clearHeaders() { - mHeaders.clear(); - return (T) this; - } - - /** - * Add parameter. - */ - public abstract T param(String key, int value); - - /** - * Add parameter. - */ - public abstract T param(String key, long value); - - /** - * Add parameter. - */ - public abstract T param(String key, boolean value); - - /** - * Add parameter. - */ - public abstract T param(String key, char value); - - /** - * Add parameter. - */ - public abstract T param(String key, double value); - - /** - * Add parameter. - */ - public abstract T param(String key, float value); - - /** - * Add parameter. - */ - public abstract T param(String key, short value); - - /** - * Add parameter. - */ - public abstract T param(String key, String value); - - /** - * Add parameters. - */ - public abstract T param(String key, List value); - - /** - * Remove parameters. - */ - public abstract T removeParam(String key); - - /** - * Clear parameters. - */ - public abstract T clearParams(); - - /** - * Proxy information for this request. - */ - public T proxy(Proxy proxy) { - this.mProxy = proxy; - return (T) this; - } - - /** - * SSLSocketFactory for this request. - */ - public T sslSocketFactory(SSLSocketFactory sslSocketFactory) { - this.mSSLSocketFactory = sslSocketFactory; - return (T) this; - } - - /** - * HostnameVerifier for this request. - */ - public T hostnameVerifier(HostnameVerifier hostnameVerifier) { - this.mHostnameVerifier = hostnameVerifier; - return (T) this; - } - - /** - * Connect timeout for this request. - */ - public T connectTimeout(int timeout, TimeUnit timeUnit) { - long time = timeUnit.toMillis(timeout); - this.mConnectTimeout = (int) Math.min(time, Integer.MAX_VALUE); - return (T) this; - } - - /** - * Read timeout for this request. - */ - public T readTimeout(int timeout, TimeUnit timeUnit) { - long time = timeUnit.toMillis(timeout); - this.mReadTimeout = (int) Math.min(time, Integer.MAX_VALUE); - return (T) this; - } - - /** - * Tag. - */ - public T tag(Object tag) { - this.mTag = tag; - return (T) this; - } - - /** - * 唯一标记 - */ - public T uid(Object uid) { - this.uid = uid; - return (T) this; - } - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/RequestBody.java b/kalle/src/main/java/com/yanzhenjie/kalle/RequestBody.java deleted file mode 100644 index 838b9cef0..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/RequestBody.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -/** - * Created by Zhenjie Yan on 2018/2/9. - */ -public interface RequestBody extends Content { -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/RequestMethod.java b/kalle/src/main/java/com/yanzhenjie/kalle/RequestMethod.java deleted file mode 100644 index 4dfcf3a4b..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/RequestMethod.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -import java.util.Locale; - -/** - *

- * HTTP handle method. - *

- * Created in Oct 10, 2015 8:00:48 PM. - */ -public enum RequestMethod { - - GET("GET"), - - POST("POST"), - - PUT("PUT"), - - DELETE("DELETE"), - - HEAD("HEAD"), - - PATCH("PATCH"), - - OPTIONS("OPTIONS"), - - TRACE("TRACE"); - - private final String value; - - RequestMethod(String value) { - this.value = value; - } - - public static RequestMethod reverse(String method) { - method = method.toUpperCase(Locale.ENGLISH); - switch (method) { - case "GET": { - return GET; - } - case "POST": { - return POST; - } - case "PUT": { - return PUT; - } - case "DELETE": { - return DELETE; - } - case "HEAD": { - return HEAD; - } - case "PATCH": { - return PATCH; - } - case "OPTIONS": { - return OPTIONS; - } - case "TRACE": { - return TRACE; - } - default: { - return GET; - } - } - } - - @Override - public String toString() { - return value; - } - - public boolean allowBody() { - switch (this) { - case POST: - case PUT: - case PATCH: - case DELETE: { - return true; - } - default: { - return false; - } - } - } - -} diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/Response.java b/kalle/src/main/java/com/yanzhenjie/kalle/Response.java deleted file mode 100644 index f588a5573..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/Response.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -import com.yanzhenjie.kalle.util.IOUtils; - -import java.io.Closeable; -import java.io.IOException; - -/** - * Created in Oct 15, 2015 8:55:37 PM. - */ -public final class Response implements Closeable { - - private final int mCode; - private final Headers mHeaders; - private final ResponseBody mBody; - private String logBody; - - private Response(Builder builder) { - this.mCode = builder.mCode; - this.mHeaders = builder.mHeaders; - this.mBody = builder.mBody; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * 设置日志信息 - */ - public void setLog(String logBody) { - this.logBody = logBody; - } - - public String getLog() { - return logBody; - } - - /** - * Get the mCode of response. - */ - public int code() { - return mCode; - } - - /** - * Get http headers. - */ - public Headers headers() { - return mHeaders; - } - - /** - * Get http body. - */ - public ResponseBody body() { - return mBody; - } - - @Override - public void close() throws IOException { - IOUtils.closeQuietly(mBody); - } - - /** - * It is a redirect response code. - */ - public boolean isRedirect() { - switch (mCode) { - case 300: - case 301: - case 302: - case 303: - case 307: - case 308: - return true; - case 304: - case 305: - case 306: - default: - return false; - } - } - - public static final class Builder { - private int mCode; - private Headers mHeaders; - private ResponseBody mBody; - - public Builder() { - } - - public Builder code(int code) { - this.mCode = code; - return this; - } - - public Builder headers(Headers headers) { - this.mHeaders = headers; - return this; - } - - public Builder body(ResponseBody body) { - this.mBody = body; - return this; - } - - public Response build() { - return new Response(this); - } - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/StringBody.java b/kalle/src/main/java/com/yanzhenjie/kalle/StringBody.java deleted file mode 100644 index 17156e481..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/StringBody.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -import android.text.TextUtils; - -import com.yanzhenjie.kalle.util.IOUtils; - -import java.io.IOException; -import java.io.OutputStream; -import java.nio.charset.Charset; - -import static com.yanzhenjie.kalle.Headers.VALUE_APPLICATION_STREAM; - -/** - * Created by Zhenjie Yan on 2018/2/11. - */ -public class StringBody extends BaseContent implements RequestBody { - - private final String mBody; - private final Charset mCharset; - private final String mContentType; - - public StringBody(String body) { - this(body, Kalle.getConfig().getCharset()); - } - - public StringBody(String body, Charset charset) { - this(body, charset, VALUE_APPLICATION_STREAM); - } - - public StringBody(String body, String contentType) { - this(body, Kalle.getConfig().getCharset(), contentType); - } - - public StringBody(String body, Charset charset, String contentType) { - this.mBody = body; - this.mCharset = charset; - this.mContentType = contentType; - } - - @Override - public long contentLength() { - if (TextUtils.isEmpty(mBody)) return 0; - return IOUtils.toByteArray(mBody, mCharset).length; - } - - @Override - public String contentType() { - return mContentType + "; charset=" + mCharset.name(); - } - - @Override - protected void onWrite(OutputStream writer) throws IOException { - IOUtils.write(writer, mBody, mCharset); - } - - @Override - public String toString() { - return mBody; - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/Url.java b/kalle/src/main/java/com/yanzhenjie/kalle/Url.java deleted file mode 100644 index 4494d82b8..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/Url.java +++ /dev/null @@ -1,388 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -import android.net.Uri; -import android.text.TextUtils; -import android.webkit.URLUtil; - -import java.net.URI; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -/** - * Add the mPath to the URL, such as: - *
- * Url url = Url.newBuilder("http://www.example.com/xx")
- *      .scheme("https")
- *      .port(8080)
- *      .path("yy")
- *      .query("abc", "123")
- *      .setFragment("article")
- *      .build();
- * ...
- * The real url is: https://www.example.com:8080/xx/yy?abc=123#article.
- * 
- *
- * Url url = Url.newBuilder("http://www.example.com/xx/yy?abc=123")
- *      .setPath("/aa/bb/cc")
- *      .setQuery("mln=456&ijk=789")
- *      .build();
- * ...
- * The real url is: http://www.example.com/aa/bb/cc?mln=456&ijk=789.
- * 
- *
- * Url url = Url.newBuilder("http://www.example.com/user/photo/search?name=abc").build();
- * Url newUrl = url.location("../../get?name=mln");
- * ...
- * The new url is: http://www.example.com/get?name=abc.
- * 
- * Created by Zhenjie Yan on 2018/2/9. - */ -public class Url { - - private final String mScheme; - private final String mHost; - private final int mPort; - private final String mPath; - private final String mQuery; - private final String mFragment; - private Url(Builder builder) { - this.mScheme = builder.mScheme; - this.mHost = builder.mHost; - this.mPort = builder.mPort; - this.mPath = builder.mPath; - this.mQuery = builder.mQuery.build().toString(false); - this.mFragment = builder.mFragment; - } - - public static Builder newBuilder(String url) { - return new Builder(url); - } - - private static int convertPort(int port) { - return port > 0 ? port : 80; - } - - private static List convertPath(String path) { - List pathList = new LinkedList<>(); - if (!TextUtils.isEmpty(path)) { - while (path.startsWith("/")) path = path.substring(1); - while (path.endsWith("/")) path = path.substring(0, path.length() - 1); - String[] pathArray = path.split("/"); - Collections.addAll(pathList, pathArray); - } - return pathList; - } - - private static Params convertQuery(String query) { - Params.Builder params = Params.newBuilder(); - if (!TextUtils.isEmpty(query)) { - if (query.startsWith("?")) query = query.substring(1); - String[] paramArray = query.split("&"); - for (String param : paramArray) { - String key; - String value = ""; - int end; - if ((end = param.indexOf("=")) > 0) { - key = param.substring(0, end); - if (end < param.length() - 1) { - value = param.substring(end + 1); - } - } else { - key = param; - } - params.add(key, value); - } - } - return params.build(); - } - - private static String wrapPort(int port) { - return (port <= 0 || port == 80) ? "" : String.format(Locale.getDefault(), ":%d", port); - } - - private static String wrapPath(List pathList, boolean encode) { - if (pathList.isEmpty()) return "/"; - StringBuilder builder = new StringBuilder(); - for (String path : pathList) { - builder.append("/").append(encode ? Uri.encode(path) : path); - } - return builder.toString(); - } - - private static String wrapQuery(Params params, boolean encode) { - String query = params.toString(encode); - return TextUtils.isEmpty(query) ? "" : String.format("?%s", query); - } - - private static String wrapFragment(String fragment, boolean encode) { - return TextUtils.isEmpty(fragment) ? "" : String.format("#%s", encode ? Uri.encode(fragment) : fragment); - } - - public String getScheme() { - return mScheme; - } - - public String getHost() { - return mHost; - } - - public int getPort() { - return mPort; - } - - public String getPath() { - return mPath; - } - - public List copyPath() { - return convertPath(mPath); - } - - public String getQuery() { - return mQuery; - } - - /** - * @deprecated use {@link #getParams()} instead. - */ - @Deprecated - public Params copyQuery() { - return getParams(); - } - - public Params getParams() { - return convertQuery(mQuery); - } - - public String getFragment() { - return mFragment; - } - - public Builder builder() { - return newBuilder(toString()); - } - - @Override - public String toString() { - return toString(false); - } - - public String toString(boolean encode) { - String query = wrapQuery(convertQuery(mQuery), encode); - String fragment = wrapFragment(mFragment, encode); - return mScheme + "://" + mHost + wrapPort(mPort) + mPath + query + fragment; - } - - public Url location(String location) { - if (TextUtils.isEmpty(location)) return null; - - if (URLUtil.isNetworkUrl(location)) { - return newBuilder(location).build(); - } - - URI newUri = URI.create(location); - if (location.startsWith("/")) { - return builder().setPath(newUri.getPath()) - .setQuery(newUri.getQuery()) - .setFragment(newUri.getFragment()) - .build(); - } else if (location.contains("../")) { - List oldPathList = convertPath(getPath()); - List newPathList = convertPath(newUri.getPath()); - - int start = newPathList.lastIndexOf(".."); - - newPathList = newPathList.subList(start + 1, newPathList.size()); - - if (!oldPathList.isEmpty()) { - oldPathList = oldPathList.subList(0, oldPathList.size() - start - 2); - oldPathList.addAll(newPathList); - String path = TextUtils.join("/", oldPathList); - return builder().setPath(path).setQuery(newUri.getQuery()).setFragment(newUri.getFragment()).build(); - } - - String path = TextUtils.join("/", newPathList); - - return builder().setPath(path).setQuery(newUri.getQuery()).setFragment(newUri.getFragment()).build(); - } else { - String path = (getPath() + newUri.getPath()).replace("//", "/"); - return builder().setPath(path).setQuery(newUri.getQuery()).setFragment(newUri.getFragment()).build(); - } - } - - public static class Builder { - - private String mScheme; - private String mHost; - private int mPort; - private String mPath; - private Params.Builder mQuery; - private String mFragment; - - private Builder(String url) { - URI uri = URI.create(url); - - this.mScheme = uri.getScheme(); - this.mHost = uri.getHost(); - this.mPort = convertPort(uri.getPort()); - this.mPath = uri.getPath(); - this.mQuery = convertQuery(uri.getQuery()).builder(); - this.mFragment = uri.getFragment(); - } - - public Builder setScheme(String scheme) { - this.mScheme = scheme; - return this; - } - - public Builder setHost(String host) { - this.mHost = host; - return this; - } - - public Builder setPort(int port) { - this.mPort = port; - return this; - } - - public Builder addPath(int value) { - return addPath(Integer.toString(value)); - } - - public Builder addPath(long value) { - return addPath(Long.toString(value)); - } - - public Builder addPath(boolean value) { - return addPath(Boolean.toString(value)); - } - - public Builder addPath(char value) { - return addPath(String.valueOf(value)); - } - - public Builder addPath(double value) { - return addPath(Double.toString(value)); - } - - public Builder addPath(float value) { - return addPath(Float.toString(value)); - } - - public Builder addPath(String path) { - mPath = mPath + "/" + path; - return this; - } - - public Builder setPath(String path) { - mPath = path; - return this; - } - - public Builder clearPath() { - mPath = ""; - return this; - } - - public Builder addQuery(String key, int value) { - return addQuery(key, Integer.toString(value)); - } - - public Builder addQuery(String key, long value) { - return addQuery(key, Long.toString(value)); - } - - public Builder addQuery(String key, boolean value) { - return addQuery(key, Boolean.toString(value)); - } - - public Builder addQuery(String key, char value) { - return addQuery(key, String.valueOf(value)); - } - - public Builder addQuery(String key, double value) { - return addQuery(key, Double.toString(value)); - } - - public Builder addQuery(String key, float value) { - return addQuery(key, Float.toString(value)); - } - - public Builder addQuery(String key, short value) { - return addQuery(key, Integer.toString(value)); - } - - public Builder addQuery(String key, String value) { - mQuery.add(key, value); - return this; - } - - public Builder addQuery(String key, List values) { - for (String value : values) { - addQuery(key, value); - } - return this; - } - - public Builder addQuery(Params query) { - for (Map.Entry> entry : query.entrySet()) { - String key = entry.getKey(); - List values = entry.getValue(); - for (Object value : values) { - if (value instanceof CharSequence) { - String textValue = value.toString(); - addQuery(key, textValue); - } - } - } - return this; - } - - public Builder setQuery(String query) { - mQuery = convertQuery(query).builder(); - return this; - } - - public Builder setQuery(Params query) { - mQuery = query.builder(); - return this; - } - - public Builder removeQuery(String key) { - mQuery.remove(key); - return this; - } - - public Builder clearQuery() { - mQuery.clear(); - return this; - } - - public Builder setFragment(String fragment) { - this.mFragment = fragment; - return this; - } - - public Url build() { - return new Url(this); - } - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/UrlBody.java b/kalle/src/main/java/com/yanzhenjie/kalle/UrlBody.java deleted file mode 100644 index b0a909f86..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/UrlBody.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -import android.text.TextUtils; - -import com.yanzhenjie.kalle.util.IOUtils; - -import java.io.IOException; -import java.io.OutputStream; -import java.nio.charset.Charset; -import java.util.List; - -import static com.yanzhenjie.kalle.Headers.VALUE_APPLICATION_URLENCODED; - -/** - * Created by Zhenjie Yan on 2018/2/24. - */ -public class UrlBody extends BaseContent implements RequestBody { - - private final Params mParams; - private final Charset mCharset; - private final String mContentType; - private UrlBody(Builder builder) { - this.mParams = builder.mParams.build(); - this.mCharset = builder.mCharset == null ? Kalle.getConfig().getCharset() : builder.mCharset; - this.mContentType = TextUtils.isEmpty(builder.mContentType) ? VALUE_APPLICATION_URLENCODED : builder.mContentType; - } - - public static Builder newBuilder() { - return new Builder(); - } - - /** - * Copy parameters from url body. - */ - public Params copyParams() { - return mParams; - } - - @Override - public long contentLength() { - String body = mParams.toString(true); - return IOUtils.toByteArray(body, mCharset).length; - } - - @Override - public String contentType() { - return mContentType + "; charset=" + mCharset.name(); - } - - @Override - protected void onWrite(OutputStream writer) throws IOException { - String body = mParams.toString(true); - IOUtils.write(writer, body, mCharset); - } - - @Override - public String toString() { - return toString(false); - } - - public String toString(boolean encode) { - return mParams.toString(encode); - } - - public static class Builder { - - private Charset mCharset; - private String mContentType; - private Params.Builder mParams; - - private Builder() { - this.mParams = Params.newBuilder(); - } - - /** - * Data charset. - */ - public Builder charset(Charset charset) { - this.mCharset = charset; - return this; - } - - /** - * Content type. - */ - public Builder contentType(String contentType) { - this.mContentType = contentType; - return this; - } - - /** - * Add parameter. - */ - public Builder param(String key, int value) { - mParams.add(key, value); - return this; - } - - /** - * Add parameter. - */ - public Builder param(String key, long value) { - mParams.add(key, value); - return this; - } - - /** - * Add parameter. - */ - public Builder param(String key, boolean value) { - mParams.add(key, value); - return this; - } - - /** - * Add parameter. - */ - public Builder param(String key, char value) { - mParams.add(key, value); - return this; - } - - /** - * Add parameter. - */ - public Builder param(String key, double value) { - mParams.add(key, value); - return this; - } - - /** - * Add parameter. - */ - public Builder param(String key, float value) { - mParams.add(key, value); - return this; - } - - /** - * Add parameter. - */ - public Builder param(String key, short value) { - mParams.add(key, value); - return this; - } - - /** - * Add parameter. - */ - public Builder param(String key, CharSequence value) { - mParams.add(key, value); - return this; - } - - /** - * Add parameter. - */ - public Builder param(String key, String value) { - mParams.add(key, value); - return this; - } - - /** - * Add parameters. - */ - public Builder param(String key, List values) { - mParams.add(key, values); - return this; - } - - /** - * Add parameters. - */ - public Builder params(Params params) { - mParams.add(params); - return this; - } - - /** - * Remove parameters. - */ - public Builder removeParam(String key) { - mParams.remove(key); - return this; - } - - /** - * Clear parameters. - */ - public Builder clearParams() { - mParams.clear(); - return this; - } - - public UrlBody build() { - return new UrlBody(this); - } - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/UrlRequest.java b/kalle/src/main/java/com/yanzhenjie/kalle/UrlRequest.java deleted file mode 100644 index 4eb8cc6c6..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/UrlRequest.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -import java.util.List; - -/** - * Created by Zhenjie Yan on 2018/2/13. - */ -public class UrlRequest extends Request { - - private final Url mUrl; - - protected UrlRequest(Api api) { - super(api); - this.mUrl = api.mUrl.build(); - } - - public static UrlRequest.Builder newBuilder(String url, RequestMethod method) { - return newBuilder(Url.newBuilder(url).build(), method); - } - - public static UrlRequest.Builder newBuilder(Url url, RequestMethod method) { - return new UrlRequest.Builder(url, method); - } - - /** - * @deprecated use {@link #newBuilder(Url, RequestMethod)} instead. - */ - @Deprecated - public static UrlRequest.Builder newBuilder(Url.Builder url, RequestMethod method) { - return newBuilder(url.build(), method); - } - - @Override - public Url url() { - return mUrl; - } - - @Override - public Params copyParams() { - return mUrl.getParams(); - } - - @Override - public RequestBody body() { - return null; - } - - public static class Api> extends Request.Api { - - private Url.Builder mUrl; - - protected Api(Url url, RequestMethod method) { - super(method); - this.mUrl = url.builder(); - this.mUrl.addQuery(Kalle.getConfig().getParams()); - } - - @Override - public T path(int value) { - mUrl.addPath(value); - return (T) this; - } - - @Override - public T path(long value) { - mUrl.addPath(value); - return (T) this; - } - - @Override - public T path(boolean value) { - mUrl.addPath(value); - return (T) this; - } - - @Override - public T path(char value) { - mUrl.addPath(value); - return (T) this; - } - - @Override - public T path(double value) { - mUrl.addPath(value); - return (T) this; - } - - @Override - public T path(float value) { - mUrl.addPath(value); - return (T) this; - } - - @Override - public T path(String value) { - mUrl.addPath(value); - return (T) this; - } - - @Override - public T param(String key, int value) { - mUrl.addQuery(key, value); - return (T) this; - } - - @Override - public T param(String key, long value) { - mUrl.addQuery(key, value); - return (T) this; - } - - @Override - public T param(String key, boolean value) { - mUrl.addQuery(key, value); - return (T) this; - } - - @Override - public T param(String key, char value) { - mUrl.addQuery(key, value); - return (T) this; - } - - @Override - public T param(String key, double value) { - mUrl.addQuery(key, value); - return (T) this; - } - - @Override - public T param(String key, float value) { - mUrl.addQuery(key, value); - return (T) this; - } - - @Override - public T param(String key, short value) { - mUrl.addQuery(key, value); - return (T) this; - } - - @Override - public T param(String key, String value) { - mUrl.addQuery(key, value); - return (T) this; - } - - @Override - public T param(String key, List values) { - mUrl.addQuery(key, values); - return (T) this; - } - - /** - * Add parameters to url. - */ - public T params(Params params) { - mUrl.addQuery(params); - return (T) this; - } - - /** - * Set parameters to url. - */ - public T setParams(Params params) { - mUrl.setQuery(params); - return (T) this; - } - - @Override - public T removeParam(String key) { - mUrl.removeQuery(key); - return (T) this; - } - - @Override - public T clearParams() { - mUrl.clearQuery(); - return (T) this; - } - } - - public static class Builder extends UrlRequest.Api { - - private Builder(Url url, RequestMethod method) { - super(url, method); - } - - public UrlRequest build() { - return new UrlRequest(this); - } - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/XmlBody.java b/kalle/src/main/java/com/yanzhenjie/kalle/XmlBody.java deleted file mode 100644 index 34aa86ed4..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/XmlBody.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle; - -import java.nio.charset.Charset; - -import static com.yanzhenjie.kalle.Headers.VALUE_APPLICATION_XML; - -/** - * Created by Zhenjie Yan on 2018/2/11. - */ -public class XmlBody extends StringBody { - - public XmlBody(String body) { - this(body, Kalle.getConfig().getCharset()); - } - - public XmlBody(String body, Charset charset) { - super(body, charset, VALUE_APPLICATION_XML); - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/connect/BroadcastNetwork.java b/kalle/src/main/java/com/yanzhenjie/kalle/connect/BroadcastNetwork.java deleted file mode 100644 index 00dd51990..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/connect/BroadcastNetwork.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.connect; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.net.ConnectivityManager; -import android.net.wifi.WifiManager; - -/** - * Created by Zhenjie Yan on 2018/2/20. - */ -public class BroadcastNetwork implements Network { - - private final Context mContext; - private final NetworkReceiver mReceiver; - - public BroadcastNetwork(Context context) { - this.mContext = context.getApplicationContext(); - this.mReceiver = new NetworkReceiver(new NetworkChecker(mContext)); - - IntentFilter filter = new IntentFilter(); - filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); - filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); - filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); - filter.addAction("android.net.ethernet.STATE_CHANGE"); - filter.addAction("android.net.ethernet.ETHERNET_STATE_CHANGED"); - filter.addAction(Intent.ACTION_SCREEN_OFF); - filter.addAction(Intent.ACTION_SCREEN_ON); - filter.addAction(Intent.ACTION_USER_PRESENT); - mContext.registerReceiver(mReceiver, filter); - } - - @Override - public boolean isAvailable() { - return mReceiver.mAvailable; - } - - public void destroy() { - mContext.unregisterReceiver(mReceiver); - } - - private static class NetworkReceiver extends BroadcastReceiver { - - private NetworkChecker mChecker; - private boolean mAvailable; - - public NetworkReceiver(NetworkChecker checker) { - this.mChecker = checker; - this.mAvailable = mChecker.isAvailable(); - } - - @Override - public void onReceive(Context context, Intent intent) { - mAvailable = mChecker.isAvailable(); - } - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/connect/ConnectFactory.java b/kalle/src/main/java/com/yanzhenjie/kalle/connect/ConnectFactory.java deleted file mode 100644 index a246013ad..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/connect/ConnectFactory.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.connect; - -import com.yanzhenjie.kalle.Request; - -import java.io.IOException; - -/** - * Created by Zhenjie Yan on 2018/2/20. - */ -public interface ConnectFactory { - /** - * According to the request attribute, - * and the server to establish a connection. - */ - Connection connect(Request request) throws IOException; -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/connect/Connection.java b/kalle/src/main/java/com/yanzhenjie/kalle/connect/Connection.java deleted file mode 100644 index 9a89cb8d8..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/connect/Connection.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.connect; - -import java.io.Closeable; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.List; -import java.util.Map; - -/** - * Created by Zhenjie Yan on 2018/2/20. - */ -public interface Connection extends Closeable { - - /** - * Gets output stream for socket. - */ - OutputStream getOutputStream() throws IOException; - - /** - * Gets response code for server. - */ - int getCode() throws IOException; - - /** - * Gets response headers for server. - */ - Map> getHeaders() throws IOException; - - /** - * Gets input stream for socket. - */ - InputStream getInputStream() throws IOException; - - /** - * Cancel connect. - */ - void disconnect(); - -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/connect/Interceptor.java b/kalle/src/main/java/com/yanzhenjie/kalle/connect/Interceptor.java deleted file mode 100644 index 7d19e7fa5..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/connect/Interceptor.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.connect; - -import com.yanzhenjie.kalle.Response; -import com.yanzhenjie.kalle.connect.http.Chain; - -import java.io.IOException; - -/** - *

- * Intercept before call request. - *

- * Created by Zhenjie Yan on 2018/2/11. - */ -public interface Interceptor { - - /** - * When intercepting the {@link Chain}, - * here can do some signature and login operation, - * it should send a response and return. - * - * @param chain request chain. - * @return the server connection. - * @throws IOException io exception may occur during the implementation, you can handle or throw. - */ - Response intercept(Chain chain) throws IOException; -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/connect/Network.java b/kalle/src/main/java/com/yanzhenjie/kalle/connect/Network.java deleted file mode 100644 index 5d3eb76ce..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/connect/Network.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.connect; - -/** - * Created by Zhenjie Yan on 2018/2/13. - */ -public interface Network { - - /** - * The network has always been available. - */ - Network DEFAULT = new Network() { - @Override - public boolean isAvailable() { - return true; - } - }; - - /** - * Check the network is enable. - */ - boolean isAvailable(); -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/connect/NetworkChecker.java b/kalle/src/main/java/com/yanzhenjie/kalle/connect/NetworkChecker.java deleted file mode 100644 index 45a3df748..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/connect/NetworkChecker.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.connect; - -import android.content.Context; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; -import android.os.Build; -import android.telephony.TelephonyManager; - -import static com.yanzhenjie.kalle.connect.NetworkChecker.NetType.Mobile; -import static com.yanzhenjie.kalle.connect.NetworkChecker.NetType.Mobile2G; -import static com.yanzhenjie.kalle.connect.NetworkChecker.NetType.Mobile3G; -import static com.yanzhenjie.kalle.connect.NetworkChecker.NetType.Mobile4G; -import static com.yanzhenjie.kalle.connect.NetworkChecker.NetType.Wifi; -import static com.yanzhenjie.kalle.connect.NetworkChecker.NetType.Wired; - -/** - * Created by Zhenjie Yan on 2018/2/13. - */ -public class NetworkChecker { - - private ConnectivityManager mManager; - - public NetworkChecker(Context context) { - this.mManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - } - - private static boolean isConnected(NetType netType, NetworkInfo networkInfo) { - if (networkInfo == null) return false; - - switch (netType) { - case Wifi: { - if (!isConnected(networkInfo)) return false; - return networkInfo.getType() == ConnectivityManager.TYPE_WIFI; - } - case Wired: { - if (!isConnected(networkInfo)) return false; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) - return networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET; - return false; - } - case Mobile: { - if (!isConnected(networkInfo)) return false; - return networkInfo.getType() == ConnectivityManager.TYPE_MOBILE; - } - case Mobile2G: { - if (!isConnected(Mobile, networkInfo)) return false; - return isMobileSubType(Mobile2G, networkInfo); - } - case Mobile3G: { - if (!isConnected(Mobile, networkInfo)) return false; - return isMobileSubType(Mobile3G, networkInfo); - } - case Mobile4G: { - if (!isConnected(Mobile, networkInfo)) return false; - return isMobileSubType(Mobile4G, networkInfo); - } - } - return false; - } - - /** - * Whether network connection. - */ - private static boolean isConnected(NetworkInfo networkInfo) { - return networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected(); - } - - private static boolean isMobileSubType(NetType netType, NetworkInfo networkInfo) { - switch (networkInfo.getType()) { - case TelephonyManager.NETWORK_TYPE_GSM: - case TelephonyManager.NETWORK_TYPE_GPRS: - case TelephonyManager.NETWORK_TYPE_CDMA: - case TelephonyManager.NETWORK_TYPE_EDGE: - case TelephonyManager.NETWORK_TYPE_1xRTT: - case TelephonyManager.NETWORK_TYPE_IDEN: { - return netType == Mobile2G; - } - case TelephonyManager.NETWORK_TYPE_TD_SCDMA: - case TelephonyManager.NETWORK_TYPE_EVDO_A: - case TelephonyManager.NETWORK_TYPE_UMTS: - case TelephonyManager.NETWORK_TYPE_EVDO_0: - case TelephonyManager.NETWORK_TYPE_HSDPA: - case TelephonyManager.NETWORK_TYPE_HSUPA: - case TelephonyManager.NETWORK_TYPE_HSPA: - case TelephonyManager.NETWORK_TYPE_EVDO_B: - case TelephonyManager.NETWORK_TYPE_EHRPD: - case TelephonyManager.NETWORK_TYPE_HSPAP: { - return netType == Mobile3G; - } - case TelephonyManager.NETWORK_TYPE_IWLAN: - case TelephonyManager.NETWORK_TYPE_LTE: { - return netType == Mobile4G; - } - default: { - String subtypeName = networkInfo.getSubtypeName(); - if (subtypeName.equalsIgnoreCase("TD-SCDMA") - || subtypeName.equalsIgnoreCase("WCDMA") - || subtypeName.equalsIgnoreCase("CDMA2000")) { - return netType == Mobile3G; - } - break; - } - } - return false; - } - - /** - * Check the network is enable. - */ - public boolean isAvailable() { - return isWifiConnected() || isWiredConnected() || isMobileConnected(); - } - - /** - * To determine whether a WiFi network is available. - */ - public final boolean isWifiConnected() { - return isAvailable(Wifi); - } - - /** - * To determine whether a wired network is available. - */ - public final boolean isWiredConnected() { - return isAvailable(Wired); - } - - /** - * Mobile Internet connection. - */ - public final boolean isMobileConnected() { - return isAvailable(Mobile); - } - - /** - * 2G Mobile Internet connection. - */ - public final boolean isMobile2GConnected() { - return isAvailable(Mobile2G); - } - - /** - * 3G Mobile Internet connection. - */ - public final boolean isMobile3GConnected() { - return isAvailable(Mobile3G); - } - - /** - * 4G Mobile Internet connection. - */ - public final boolean isMobile4GConnected() { - return isAvailable(Mobile4G); - } - - /** - * According to the different type of network to determine whether the network connection. - */ - public final boolean isAvailable(NetType netType) { - return isConnected(netType, mManager.getActiveNetworkInfo()); - } - - public enum NetType { - Wifi, - Wired, - Mobile, - Mobile2G, - Mobile3G, - Mobile4G - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/connect/RealTimeNetwork.java b/kalle/src/main/java/com/yanzhenjie/kalle/connect/RealTimeNetwork.java deleted file mode 100644 index ab9a272cc..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/connect/RealTimeNetwork.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.connect; - -import android.content.Context; - -/** - * Created by Zhenjie Yan on 2019-05-19. - */ -public class RealTimeNetwork implements Network { - - private final Context mContext; - private final NetworkChecker mChecker; - - public RealTimeNetwork(Context context) { - this.mContext = context.getApplicationContext(); - this.mChecker = new NetworkChecker(mContext); - } - - @Override - public boolean isAvailable() { - return mChecker.isAvailable(); - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/connect/StreamBody.java b/kalle/src/main/java/com/yanzhenjie/kalle/connect/StreamBody.java deleted file mode 100644 index 56074599f..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/connect/StreamBody.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.connect; - -import android.text.TextUtils; - -import com.yanzhenjie.kalle.Headers; -import com.yanzhenjie.kalle.ResponseBody; -import com.yanzhenjie.kalle.util.IOUtils; - -import java.io.IOException; -import java.io.InputStream; - -/** - * Created by Zhenjie Yan on 2018/2/22. - */ -public class StreamBody implements ResponseBody { - - private String mContentType; - private InputStream mStream; - - public StreamBody(String contentType, InputStream stream) { - this.mContentType = contentType; - this.mStream = stream; - } - - @Override - public String string() throws IOException { - String charset = Headers.parseSubValue(mContentType, "charset", null); - return TextUtils.isEmpty(charset) ? IOUtils.toString(mStream) : IOUtils.toString(mStream, charset); - } - - @Override - public byte[] byteArray() throws IOException { - return IOUtils.toByteArray(mStream); - } - - @Override - public InputStream stream() throws IOException { - return mStream; - } - - @Override - public void close() throws IOException { - mStream.close(); - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/AppChain.java b/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/AppChain.java deleted file mode 100644 index c508c944b..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/AppChain.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.connect.http; - -import com.yanzhenjie.kalle.Request; -import com.yanzhenjie.kalle.Response; -import com.yanzhenjie.kalle.connect.Interceptor; - -import java.io.IOException; -import java.util.List; - -/** - * Created by Zhenjie Yan on 2018/3/6. - */ -class AppChain implements Chain { - - private final List mInterceptors; - private final int mTargetIndex; - private final Request mRequest; - private Call mCall; - - AppChain(List interceptors, int targetIndex, Request request, Call call) { - this.mInterceptors = interceptors; - this.mTargetIndex = targetIndex; - this.mRequest = request; - this.mCall = call; - } - - @Override - public Request request() { - return mRequest; - } - - @Override - public Response proceed(Request request) throws IOException { - Interceptor interceptor = mInterceptors.get(mTargetIndex); - Chain chain = new AppChain(mInterceptors, mTargetIndex + 1, request, mCall); - return interceptor.intercept(chain); - } - - @Override - public Call newCall() { - return mCall; - } - - @Override - public Call call() { - return mCall; - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/Call.java b/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/Call.java deleted file mode 100644 index b7eb72890..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/Call.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.connect.http; - -import com.yanzhenjie.kalle.Kalle; -import com.yanzhenjie.kalle.Request; -import com.yanzhenjie.kalle.Response; -import com.yanzhenjie.kalle.connect.Interceptor; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CancellationException; -import java.util.concurrent.Executor; -import java.util.concurrent.Executors; - -/** - * Created by Zhenjie Yan on 2018/2/24. - */ -public class Call { - - private static final Executor EXECUTOR = Executors.newCachedThreadPool(); - - private final Request mRequest; - private ConnectInterceptor mConnectInterceptor; - private boolean isExecuted; - private boolean isCanceled; - - public Call(Request request) { - this.mRequest = request; - } - - /** - * Execute request. - */ - public Response execute() throws IOException { - if (isCanceled) - throw new CancellationException("The request has been cancelled [" + mRequest.location() + "]"); - isExecuted = true; - - List interceptors = new ArrayList<>(Kalle.getConfig().getInterceptor()); - mConnectInterceptor = new ConnectInterceptor(); - interceptors.add(mConnectInterceptor); - - Chain chain = new AppChain(interceptors, 0, mRequest, this); - try { - return chain.proceed(mRequest); - } catch (Exception e) { - if (isCanceled) { - throw new CancellationException("The request has been cancelled [" + mRequest.location() + "]"); - } else { - throw e; - } - } - } - - /** - * The call is executed. - * - * @return true, otherwise is false. - */ - public boolean isExecuted() { - return isExecuted; - } - - /** - * The call is canceled. - * - * @return true, otherwise is false. - */ - public boolean isCanceled() { - return isCanceled; - } - - /** - * Cancel the call. - */ - public void cancel() { - if (!isCanceled) { - isCanceled = true; - if (mConnectInterceptor != null) { - mConnectInterceptor.cancel(); - } - } - } - - /** - * Cancel the call asynchronously. - */ - public void asyncCancel() { - EXECUTOR.execute(new Runnable() { - @Override - public void run() { - cancel(); - } - }); - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/Chain.java b/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/Chain.java deleted file mode 100644 index e1c006993..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/Chain.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.connect.http; - -import com.yanzhenjie.kalle.Request; -import com.yanzhenjie.kalle.Response; - -import java.io.IOException; - -/** - * Created by Zhenjie Yan on 2018/3/6. - */ -public interface Chain { - /** - * Get the request in the chain. - * - * @return target request. - */ - Request request(); - - /** - * Proceed to the next request processing. - * - * @param request target request. - * @return {@link Response}. - * @throws IOException io exception may occur during the implementation, you can handle or throw. - */ - Response proceed(Request request) throws IOException; - - /** - * Return {@link Call}, request will be executed on it. - * - * @deprecated use {@link #call()} instead. - */ - @Deprecated - Call newCall(); - - /** - * Return {@link Call}, request will be executed on it. - * - * @return {@link Call}. - */ - Call call(); -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/ConnectInterceptor.java b/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/ConnectInterceptor.java deleted file mode 100644 index 1a3fd94ec..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/ConnectInterceptor.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.connect.http; - -import com.yanzhenjie.kalle.Headers; -import com.yanzhenjie.kalle.Kalle; -import com.yanzhenjie.kalle.Request; -import com.yanzhenjie.kalle.RequestBody; -import com.yanzhenjie.kalle.RequestMethod; -import com.yanzhenjie.kalle.Response; -import com.yanzhenjie.kalle.ResponseBody; -import com.yanzhenjie.kalle.connect.ConnectFactory; -import com.yanzhenjie.kalle.connect.Connection; -import com.yanzhenjie.kalle.connect.Interceptor; -import com.yanzhenjie.kalle.connect.Network; -import com.yanzhenjie.kalle.connect.StreamBody; -import com.yanzhenjie.kalle.cookie.CookieManager; -import com.yanzhenjie.kalle.exception.ConnectException; -import com.yanzhenjie.kalle.exception.ConnectTimeoutError; -import com.yanzhenjie.kalle.exception.HostError; -import com.yanzhenjie.kalle.exception.NetException; -import com.yanzhenjie.kalle.exception.NetworkError; -import com.yanzhenjie.kalle.exception.ReadException; -import com.yanzhenjie.kalle.exception.ReadTimeoutError; -import com.yanzhenjie.kalle.exception.URLError; -import com.yanzhenjie.kalle.exception.WriteException; -import com.yanzhenjie.kalle.util.IOUtils; - -import java.io.IOException; -import java.io.OutputStream; -import java.net.MalformedURLException; -import java.net.SocketTimeoutException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.UnknownHostException; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CancellationException; - -import static com.yanzhenjie.kalle.Headers.KEY_CONTENT_LENGTH; -import static com.yanzhenjie.kalle.Headers.KEY_CONTENT_TYPE; -import static com.yanzhenjie.kalle.Headers.KEY_COOKIE; -import static com.yanzhenjie.kalle.Headers.KEY_HOST; -import static com.yanzhenjie.kalle.Headers.KEY_SET_COOKIE; - -/** - * Created by Zhenjie Yan on 2018/2/20. - */ -class ConnectInterceptor implements Interceptor { - - private final CookieManager mCookieManager; - private final ConnectFactory mFactory; - private final Network mNetwork; - - private Connection mConnection; - private boolean isCanceled; - - ConnectInterceptor() { - this.mCookieManager = new CookieManager(Kalle.getConfig().getCookieStore()); - this.mFactory = Kalle.getConfig().getConnectFactory(); - this.mNetwork = Kalle.getConfig().getNetwork(); - } - - @Override - public Response intercept(Chain chain) throws IOException { - if (isCanceled) throw new CancellationException("The request has been cancelled."); - - Request request = chain.request(); - RequestMethod method = request.method(); - - if (method.allowBody()) { - Headers headers = request.headers(); - RequestBody body = request.body(); - headers.set(KEY_CONTENT_LENGTH, Long.toString(body.contentLength())); - headers.set(KEY_CONTENT_TYPE, body.contentType()); - mConnection = connect(request); - writeBody(request); - } else { - mConnection = connect(request); - } - return readResponse(request); - } - - /** - * Cancel the request. - */ - public void cancel() { - isCanceled = true; - if (mConnection != null) { - mConnection.disconnect(); - } - } - - /** - * Connect to the server to change the connection anomalies occurred. - * - * @param request target request. - * @return connection between client and server. - * @throws ConnectException anomalies that occurred during the connection. - */ - private Connection connect(Request request) throws NetException { - if (!mNetwork.isAvailable()) - throw new NetworkError(request, "Network Unavailable"); - - try { - Headers headers = request.headers(); - URI uri = new URI(request.url().toString()); - List cookieHeader = mCookieManager.get(uri); - if (cookieHeader != null && !cookieHeader.isEmpty()) - headers.add(KEY_COOKIE, cookieHeader); - headers.set(KEY_HOST, uri.getHost()); - return mFactory.connect(request); - } catch (URISyntaxException e) { - throw new URLError(request, "The url syntax error", e); - } catch (MalformedURLException e) { - throw new URLError(request, "The url is malformed", e); - } catch (UnknownHostException e) { - throw new HostError(request, "Hostname can not be resolved", e); - } catch (SocketTimeoutException e) { - throw new ConnectTimeoutError(request, "Connect time out", e); - } catch (Exception e) { - throw new ConnectException(request, "An unknown exception", e); - } - } - - private void writeBody(Request request) throws WriteException { - try { - OutputStream stream = mConnection.getOutputStream(); - request.body().writeTo(IOUtils.toBufferedOutputStream(stream)); - IOUtils.closeQuietly(stream); - } catch (Exception e) { - throw new WriteException(request, e); - } - } - - private Response readResponse(Request request) throws NetException { - try { - int code = mConnection.getCode(); - Headers headers = parseResponseHeaders(mConnection.getHeaders()); - - List cookieList = headers.get(KEY_SET_COOKIE); - if (cookieList != null && !cookieList.isEmpty()) - mCookieManager.add(URI.create(request.url().toString()), cookieList); - - String contentType = headers.getContentType(); - ResponseBody body = new StreamBody(contentType, mConnection.getInputStream()); - return Response.newBuilder().code(code).headers(headers).body(body).build(); - } catch (SocketTimeoutException e) { - throw new ReadTimeoutError(request, "Read data time out", e); - } catch (Exception e) { - throw new ReadException(request, e); - } - } - - private Headers parseResponseHeaders(Map> headersMap) { - Headers headers = new Headers(); - for (Map.Entry> entry : headersMap.entrySet()) { - headers.add(entry.getKey(), entry.getValue()); - } - return headers; - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/LoggerInterceptor.java b/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/LoggerInterceptor.java deleted file mode 100644 index 6e7ed1c70..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/LoggerInterceptor.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.connect.http; - -import android.text.TextUtils; -import android.util.Log; - -import com.yanzhenjie.kalle.Headers; -import com.yanzhenjie.kalle.Request; -import com.yanzhenjie.kalle.RequestBody; -import com.yanzhenjie.kalle.Response; -import com.yanzhenjie.kalle.StringBody; -import com.yanzhenjie.kalle.UrlBody; -import com.yanzhenjie.kalle.connect.Interceptor; - -import java.io.IOException; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -/** - * Created by Zhenjie Yan on 2018/3/26. - */ -public class LoggerInterceptor implements Interceptor { - - private final String mTag; - private final boolean isEnable; - - public LoggerInterceptor(String tag, boolean isEnable) { - this.mTag = tag; - this.isEnable = isEnable; - } - - @Override - public Response intercept(Chain chain) throws IOException { - Request request = chain.request(); - if (isEnable) { - Response response = chain.proceed(request); - - String url = request.url().toString(); - - StringBuilder log = new StringBuilder(String.format(" \nPrint Request: %1$s.", url)); - log.append(String.format("\nMethod: %1$s.", request.method().name())); - - Headers toHeaders = request.headers(); - for (Map.Entry> entry : toHeaders.entrySet()) { - String key = entry.getKey(); - List values = entry.getValue(); - log.append(String.format("\n%1$s: %2$s.", key, TextUtils.join(";", values))); - } - - if (request.method().allowBody()) { - RequestBody body = request.body(); - if (body instanceof StringBody || body instanceof UrlBody) { - log.append(String.format(" \nRequest Body: %1$s.", body.toString())); - } - } - - log.append(String.format(" \nPrint Response: %1$s.", url)); - log.append(String.format(Locale.getDefault(), "\nCode: %1$d", response.code())); - - Headers fromHeaders = response.headers(); - for (Map.Entry> entry : fromHeaders.entrySet()) { - String key = entry.getKey(); - List values = entry.getValue(); - log.append(String.format("\n%1$s: %2$s.", key, TextUtils.join(";", values))); - } - Log.i(mTag, log.toString()); - return response; - } - return chain.proceed(request); - } - -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/RedirectInterceptor.kt b/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/RedirectInterceptor.kt deleted file mode 100644 index fc7618cad..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/RedirectInterceptor.kt +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.connect.http - -import com.yanzhenjie.kalle.* -import com.yanzhenjie.kalle.connect.Interceptor -import com.yanzhenjie.kalle.util.IOUtils -import java.io.IOException - -class RedirectInterceptor : Interceptor { - - @Throws(IOException::class) - override fun intercept(chain: Chain): Response { - val request = chain.request() - val response = chain.proceed(request) - return chain.redirect(request, response) - } - - /** - * 重定向 - */ - private fun Chain.redirect(request: Request, response: Response): Response { - return if (response.isRedirect) { - val oldUrl = request.url() - val url = oldUrl.location(response.headers().location) - val headers = request.headers() - headers.remove(Headers.KEY_COOKIE) - val method = request.method() - val newRequest: Request - newRequest = if (method.allowBody()) { - BodyRequest.newBuilder(url, method) - .setHeaders(headers) - .setParams(request.copyParams()) - .body(request.body()) - .build() - } else { - UrlRequest.newBuilder(url, method) - .setHeaders(headers) - .build() - } - IOUtils.closeQuietly(response) - redirect(newRequest, proceed(newRequest)) - } else response - } - - -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/RetryInterceptor.java b/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/RetryInterceptor.java deleted file mode 100644 index 3bf785599..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/connect/http/RetryInterceptor.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.connect.http; - -import com.yanzhenjie.kalle.Response; -import com.yanzhenjie.kalle.connect.Interceptor; - -import java.io.IOException; - -/** - * Created by Zhenjie Yan on 2018/3/6. - */ -public class RetryInterceptor implements Interceptor { - - private int mCount; - - public RetryInterceptor(int count) { - this.mCount = count; - } - - @Override - public Response intercept(Chain chain) throws IOException { - try { - return chain.proceed(chain.request()); - } catch (IOException e) { - if (mCount > 0) { - mCount--; - return intercept(chain); - } - throw e; - } - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/connect/stream/NullStream.java b/kalle/src/main/java/com/yanzhenjie/kalle/connect/stream/NullStream.java deleted file mode 100644 index 773955752..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/connect/stream/NullStream.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.-1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.-1 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.connect.stream; - -import com.yanzhenjie.kalle.connect.Connection; -import com.yanzhenjie.kalle.util.IOUtils; - -import java.io.InputStream; - -/** - * Created by Zhenjie Yan on 2018/2/25. - */ -public class NullStream extends InputStream { - - private final Connection mConnection; - - public NullStream(Connection connection) { - this.mConnection = connection; - } - - @Override - public int read() { - return -1; - } - - @Override - public int read(byte[] b) { - return -1; - } - - @Override - public int read(byte[] b, int off, int len) { - return -1; - } - - @Override - public void close() { - IOUtils.closeQuietly(mConnection); - } - - @Override - public long skip(long n) { - return 0; - } - - @Override - public int available() { - return 0; - } - - @Override - public void reset() { - } - - @Override - public boolean markSupported() { - return false; - } - - @Override - public void mark(int limit) { - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/connect/stream/SourceStream.java b/kalle/src/main/java/com/yanzhenjie/kalle/connect/stream/SourceStream.java deleted file mode 100644 index 33c0f2a40..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/connect/stream/SourceStream.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.connect.stream; - -import com.yanzhenjie.kalle.connect.Connection; -import com.yanzhenjie.kalle.util.IOUtils; - -import java.io.IOException; -import java.io.InputStream; - -/** - * Created by Zhenjie Yan on 2018/2/25. - */ -public class SourceStream extends InputStream { - - private final Connection mConnection; - private final InputStream mStream; - - public SourceStream(Connection connection, InputStream stream) { - this.mConnection = connection; - this.mStream = stream; - } - - @Override - public int read() throws IOException { - return mStream.read(); - } - - @Override - public int read(byte[] b) throws IOException { - return mStream.read(b, 0, b.length); - } - - @Override - public int read(byte[] b, int off, int len) throws IOException { - return mStream.read(b, off, len); - } - - @Override - public long skip(long n) throws IOException { - return mStream.skip(n); - } - - @Override - public int available() throws IOException { - return mStream.available(); - } - - @Override - public void close() throws IOException { - IOUtils.closeQuietly(mStream); - IOUtils.closeQuietly(mConnection); - } - - @Override - public void reset() throws IOException { - mStream.reset(); - } - - @Override - public synchronized void mark(int limit) { - mStream.mark(limit); - } - - @Override - public boolean markSupported() { - return mStream.markSupported(); - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/cookie/Cookie.java b/kalle/src/main/java/com/yanzhenjie/kalle/cookie/Cookie.java deleted file mode 100644 index 8830ea696..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/cookie/Cookie.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.cookie; - -import android.text.TextUtils; - -import java.io.Serializable; -import java.net.HttpCookie; - -/** - *

Cookie entity.

- * Created in Dec 17, 2015 7:21:16 PM. - */ -public class Cookie implements Serializable { - - private long id = -1; - private String url; - private String name; - private String value; - private String comment; - private String commentURL; - private boolean discard; - private String domain; - private long expiry; - private String path; - private String portList; - private boolean secure; - private int version = 1; - - public Cookie() { - } - - public static Cookie toCookie(String url, HttpCookie httpCookie) { - Cookie cookie = new Cookie(); - cookie.setUrl(url); - cookie.setName(httpCookie.getName()); - cookie.setValue(httpCookie.getValue()); - cookie.setComment(httpCookie.getComment()); - cookie.setCommentURL(httpCookie.getCommentURL()); - cookie.setDiscard(httpCookie.getDiscard()); - cookie.setDomain(httpCookie.getDomain()); - long maxAge = httpCookie.getMaxAge(); - if (maxAge > 0) { - long expiry = (maxAge * 1000L) + System.currentTimeMillis(); - if (expiry < 0L) { - expiry = System.currentTimeMillis() + 100L * 365L * 24L * 60L * 60L * 1000L; - } - cookie.setExpiry(expiry); - } else if (maxAge < 0) { - cookie.setExpiry(-1); - } else { - cookie.setExpiry(0); - } - - String path = httpCookie.getPath(); - if (!TextUtils.isEmpty(path) && path.length() > 1 && path.endsWith("/")) { - path = path.substring(0, path.length() - 1); - } - cookie.setPath(path); - cookie.setPortList(httpCookie.getPortlist()); - cookie.setSecure(httpCookie.getSecure()); - cookie.setVersion(httpCookie.getVersion()); - return cookie; - } - - public static HttpCookie toHttpCookie(Cookie cookie) { - HttpCookie httpCookie = new HttpCookie(cookie.name, cookie.value); - httpCookie.setComment(cookie.comment); - httpCookie.setCommentURL(cookie.commentURL); - httpCookie.setDiscard(cookie.discard); - httpCookie.setDomain(cookie.domain); - if (cookie.expiry == 0) { - httpCookie.setMaxAge(0); - } else if (cookie.expiry < 0) { - httpCookie.setMaxAge(-1L); - } else { - long expiry = cookie.expiry - System.currentTimeMillis(); - expiry = expiry <= 0 ? 0 : expiry; - httpCookie.setMaxAge(expiry / 1000L); - } - httpCookie.setPath(cookie.path); - httpCookie.setPortlist(cookie.portList); - httpCookie.setSecure(cookie.secure); - httpCookie.setVersion(cookie.version); - return httpCookie; - } - - public static boolean isExpired(Cookie entity) { - return entity.expiry != -1L && entity.expiry < System.currentTimeMillis(); - } - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - public String getComment() { - return comment; - } - - public void setComment(String comment) { - this.comment = comment; - } - - public String getCommentURL() { - return commentURL; - } - - public void setCommentURL(String commentURL) { - this.commentURL = commentURL; - } - - public boolean isDiscard() { - return discard; - } - - public void setDiscard(boolean discard) { - this.discard = discard; - } - - public String getDomain() { - return domain; - } - - public void setDomain(String domain) { - this.domain = domain; - } - - public long getExpiry() { - return expiry; - } - - public void setExpiry(long expiry) { - this.expiry = expiry; - } - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - public String getPortList() { - return portList; - } - - public void setPortList(String portList) { - this.portList = portList; - } - - public boolean isSecure() { - return secure; - } - - public void setSecure(boolean secure) { - this.secure = secure; - } - - public int getVersion() { - return version; - } - - public void setVersion(int version) { - this.version = version; - } -} diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/cookie/CookieManager.java b/kalle/src/main/java/com/yanzhenjie/kalle/cookie/CookieManager.java deleted file mode 100644 index ae1c351b7..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/cookie/CookieManager.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.cookie; - -import android.text.TextUtils; - -import java.net.HttpCookie; -import java.net.URI; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -/** - * Created by Zhenjie Yan on 2018/2/22. - */ -public class CookieManager { - - private CookieStore cookieJar; - - public CookieManager(CookieStore store) { - this.cookieJar = store; - } - - private static int getPort(URI uri) { - int port = uri.getPort(); - return (port == -1) ? ("https".equals(uri.getScheme()) ? 443 : 80) : port; - } - - private static boolean containsPort(String portList, int port) { - if (portList.contains(",")) { - String[] portArray = portList.split(","); - String inPort = Integer.toString(port); - for (String outPort : portArray) { - if (outPort.equals(inPort)) { - return true; - } - } - return false; - } - return portList.equalsIgnoreCase(Integer.toString(port)); - } - - private static boolean pathMatches(URI uri, HttpCookie cookie) { - return normalizePath(uri.getPath()).startsWith(normalizePath(cookie.getPath())); - } - - private static String normalizePath(String path) { - if (path == null) { - path = ""; - } - if (!path.endsWith("/")) { - path = path + "/"; - } - return path; - } - - /** - * Get the cookie under the specified URI, where https and secure will be verified. - * - * @param uri uri. - * @return all cookies that match the rules. - */ - public List get(URI uri) { - boolean secureLink = "https".equalsIgnoreCase(uri.getScheme()); - List outCookieList = new ArrayList<>(); - List inCookieList = cookieJar.get(uri); - for (HttpCookie cookie : inCookieList) { - if (pathMatches(uri, cookie) && (secureLink || !cookie.getSecure())) { - String portList = cookie.getPortlist(); - int port = getPort(uri); - if (TextUtils.isEmpty(portList) || containsPort(portList, port)) { - outCookieList.add(cookie); - } - } - } - if (outCookieList.isEmpty()) return Collections.emptyList(); - - List cookieList = new ArrayList<>(); - cookieList.add(sortByPath(outCookieList)); - return cookieList; - } - - /** - * Cookie for the specified URI to save, where path and port will be verified. - * - * @param uri uri. - * @param cookieList all you want to save the Cookie, does not meet the rules will not be saved. - */ - public void add(URI uri, List cookieList) { - for (String cookieValue : cookieList) { - List cookies = HttpCookie.parse(cookieValue); - for (HttpCookie cookie : cookies) { - if (cookie.getPath() == null) { - String path = normalizePath(uri.getPath()); - cookie.setPath(path); - } else if (!pathMatches(uri, cookie)) { - continue; - } - - if (cookie.getDomain() == null) cookie.setDomain(uri.getHost()); - - String portList = cookie.getPortlist(); - int port = getPort(uri); - if (TextUtils.isEmpty(portList) || containsPort(portList, port)) { - cookieJar.add(uri, cookie); - } - } - } - } - - private String sortByPath(List cookies) { - Collections.sort(cookies, new CookiePathComparator()); - final StringBuilder result = new StringBuilder(); - int minVersion = 1; - for (HttpCookie cookie : cookies) { - if (cookie.getVersion() < minVersion) { - minVersion = cookie.getVersion(); - } - } - - if (minVersion == 1) { - result.append("$Version=\"1\"; "); - } - - for (int i = 0; i < cookies.size(); ++i) { - if (i != 0) { - result.append("; "); - } - - result.append(cookies.get(i).toString()); - } - - return result.toString(); - } - - - private static class CookiePathComparator implements Comparator { - @Override - public int compare(HttpCookie c1, HttpCookie c2) { - if (c1 == c2) return 0; - if (c1 == null) return -1; - if (c2 == null) return 1; - - if (!c1.getName().equals(c2.getName())) return 0; - - final String c1Path = normalizePath(c1.getPath()); - final String c2Path = normalizePath(c2.getPath()); - - if (c1Path.startsWith(c2Path)) return -1; - else if (c2Path.startsWith(c1Path)) return 1; - else return 0; - } - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/cookie/CookieStore.java b/kalle/src/main/java/com/yanzhenjie/kalle/cookie/CookieStore.java deleted file mode 100644 index 475b5721a..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/cookie/CookieStore.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.cookie; - -import java.net.HttpCookie; -import java.net.URI; -import java.util.Collections; -import java.util.List; - -/** - * Created by Zhenjie Yan on 2018/2/20. - */ -public interface CookieStore { - - CookieStore DEFAULT = new CookieStore() { - @Override - public List get(URI uri) { - return Collections.emptyList(); - } - - @Override - public void add(URI uri, HttpCookie httpCookie) { - } - - @Override - public void remove(HttpCookie httpCookie) { - } - - @Override - public void clear() { - } - }; - - /** - * According to url loading cookies. - * - * @param uri uri. - * @return all cookies that match the rules. - */ - List get(URI uri); - - /** - * Save cookie for the specified url. - * - * @param uri uri. - * @param cookie cookie. - */ - void add(URI uri, HttpCookie cookie); - - /** - * Remove the specified cookie. - * - * @param cookie cookie. - */ - void remove(HttpCookie cookie); - - /** - * Clear the cookie. - */ - void clear(); -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/cookie/DBCookieStore.java b/kalle/src/main/java/com/yanzhenjie/kalle/cookie/DBCookieStore.java deleted file mode 100644 index c5ba7c738..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/cookie/DBCookieStore.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.cookie; - -import android.content.Context; -import android.text.TextUtils; - -import com.yanzhenjie.kalle.cookie.db.CookieDao; -import com.yanzhenjie.kalle.cookie.db.Field; -import com.yanzhenjie.kalle.cookie.db.Where; - -import java.net.HttpCookie; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -/** - * Created in Dec 17, 2015 7:20:52 PM. - */ -public class DBCookieStore implements CookieStore, Field { - - private final static int MAX_COOKIE_SIZE = 888; - private Lock mLock; - private CookieDao mCookieDao; - private DBCookieStore(Builder builder) { - mLock = new ReentrantLock(); - mCookieDao = new CookieDao(builder.mContext); - - Where where = Where.newBuilder() - .add(EXPIRY, Where.Options.EQUAL, -1) - .or(EXPIRY, Where.Options.EQUAL, 0) - .build(); - mCookieDao.delete(where.toString()); - } - - public static Builder newBuilder(Context context) { - return new Builder(context); - } - - private static URI getEffectiveURI(final URI uri) { - URI effectiveURI; - try { - effectiveURI = new URI("http", uri.getHost(), uri.getPath(), null, null); - } catch (URISyntaxException e) { - effectiveURI = uri; - } - return effectiveURI; - } - - @Override - public List get(URI uri) { - mLock.lock(); - try { - uri = getEffectiveURI(uri); - - Where.Builder whereBuilder = Where.newBuilder(); - - String host = uri.getHost(); - if (!TextUtils.isEmpty(host)) { - Where.Builder subBuilder = Where.newBuilder() - .add(DOMAIN, Where.Options.EQUAL, host) - .or(DOMAIN, Where.Options.EQUAL, "." + host); - - int firstDot = host.indexOf("."); - int lastDot = host.lastIndexOf("."); - if (firstDot > 0) { - if (lastDot > firstDot) { - String domain = host.substring(firstDot, host.length()); - if (!TextUtils.isEmpty(domain)) { - subBuilder.or(DOMAIN, Where.Options.EQUAL, domain); - } - } - if (lastDot > firstDot + 1) { - String domain = host.substring(firstDot + 1, host.length()); - if (!TextUtils.isEmpty(domain)) { - subBuilder.or(DOMAIN, Where.Options.EQUAL, domain); - } - } - } - whereBuilder.set(subBuilder.build().toString()); - } - - String path = uri.getPath(); - if (!TextUtils.isEmpty(path)) { - Where.Builder subBuilder = Where.newBuilder() - .add(PATH, Where.Options.EQUAL, path) - .or(PATH, Where.Options.EQUAL, "/") - .orNull(PATH); - int lastSplit = path.lastIndexOf("/"); - while (lastSplit > 0) { - path = path.substring(0, lastSplit); - subBuilder.or(PATH, Where.Options.EQUAL, path); - lastSplit = path.lastIndexOf("/"); - } - subBuilder.bracket(); - whereBuilder.and(subBuilder.build()); - } - - whereBuilder.or(URL, Where.Options.EQUAL, uri.toString()); - - Where where = whereBuilder.build(); - List cookieList = mCookieDao.getList(where.toString(), null, null, null); - List returnedCookies = new ArrayList<>(); - for (Cookie cookie : cookieList) { - if (!Cookie.isExpired(cookie)) returnedCookies.add(Cookie.toHttpCookie(cookie)); - } - return returnedCookies; - } finally { - mLock.unlock(); - } - } - - @Override - public void add(URI uri, HttpCookie httpCookie) { - mLock.lock(); - try { - if (uri != null && httpCookie != null) { - uri = getEffectiveURI(uri); - mCookieDao.replace(Cookie.toCookie(uri.toString(), httpCookie)); - trimSize(); - } - } finally { - mLock.unlock(); - } - } - - @Override - public void remove(HttpCookie httpCookie) { - mLock.lock(); - try { - Where.Builder whereBuilder = Where.newBuilder().add(NAME, Where.Options.EQUAL, httpCookie.getName()); - - String domain = httpCookie.getDomain(); - if (!TextUtils.isEmpty(domain)) whereBuilder.and(DOMAIN, Where.Options.EQUAL, domain); - - String path = httpCookie.getPath(); - if (!TextUtils.isEmpty(path)) { - if (path.length() > 1 && path.endsWith("/")) { - path = path.substring(0, path.length() - 1); - } - whereBuilder.and(PATH, Where.Options.EQUAL, path); - } - mCookieDao.delete(whereBuilder.build().toString()); - } finally { - mLock.unlock(); - } - } - - @Override - public void clear() { - mLock.lock(); - try { - mCookieDao.deleteAll(); - } finally { - mLock.unlock(); - } - } - - private void trimSize() { - int count = mCookieDao.count(); - if (count > MAX_COOKIE_SIZE) { - List rmList = mCookieDao.getList(null, null, Integer.toString(count - MAX_COOKIE_SIZE), null); - if (rmList != null) mCookieDao.delete(rmList); - } - } - - public static class Builder { - - private Context mContext; - - private Builder(Context context) { - this.mContext = context; - } - - public DBCookieStore build() { - return new DBCookieStore(this); - } - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/cookie/db/CookieDao.java b/kalle/src/main/java/com/yanzhenjie/kalle/cookie/db/CookieDao.java deleted file mode 100644 index ce0fe0e17..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/cookie/db/CookieDao.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.cookie.db; - -import android.content.ContentValues; -import android.content.Context; -import android.database.Cursor; -import android.database.SQLException; -import android.database.sqlite.SQLiteDatabase; -import android.text.TextUtils; - -import com.yanzhenjie.kalle.cookie.Cookie; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created in Jan 10, 2016 8:18:28 PM. - */ -public class CookieDao implements Field { - - private SQLHelper mSQLHelper; - - public CookieDao(Context context) { - this.mSQLHelper = new SQLHelper(context); - } - - protected final SQLiteDatabase getDateBase() { - return mSQLHelper.getReadableDatabase(); - } - - protected final void closeDateBase(SQLiteDatabase database) { - if (database != null && database.isOpen()) - database.close(); - } - - protected final void closeCursor(Cursor cursor) { - if (cursor != null && !cursor.isClosed()) { - cursor.close(); - } - } - - /** - * Query the number of records. - */ - public int count() { - return count("SELECT COUNT(" + ID + ") FROM " + TABLE_NAME); - } - - /** - * Query the number of records. - */ - public int count(String sql) { - SQLiteDatabase database = getDateBase(); - Cursor cursor = database.rawQuery(sql, null); - try { - return cursor.moveToNext() ? cursor.getInt(0) : 0; - } finally { - closeCursor(cursor); - closeDateBase(database); - } - } - - /** - * Delete all cookie. - */ - public boolean deleteAll() { - return delete("1=1"); - } - - /** - * Delete the cookie in the specified list. - */ - public boolean delete(List cookies) { - List idList = new ArrayList<>(); - for (Cookie cookie : cookies) { - idList.add(cookie.getId()); - } - Where where = Where.newBuilder().in(ID, idList).build(); - return delete(where.toString()); - } - - /** - * Delete cookies based on the conditions. - */ - public boolean delete(String where) { - SQLiteDatabase database = getDateBase(); - String sql = "DELETE FROM " + TABLE_NAME + " WHERE " + where; - database.beginTransaction(); - try { - database.execSQL(sql); - database.setTransactionSuccessful(); - return true; - } catch (SQLException e) { - return false; - } finally { - database.endTransaction(); - closeDateBase(database); - } - } - - /** - * Query all cookie. - */ - public List getAll() { - return getList(null, null, null, null); - } - - /** - * Query the cookie list based on the conditions. - */ - public List getList(String where, String orderBy, String limit, String offset) { - StringBuilder sqlBuild = new StringBuilder("SELECT ").append("*").append(" FROM ").append(TABLE_NAME); - if (!TextUtils.isEmpty(where)) { - sqlBuild.append(" WHERE "); - sqlBuild.append(where); - } - if (!TextUtils.isEmpty(orderBy)) { - sqlBuild.append(" ORDER BY "); - sqlBuild.append(orderBy); - } - if (!TextUtils.isEmpty(limit)) { - sqlBuild.append(" LIMIT "); - sqlBuild.append(limit); - - if (!TextUtils.isEmpty(offset)) { - sqlBuild.append(" OFFSET "); - sqlBuild.append(offset); - } - } - return getList(sqlBuild.toString()); - } - - /** - * Save or set cookies. - */ - public long replace(Cookie cookie) { - SQLiteDatabase database = getDateBase(); - database.beginTransaction(); - - ContentValues values = new ContentValues(); - values.put(URL, cookie.getUrl()); - values.put(NAME, cookie.getName()); - values.put(VALUE, cookie.getValue()); - values.put(COMMENT, cookie.getComment()); - values.put(COMMENT_URL, cookie.getCommentURL()); - values.put(DISCARD, String.valueOf(cookie.isDiscard())); - values.put(DOMAIN, cookie.getDomain()); - values.put(EXPIRY, cookie.getExpiry()); - values.put(PATH, cookie.getPath()); - values.put(PORT_LIST, cookie.getPortList()); - values.put(SECURE, String.valueOf(cookie.isSecure())); - values.put(VERSION, cookie.getVersion()); - try { - long result = database.replace(TABLE_NAME, null, values); - database.setTransactionSuccessful(); - return result; - } catch (Exception e) { - return -1; - } finally { - database.endTransaction(); - closeDateBase(database); - } - } - - /** - * According to the unique index adds or updates a row data. - */ - public List getList(String querySql) { - SQLiteDatabase database = getDateBase(); - List cookieList = new ArrayList<>(); - Cursor cursor = database.rawQuery(querySql, null); - while (cursor.moveToNext()) { - Cookie cookie = new Cookie(); - cookie.setId(cursor.getInt(cursor.getColumnIndex(ID))); - cookie.setUrl(cursor.getString(cursor.getColumnIndex(URL))); - cookie.setName(cursor.getString(cursor.getColumnIndex(NAME))); - cookie.setValue(cursor.getString(cursor.getColumnIndex(VALUE))); - cookie.setComment(cursor.getString(cursor.getColumnIndex(COMMENT))); - cookie.setCommentURL(cursor.getString(cursor.getColumnIndex(COMMENT_URL))); - cookie.setDiscard("true".equals(cursor.getString(cursor.getColumnIndex(DISCARD)))); - cookie.setDomain(cursor.getString(cursor.getColumnIndex(DOMAIN))); - cookie.setExpiry(cursor.getLong(cursor.getColumnIndex(EXPIRY))); - cookie.setPath(cursor.getString(cursor.getColumnIndex(PATH))); - cookie.setPortList(cursor.getString(cursor.getColumnIndex(PORT_LIST))); - cookie.setSecure("true".equals(cursor.getString(cursor.getColumnIndex(SECURE)))); - cookie.setVersion(cursor.getInt(cursor.getColumnIndex(VERSION))); - cookieList.add(cookie); - } - closeCursor(cursor); - closeDateBase(database); - return cookieList; - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/cookie/db/Field.java b/kalle/src/main/java/com/yanzhenjie/kalle/cookie/db/Field.java deleted file mode 100644 index 999d728a7..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/cookie/db/Field.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.cookie.db; - -/** - * Created by Zhenjie Yan on 2018/2/20. - */ -public interface Field { - String TABLE_NAME = "COOKIES_TABLE"; - - String ID = "_ID"; - String URL = "URL"; - String NAME = "NAME"; - String VALUE = "VALUE"; - String COMMENT = "COMMENT"; - String COMMENT_URL = "COMMENT_URL"; - String DISCARD = "DISCARD"; - String DOMAIN = "DOMAIN"; - String EXPIRY = "EXPIRY"; - String PATH = "PATH"; - String PORT_LIST = "PORT_LIST"; - String SECURE = "SECURE"; - String VERSION = "VERSION"; -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/cookie/db/SQLHelper.java b/kalle/src/main/java/com/yanzhenjie/kalle/cookie/db/SQLHelper.java deleted file mode 100644 index 2f48a54f4..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/cookie/db/SQLHelper.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.cookie.db; - -import android.content.Context; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteOpenHelper; - -/** - *

Cookie database operation class.

- * Created in Dec 18, 2015 6:30:59 PM. - */ -final class SQLHelper extends SQLiteOpenHelper implements Field { - - private static final String DB_COOKIE_NAME = "_kalle_cookies_db.db"; - private static final int DB_COOKIE_VERSION = 3; - - private static final String SQL_CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + "(" + ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - " " + URL + " TEXT, " + NAME + " TEXT, " + VALUE + " TEXT, " + COMMENT + " TEXT, " + COMMENT_URL + " TEXT, " + DISCARD + " TEXT," + - " " + DOMAIN + " TEXT, " + EXPIRY + " INTEGER, " + PATH + " TEXT, " + PORT_LIST + " TEXT, " + SECURE + " TEXT, " + VERSION + " INTEGER)"; - private static final String SQL_CREATE_UNIQUE_INDEX = "CREATE UNIQUE INDEX COOKIE_UNIQUE_INDEX ON COOKIES_TABLE(\"" + NAME + "\", \"" + DOMAIN + "\", \"" + PATH + "\")"; - private static final String SQL_DELETE_TABLE = "DROP TABLE IF EXISTS " + TABLE_NAME; - - SQLHelper(Context context) { - super(context.getApplicationContext(), DB_COOKIE_NAME, null, DB_COOKIE_VERSION); - } - - @Override - public void onCreate(SQLiteDatabase db) { - db.beginTransaction(); - try { - db.execSQL(SQL_CREATE_TABLE); - db.execSQL(SQL_CREATE_UNIQUE_INDEX); - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - } - - @Override - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - if (newVersion != oldVersion) { - db.beginTransaction(); - try { - db.execSQL(SQL_DELETE_TABLE); - db.execSQL(SQL_CREATE_TABLE); - db.execSQL(SQL_CREATE_UNIQUE_INDEX); - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - } - } -} diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/cookie/db/Where.java b/kalle/src/main/java/com/yanzhenjie/kalle/cookie/db/Where.java deleted file mode 100644 index 2589b6a23..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/cookie/db/Where.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.cookie.db; - -import java.util.Iterator; -import java.util.List; - -/** - * Created in Dec 19, 2015 4:16:24 PM. - */ -public class Where { - - private StringBuilder mBuilder; - - private Where(Builder builder) { - this.mBuilder = builder.mBuilder; - } - - public static Builder newBuilder() { - return new Builder(); - } - - @Override - public String toString() { - return mBuilder.toString(); - } - - public enum Options { - - EQUAL(" = "), NO_EQUAL(" != "), BIGGER(" > "), SMALLER(" < "); - - private String value; - - Options(String value) { - this.value = value; - } - } - - public static class Builder { - private StringBuilder mBuilder; - - private Builder() { - mBuilder = new StringBuilder(); - } - - public Builder append(Object row) { - mBuilder.append(row); - return this; - } - - public Builder set(String row) { - mBuilder.delete(0, mBuilder.length()).append(row); - return this; - } - - public Builder isNull(CharSequence columnName) { - mBuilder.append("\"").append(columnName).append("\"").append(" IS ").append("NULL"); - return this; - } - - private Builder add(CharSequence columnName, Options op) { - mBuilder.append("\"").append(columnName).append("\"").append(op.value); - return this; - } - - public Builder add(CharSequence columnName, Options op, Object value) { - add(columnName, op).append("'").append(value).append("'"); - return this; - } - - public Builder in(CharSequence columnName, List values) { - mBuilder.append(columnName).append(" IN ").append("("); - StringBuilder sb = new StringBuilder(); - Iterator it = values.iterator(); - if (it.hasNext()) { - sb.append("'").append(it.next()).append("'"); - while (it.hasNext()) { - sb.append(", '").append(it.next()).append("'"); - } - } - mBuilder.append(sb).append(")"); - return this; - } - - public Builder and() { - if (mBuilder.length() > 0) mBuilder.append(" AND "); - return this; - } - - public Builder and(CharSequence columnName, Options op, Object value) { - return and().add(columnName, op, value); - } - - public Builder andNull(CharSequence columnName) { - return and().isNull(columnName); - } - - public Builder and(Where where) { - return and().append(where); - } - - public Builder or() { - if (mBuilder.length() > 0) - mBuilder.append(" OR "); - return this; - } - - public Builder or(CharSequence columnName, Options op, Object value) { - return or().add(columnName, op, value); - } - - public Builder orNull(CharSequence columnName) { - return or().isNull(columnName); - } - - public Builder or(Where where) { - return or().append(where); - } - - public Builder bracket() { - return insert(0, "(").append(')'); - } - - public Builder insert(int index, CharSequence s) { - mBuilder.insert(index, s); - return this; - } - - public Where build() { - return new Where(this); - } - } -} diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/download/BasicWorker.java b/kalle/src/main/java/com/yanzhenjie/kalle/download/BasicWorker.java deleted file mode 100644 index 170d88940..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/download/BasicWorker.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.download; - -import android.text.TextUtils; - -import com.yanzhenjie.kalle.Canceller; -import com.yanzhenjie.kalle.Headers; -import com.yanzhenjie.kalle.Kalle; -import com.yanzhenjie.kalle.Response; -import com.yanzhenjie.kalle.Url; -import com.yanzhenjie.kalle.exception.DownloadError; -import com.yanzhenjie.kalle.util.IOUtils; -import com.yanzhenjie.kalle.util.UrlUtils; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.RandomAccessFile; -import java.util.concurrent.Callable; -import java.util.concurrent.Executor; - -import static com.yanzhenjie.kalle.Headers.KEY_RANGE; - -/** - * Created by Zhenjie Yan on 2018/3/18. - */ -public abstract class BasicWorker implements Callable, Canceller { - - private final T mDownload; - - private String mDirectory; - private String mFileName; - private Download.ProgressBar mProgressBar; - private Download.Policy mPolicy; - - BasicWorker(T download) { - this.mDownload = download; - this.mDirectory = mDownload.directory(); - this.mFileName = mDownload.fileName(); - this.mProgressBar = new AsyncProgressBar(mDownload.progressBar()); - this.mPolicy = mDownload.policy(); - } - - @Override - public String call() throws Exception { - if (TextUtils.isEmpty(mDirectory)) throw new IOException("Please specify the directory."); - File directory = new File(mDirectory); - IOUtils.createFolder(directory); - - Response response = null; - try { - int code; - Headers comeHeaders; - File tempFile; - - if (TextUtils.isEmpty(mFileName)) { - response = requestNetwork(mDownload); - code = response.code(); - comeHeaders = response.headers(); - mFileName = getRealFileName(comeHeaders); - tempFile = new File(mDirectory, mFileName + ".kalle"); - } else { - tempFile = new File(mDirectory, mFileName + ".kalle"); - if (mPolicy.isRange() && tempFile.exists()) { - Headers toHeaders = mDownload.headers(); - toHeaders.set(KEY_RANGE, "bytes=" + tempFile.length() + "-"); - response = requestNetwork(mDownload); - code = response.code(); - comeHeaders = response.headers(); - } else { - response = requestNetwork(mDownload); - code = response.code(); - comeHeaders = response.headers(); - - IOUtils.delFileOrFolder(tempFile); - } - } - - if (!mPolicy.allowDownload(code, comeHeaders)) { - throw new DownloadError(code, comeHeaders, mDownload.request(), "The download policy prohibits the program from continuing to download"); - } - - File file = new File(mDirectory, mFileName); - if (file.exists()) { - String filePath = file.getAbsolutePath(); - if (mPolicy.oldAvailable(filePath, code, comeHeaders)) { - mProgressBar.onProgress(100, file.length(), 0); - return filePath; - } else { - IOUtils.delFileOrFolder(file); - } - } - - long contentLength; - - if (code == 206) { - String range = comeHeaders.getContentRange(); - contentLength = Long.parseLong(range.substring(range.indexOf('/') + 1)); - } else { - IOUtils.createNewFile(tempFile); - contentLength = comeHeaders.getContentLength(); - } - - long oldCount = tempFile.length(); - int oldProgress = 0; - long oldSpeed = 0; - - RandomAccessFile randomFile = new RandomAccessFile(tempFile, "rws"); - randomFile.seek(oldCount); - - int len; - byte[] buffer = new byte[8096]; - - long speedTime = System.currentTimeMillis(); - long speedCount = 0; - - InputStream stream = response.body().stream(); - - while ((len = stream.read(buffer)) != -1) { - randomFile.write(buffer, 0, len); - - oldCount += len; - speedCount += len; - - long totalTime = System.currentTimeMillis() - speedTime; - if (totalTime < 400) continue; - - long speed = speedCount * 1000 / totalTime; - - if (contentLength != 0) { - int progress = (int) (oldCount * 100 / contentLength); - if (progress != oldProgress || speed != oldSpeed) { - oldProgress = progress; - oldSpeed = speed; - speedCount = 0; - speedTime = System.currentTimeMillis(); - - mProgressBar.onProgress(oldProgress, oldCount, oldSpeed); - } - } else if (oldSpeed != speed) { - speedCount = 0; - oldSpeed = speed; - speedTime = System.currentTimeMillis(); - - mProgressBar.onProgress(0, oldCount, oldSpeed); - } else { - mProgressBar.onProgress(0, oldCount, oldSpeed); - } - } - mProgressBar.onProgress(100, oldCount, oldSpeed); - - //noinspection ResultOfMethodCallIgnored - tempFile.renameTo(file); - return file.getAbsolutePath(); - } finally { - IOUtils.closeQuietly(response); - } - } - - /** - * Perform a network request. - * - * @param download target request. - * @return {@link Response}. - * @throws IOException when connecting to the network, write data, read the data {@link IOException} occurred. - */ - protected abstract Response requestNetwork(T download) throws IOException; - - /** - * Cancel request. - */ - public abstract void cancel(); - - private String getRealFileName(Headers headers) throws IOException { - String fileName = null; - String contentDisposition = headers.getContentDisposition(); - if (!TextUtils.isEmpty(contentDisposition)) { - fileName = Headers.parseSubValue(contentDisposition, "filename", null); - if (!TextUtils.isEmpty(fileName)) { - fileName = UrlUtils.urlDecode(fileName, "utf-8"); - if (fileName.startsWith("\"") && fileName.endsWith("\"")) { - fileName = fileName.substring(1, fileName.length() - 1); - } - } - } - - // From url. - if (TextUtils.isEmpty(fileName)) { - Url url = mDownload.url(); - String path = url.getPath(); - if (TextUtils.isEmpty(path)) { - fileName = Integer.toString(url.toString().hashCode()); - } else { - String[] slash = path.split("/"); - fileName = slash[slash.length - 1]; - } - } - return fileName; - } - - private static class AsyncProgressBar implements Download.ProgressBar { - - private final Download.ProgressBar mProgressBar; - private final Executor mExecutor; - - AsyncProgressBar(Download.ProgressBar bar) { - this.mProgressBar = bar; - this.mExecutor = Kalle.getConfig().getMainExecutor(); - } - - @Override - public void onProgress(final int progress, final long byteCount, final long speed) { - mExecutor.execute(new Runnable() { - @Override - public void run() { - mProgressBar.onProgress(progress, byteCount, speed); - } - }); - } - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/download/BodyDownload.java b/kalle/src/main/java/com/yanzhenjie/kalle/download/BodyDownload.java deleted file mode 100644 index 26a7bd890..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/download/BodyDownload.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.download; - -import com.yanzhenjie.kalle.BodyRequest; -import com.yanzhenjie.kalle.Request; -import com.yanzhenjie.kalle.RequestMethod; -import com.yanzhenjie.kalle.Url; - -/** - * Created by Zhenjie Yan on 2018/3/18. - */ -public class BodyDownload extends BodyRequest implements Download { - - private final String mDirectory; - private final String mFileName; - private final ProgressBar mProgressBar; - private final Policy mPolicy; - private BodyDownload(Api api) { - super(api); - this.mDirectory = api.mDirectory; - this.mFileName = api.mFileName; - this.mProgressBar = api.mProgressBar == null ? ProgressBar.DEFAULT : api.mProgressBar; - this.mPolicy = api.mPolicy == null ? Policy.DEFAULT : api.mPolicy; - } - - public static BodyDownload.Api newApi(Url url, RequestMethod method) { - return new BodyDownload.Api(url, method); - } - - @Override - public Request request() { - return this; - } - - @Override - public String directory() { - return mDirectory; - } - - @Override - public String fileName() { - return mFileName; - } - - @Override - public ProgressBar progressBar() { - return mProgressBar; - } - - @Override - public Policy policy() { - return mPolicy; - } - - public static class Api extends BodyRequest.Api { - - private String mDirectory; - private String mFileName; - - private ProgressBar mProgressBar; - private Policy mPolicy; - - private Api(Url url, RequestMethod method) { - super(url, method); - } - - public Api directory(String directory) { - this.mDirectory = directory; - return this; - } - - public Api fileName(String fileName) { - this.mFileName = fileName; - return this; - } - - public Api onProgress(ProgressBar bar) { - this.mProgressBar = bar; - return this; - } - - public Api policy(Policy policy) { - this.mPolicy = policy; - return this; - } - - public String perform() throws Exception { - return DownloadManager.getInstance().perform(new BodyDownload(this)); - } - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/download/BodyWorker.java b/kalle/src/main/java/com/yanzhenjie/kalle/download/BodyWorker.java deleted file mode 100644 index 42f7b7ba9..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/download/BodyWorker.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.download; - -import com.yanzhenjie.kalle.Response; -import com.yanzhenjie.kalle.connect.http.Call; - -import java.io.IOException; - -/** - * Created by Zhenjie Yan on 2018/3/18. - */ -public class BodyWorker extends BasicWorker { - - private Call mCall; - - BodyWorker(BodyDownload download) { - super(download); - } - - @Override - protected Response requestNetwork(BodyDownload download) throws IOException { - mCall = new Call(download); - return mCall.execute(); - } - - @Override - public void cancel() { - if (mCall != null && !mCall.isCanceled()) { - mCall.cancel(); - } - } - - @Override - public boolean isCancelled() { - return mCall.isCanceled(); - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/download/Download.java b/kalle/src/main/java/com/yanzhenjie/kalle/download/Download.java deleted file mode 100644 index cc5c9ae1d..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/download/Download.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.download; - -import com.yanzhenjie.kalle.Headers; -import com.yanzhenjie.kalle.Request; -import com.yanzhenjie.kalle.Url; - -/** - * Created by Zhenjie Yan on 2018/3/18. - */ -public interface Download { - - Request request(); - - /** - * Get the file download address. - */ - Url url(); - - /** - * Get headers. - */ - Headers headers(); - - /** - * Get the directory where the file is to be saved. - */ - String directory(); - - /** - * Get the file name. - */ - String fileName(); - - /** - * Get onProgress bar. - */ - ProgressBar progressBar(); - - /** - * Get download policy. - */ - Policy policy(); - - interface Policy { - - Policy DEFAULT = new Policy() { - @Override - public boolean isRange() { - return true; - } - - @Override - public boolean allowDownload(int code, Headers headers) { - return true; - } - - @Override - public boolean oldAvailable(String path, int code, Headers headers) { - return false; - } - }; - - /** - * Does it support breakpoints? - */ - boolean isRange(); - - /** - * Can I download it? - * - * @param code http response code. - * @param headers http response headers. - * @return return true to continue the download, return false will call back the download failed. - */ - boolean allowDownload(int code, Headers headers); - - /** - * Discover old files. The file will be returned if it is available, - * the file will be deleted if it is not available. - * - * @param path old file path. - * @param code http response code. - * @param headers http response headers. - * @return return true if the old file is available, other wise is false. - */ - boolean oldAvailable(String path, int code, Headers headers); - } - - interface ProgressBar { - - ProgressBar DEFAULT = new ProgressBar() { - @Override - public void onProgress(int progress, long byteCount, long speed) { - } - }; - - /** - * Download onProgress changes. - */ - void onProgress(int progress, long byteCount, long speed); - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/download/DownloadManager.java b/kalle/src/main/java/com/yanzhenjie/kalle/download/DownloadManager.java deleted file mode 100644 index e593a5b1d..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/download/DownloadManager.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.download; - -import com.yanzhenjie.kalle.NetCancel; - -/** - * Created by Zhenjie Yan on 2018/3/18. - */ -public class DownloadManager { - - private static DownloadManager sInstance; - - private DownloadManager() { - } - - public static DownloadManager getInstance() { - if (sInstance == null) { - synchronized (DownloadManager.class) { - if (sInstance == null) { - sInstance = new DownloadManager(); - } - } - } - return sInstance; - } - - /** - * Execute a request. - * - * @param download download request. - * @return download the completed file path. - */ - public String perform(UrlDownload download) throws Exception { - UrlWorker worker = new UrlWorker(download); - NetCancel.INSTANCE.add(download.uid(), worker); - return worker.call(); - } - - /** - * Execute a request. - * - * @param download download request. - * @return download the completed file path. - */ - public String perform(BodyDownload download) throws Exception { - BodyWorker worker = new BodyWorker(download); - NetCancel.INSTANCE.add(download.uid(), worker); - return worker.call(); - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/download/UrlDownload.java b/kalle/src/main/java/com/yanzhenjie/kalle/download/UrlDownload.java deleted file mode 100644 index 47d67a7f8..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/download/UrlDownload.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.download; - -import com.yanzhenjie.kalle.Request; -import com.yanzhenjie.kalle.RequestMethod; -import com.yanzhenjie.kalle.Url; -import com.yanzhenjie.kalle.UrlRequest; - -/** - * Created by Zhenjie Yan on 2018/3/18. - */ -public class UrlDownload extends UrlRequest implements Download { - - private final String mDirectory; - private final String mFileName; - private final ProgressBar mProgressBar; - private final Policy mPolicy; - - private UrlDownload(Api api) { - super(api); - this.mDirectory = api.mDirectory; - this.mFileName = api.mFileName; - this.mProgressBar = api.mProgressBar == null ? ProgressBar.DEFAULT : api.mProgressBar; - this.mPolicy = api.mPolicy == null ? Policy.DEFAULT : api.mPolicy; - } - - public static UrlDownload.Api newApi(Url url, RequestMethod method) { - return new UrlDownload.Api(url, method); - } - - @Override - public Request request() { - return this; - } - - @Override - public String directory() { - return mDirectory; - } - - @Override - public String fileName() { - return mFileName; - } - - @Override - public ProgressBar progressBar() { - return mProgressBar; - } - - @Override - public Policy policy() { - return mPolicy; - } - - public static class Api extends UrlRequest.Api { - - private String mDirectory; - private String mFileName; - - private ProgressBar mProgressBar; - private Policy mPolicy; - - private Api(Url url, RequestMethod method) { - super(url, method); - } - - public Api directory(String directory) { - this.mDirectory = directory; - return this; - } - - public Api fileName(String fileName) { - this.mFileName = fileName; - return this; - } - - public Api onProgress(ProgressBar bar) { - this.mProgressBar = bar; - return this; - } - - public Api policy(Policy policy) { - this.mPolicy = policy; - return this; - } - - public String perform() throws Exception { - return DownloadManager.getInstance().perform(new UrlDownload(this)); - } - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/download/UrlWorker.java b/kalle/src/main/java/com/yanzhenjie/kalle/download/UrlWorker.java deleted file mode 100644 index 44deea8a7..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/download/UrlWorker.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.download; - -import com.yanzhenjie.kalle.Response; -import com.yanzhenjie.kalle.connect.http.Call; - -import java.io.IOException; - -/** - * Created by Zhenjie Yan on 2018/3/18. - */ -public class UrlWorker extends BasicWorker { - - private Call mCall; - - UrlWorker(UrlDownload download) { - super(download); - } - - @Override - protected Response requestNetwork(UrlDownload download) throws IOException { - mCall = new Call(download); - return mCall.execute(); - } - - @Override - public void cancel() { - if (mCall != null && !mCall.isCanceled()) { - mCall.cancel(); - } - } - - @Override - public boolean isCancelled() { - return mCall.isCanceled(); - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/exception/ConnectException.kt b/kalle/src/main/java/com/yanzhenjie/kalle/exception/ConnectException.kt deleted file mode 100644 index b7e21ed73..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/exception/ConnectException.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.exception - -import com.yanzhenjie.kalle.Request - -open class ConnectException( - request: Request, - message: String = "", - cause: Throwable? = null -) : NetException(request, message, cause) \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/exception/ConnectTimeoutError.kt b/kalle/src/main/java/com/yanzhenjie/kalle/exception/ConnectTimeoutError.kt deleted file mode 100644 index f67bffb73..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/exception/ConnectTimeoutError.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.exception - -import com.yanzhenjie.kalle.Request - -class ConnectTimeoutError( - request: Request, - message: String = "", - cause: Throwable? = null -) : NetException(request, message, cause) \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/exception/DownloadError.kt b/kalle/src/main/java/com/yanzhenjie/kalle/exception/DownloadError.kt deleted file mode 100644 index 0c5c74db8..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/exception/DownloadError.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.exception - -import com.yanzhenjie.kalle.Headers -import com.yanzhenjie.kalle.Request - -class DownloadError( - val code: Int, - val headers: Headers, - request: Request, - message: String = "" -) : NetException(request, message) \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/exception/HostError.kt b/kalle/src/main/java/com/yanzhenjie/kalle/exception/HostError.kt deleted file mode 100644 index 18249fd68..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/exception/HostError.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.exception - -import com.yanzhenjie.kalle.Request - -class HostError( - request: Request, - message: String = "", - cause: Throwable? = null -) : NetException(request, message, cause) \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/exception/NetworkError.kt b/kalle/src/main/java/com/yanzhenjie/kalle/exception/NetworkError.kt deleted file mode 100644 index 159c1c313..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/exception/NetworkError.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.exception - -import com.yanzhenjie.kalle.Request - -class NetworkError( - request: Request, - message: String = "" -) : NetException(request, message) \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/exception/ReadException.kt b/kalle/src/main/java/com/yanzhenjie/kalle/exception/ReadException.kt deleted file mode 100644 index f0ab844c4..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/exception/ReadException.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.exception - -import com.yanzhenjie.kalle.Request - -open class ReadException( - request: Request, - cause: Throwable? = null -) : NetException(request, cause = cause) \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/exception/ReadTimeoutError.kt b/kalle/src/main/java/com/yanzhenjie/kalle/exception/ReadTimeoutError.kt deleted file mode 100644 index 7f2a72fd4..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/exception/ReadTimeoutError.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.exception - -import com.yanzhenjie.kalle.Request - -class ReadTimeoutError( - request: Request, - message: String = "", - cause: Throwable? = null -) : NetException(request, message, cause) \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/exception/URLError.kt b/kalle/src/main/java/com/yanzhenjie/kalle/exception/URLError.kt deleted file mode 100644 index 61c2e1b9a..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/exception/URLError.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.exception - -import com.yanzhenjie.kalle.Request - -class URLError( - request: Request, - message: String = "", - cause: Throwable? = null -) : NetException(request, message, cause) \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/exception/WriteException.kt b/kalle/src/main/java/com/yanzhenjie/kalle/exception/WriteException.kt deleted file mode 100644 index 1f11e2ca6..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/exception/WriteException.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.exception - -import com.yanzhenjie.kalle.Request - -class WriteException constructor( - request: Request, - cause: Throwable? = null -) : NetException(request, cause = cause) \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/secure/AESSecret.java b/kalle/src/main/java/com/yanzhenjie/kalle/secure/AESSecret.java deleted file mode 100644 index 8b9bfc7a1..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/secure/AESSecret.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.secure; - -import java.security.GeneralSecurityException; -import java.security.Key; - -import javax.crypto.Cipher; -import javax.crypto.spec.SecretKeySpec; - -/** - * Created by Zhenjie Yan on 2018/2/11. - */ -public class AESSecret implements Secret { - - private Cipher encrypt; - private Cipher decrypt; - - public AESSecret(String key) throws GeneralSecurityException { - Key cryptKey = getKey(key.getBytes()); - encrypt = Cipher.getInstance("AES"); - encrypt.init(Cipher.ENCRYPT_MODE, cryptKey); - decrypt = Cipher.getInstance("AES"); - decrypt.init(Cipher.DECRYPT_MODE, cryptKey); - } - - @Override - public String encrypt(String data) throws GeneralSecurityException { - return Encryption.byteArrayToHex(encrypt(data.getBytes())); - } - - @Override - public byte[] encrypt(byte[] data) throws GeneralSecurityException { - return encrypt.doFinal(data); - } - - @Override - public String decrypt(String data) throws GeneralSecurityException { - return new String(decrypt(Encryption.hexToByteArray(data))); - } - - @Override - public byte[] decrypt(byte[] data) throws GeneralSecurityException { - return decrypt.doFinal(data); - } - - private Key getKey(byte[] keyData) { - byte[] arrB = new byte[8]; - for (int i = 0; i < keyData.length && i < arrB.length; i++) { - arrB[i] = keyData[i]; - } - return new SecretKeySpec(arrB, "AES"); - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/secure/Encryption.java b/kalle/src/main/java/com/yanzhenjie/kalle/secure/Encryption.java deleted file mode 100644 index 08e7b9b33..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/secure/Encryption.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.secure; - -import java.security.GeneralSecurityException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -/** - * Created in 2016/4/10 11:27. - */ -public class Encryption { - - /** - * Create a secret of encryption and decryption. - */ - public static Secret createSecret(String key) { - try { - return new AESSecret(key); - } catch (GeneralSecurityException e) { - return new SafeSecret(); - } - } - - /** - * Byte array turn to hex string. - */ - public static String byteArrayToHex(byte[] byteArray) { - int len = byteArray.length; - StringBuilder sb = new StringBuilder(len * 2); - for (int i = 0; i < len; i++) { - int intTmp = byteArray[i]; - while (intTmp < 0) { - intTmp = intTmp + 256; - } - if (intTmp < 16) { - sb.append("0"); - } - sb.append(Integer.toString(intTmp, 16)); - } - return sb.toString(); - } - - /** - * Hex string turn to byte array. - */ - public static byte[] hexToByteArray(String hexString) { - byte[] byteArrayIn = hexString.getBytes(); - int iLen = byteArrayIn.length; - byte[] byteArrayOut = new byte[iLen / 2]; - for (int i = 0; i < iLen; i = i + 2) { - String strTmp = new String(byteArrayIn, i, 2); - byteArrayOut[i / 2] = (byte) Integer.parseInt(strTmp, 16); - } - return byteArrayOut; - } - - /** - * Get the md5 value of string. - */ - public static String getMD5ForString(String content) { - try { - StringBuilder md5Builder = new StringBuilder(); - MessageDigest digest = MessageDigest.getInstance("MD5"); - byte[] tempBytes = digest.digest(content.getBytes()); - int digital; - for (byte tempByte : tempBytes) { - digital = tempByte; - if (digital < 0) { - digital += 256; - } - if (digital < 16) { - md5Builder.append("0"); - } - md5Builder.append(Integer.toHexString(digital)); - } - return md5Builder.toString(); - } catch (NoSuchAlgorithmException ignored) { - } - return content; - } - -} diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/secure/SafeSecret.java b/kalle/src/main/java/com/yanzhenjie/kalle/secure/SafeSecret.java deleted file mode 100644 index 95bc80540..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/secure/SafeSecret.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.secure; - -import java.security.GeneralSecurityException; - -/** - * Created by Zhenjie Yan on 2018/2/11. - */ -public class SafeSecret implements Secret { - @Override - public String encrypt(String data) throws GeneralSecurityException { - return data; - } - - @Override - public byte[] encrypt(byte[] data) throws GeneralSecurityException { - return data; - } - - @Override - public String decrypt(String data) throws GeneralSecurityException { - return data; - } - - @Override - public byte[] decrypt(byte[] data) throws GeneralSecurityException { - return data; - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/secure/Secret.java b/kalle/src/main/java/com/yanzhenjie/kalle/secure/Secret.java deleted file mode 100644 index 40d04a2ae..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/secure/Secret.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.secure; - -import java.security.GeneralSecurityException; - -/** - * Created by Zhenjie Yan on 2018/2/11. - */ -public interface Secret { - - String encrypt(String data) throws GeneralSecurityException; - - byte[] encrypt(byte[] data) throws GeneralSecurityException; - - String decrypt(String data) throws GeneralSecurityException; - - byte[] decrypt(byte[] data) throws GeneralSecurityException; -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/simple/BasicWorker.java b/kalle/src/main/java/com/yanzhenjie/kalle/simple/BasicWorker.java deleted file mode 100644 index d5aaa4305..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/simple/BasicWorker.java +++ /dev/null @@ -1,330 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.simple; - -import com.yanzhenjie.kalle.Canceller; -import com.yanzhenjie.kalle.Headers; -import com.yanzhenjie.kalle.Kalle; -import com.yanzhenjie.kalle.Request; -import com.yanzhenjie.kalle.Response; -import com.yanzhenjie.kalle.exception.NetException; -import com.yanzhenjie.kalle.exception.NoCacheError; -import com.yanzhenjie.kalle.exception.ParseError; -import com.yanzhenjie.kalle.recorder.LogRecorder; -import com.yanzhenjie.kalle.simple.cache.Cache; -import com.yanzhenjie.kalle.simple.cache.CacheMode; -import com.yanzhenjie.kalle.simple.cache.CacheStore; -import com.yanzhenjie.kalle.util.IOUtils; - -import java.io.IOException; -import java.lang.reflect.Type; -import java.util.concurrent.Callable; - -import static com.yanzhenjie.kalle.Headers.KEY_IF_MODIFIED_SINCE; -import static com.yanzhenjie.kalle.Headers.KEY_IF_NONE_MATCH; - -abstract class BasicWorker implements Callable, Canceller { - - private static final long MAX_EXPIRES = System.currentTimeMillis() + 100L * 365L * 24L * 60L * 60L * 1000L; - - private final T mRequest; - private final CacheStore mCacheStore; - private final Converter mConverter; - private final Type mSucceed; - - BasicWorker(T request, Type succeed) { - this.mRequest = request; - this.mSucceed = succeed; - this.mCacheStore = Kalle.getConfig().getCacheStore(); - this.mConverter = request.converter() == null ? Kalle.getConfig().getConverter() : request.converter(); - } - - @Override - public final S call() throws Exception { - Response response = tryReadCacheBefore(); - if (response != null) return buildSimpleResponse(response, true); - - tryAttachCache(); - try { - Request request = mRequest.request(); - LogRecorder.recordRequest(request.logId(), request.location(), request.method().toString(), request.headers().toMap(), request.getLog()); - - response = requestNetwork(mRequest); - - int code = response.code(); - if (code == 304) { - Response cacheResponse = tryReadCacheAfter(code); - if (cacheResponse != null) { - return buildSimpleResponse(cacheResponse, true); - } else { - return buildSimpleResponse(response, false); - } - } - Headers headers = response.headers(); - - byte[] body = {}; - if (code != 204) { - body = response.body().byteArray(); - } - IOUtils.closeQuietly(response); - tryDetachCache(code, headers, body); - response = buildResponse(code, headers, body); - return buildSimpleResponse(response, false); - } catch (IOException e) { - Response cacheResponse = tryReadCacheAfter(-1); - if (cacheResponse != null) { - return buildSimpleResponse(cacheResponse, true); - } - Request request = mRequest.request(); - - String errorMsg = null; - int code = 0; - if (response != null) { - errorMsg = response.getLog(); - code = response.code(); - } - LogRecorder.recordException(request.logId(), request.getTimeMillis(), code, e.getLocalizedMessage(), errorMsg); - throw e; - } finally { - IOUtils.closeQuietly(response); - } - } - - /** - * Perform a network request. - * - * @param request target request. - * @return {@link Response}. - * @throws IOException when connecting to the network, write data, read the data {@link IOException} occurred. - */ - protected abstract Response requestNetwork(T request) throws IOException; - - /** - * Cancel request. - */ - public abstract void cancel(); - - private Response tryReadCacheBefore() throws NoCacheError { - CacheMode cacheMode = mRequest.cacheMode(); - switch (cacheMode) { - case HTTP: { - Cache cache = mCacheStore.get(mRequest.cacheKey()); - if (cache == null) return null; - if (cache.getExpires() > System.currentTimeMillis()) { - return buildResponse(cache.getCode(), cache.getHeaders(), cache.getBody()); - } - break; - } - case HTTP_YES_THEN_WRITE_CACHE: - case NETWORK: - case NETWORK_YES_THEN_HTTP: - case NETWORK_YES_THEN_WRITE_CACHE: - case NETWORK_NO_THEN_READ_CACHE: { - // Nothing. - return null; - } - case READ_CACHE: { - Cache cache = mCacheStore.get(mRequest.cacheKey()); - if (cache != null) { - return buildResponse(cache.getCode(), cache.getHeaders(), cache.getBody()); - } - throw new NoCacheError(mRequest.request(), "No cache found"); - } - case READ_CACHE_NO_THEN_NETWORK: - case READ_CACHE_NO_THEN_HTTP: { - Cache cache = mCacheStore.get(mRequest.cacheKey()); - if (cache != null) { - return buildResponse(cache.getCode(), cache.getHeaders(), cache.getBody()); - } - break; - } - case READ_CACHE_NO_THEN_NETWORK_THEN_WRITE_CACHE: { - Cache cache = mCacheStore.get(mRequest.cacheKey()); - if (cache != null) { - return buildResponse(cache.getCode(), cache.getHeaders(), cache.getBody()); - } - break; - } - } - return null; - } - - private void tryAttachCache() { - CacheMode cacheMode = mRequest.cacheMode(); - switch (cacheMode) { - case HTTP: - case HTTP_YES_THEN_WRITE_CACHE: { - Cache cacheEntity = mCacheStore.get(mRequest.cacheKey()); - if (cacheEntity != null) attachCache(cacheEntity.getHeaders()); - break; - } - case NETWORK: - case NETWORK_YES_THEN_HTTP: - case NETWORK_YES_THEN_WRITE_CACHE: - case NETWORK_NO_THEN_READ_CACHE: - case READ_CACHE: - case READ_CACHE_NO_THEN_NETWORK: - case READ_CACHE_NO_THEN_HTTP: { - // Nothing. - break; - } - case READ_CACHE_NO_THEN_NETWORK_THEN_WRITE_CACHE: { - Cache cacheEntity = mCacheStore.get(mRequest.cacheKey()); - if (cacheEntity != null) attachCache(cacheEntity.getHeaders()); - break; - } - } - } - - private void tryDetachCache(int code, Headers headers, byte[] body) { - CacheMode cacheMode = mRequest.cacheMode(); - switch (cacheMode) { - case HTTP: { - long expires = Headers.analysisCacheExpires(headers); - if (expires > 0 || headers.getLastModified() > 0) { - detachCache(code, headers, body, expires); - } - break; - } - case HTTP_YES_THEN_WRITE_CACHE: { - detachCache(code, headers, body, MAX_EXPIRES); - break; - } - case NETWORK: { - break; - } - case NETWORK_YES_THEN_HTTP: { - long expires = Headers.analysisCacheExpires(headers); - if (expires > 0 || headers.getLastModified() > 0) { - detachCache(code, headers, body, expires); - } - break; - } - case NETWORK_YES_THEN_WRITE_CACHE: { - detachCache(code, headers, body, MAX_EXPIRES); - break; - } - case NETWORK_NO_THEN_READ_CACHE: - case READ_CACHE: - case READ_CACHE_NO_THEN_NETWORK: { - break; - } - case READ_CACHE_NO_THEN_HTTP: { - long expires = Headers.analysisCacheExpires(headers); - if (expires > 0 || headers.getLastModified() > 0) { - detachCache(code, headers, body, expires); - } - break; - } - case READ_CACHE_NO_THEN_NETWORK_THEN_WRITE_CACHE: { - //禁止服务器错误时存入缓存 - if (code >= 200 && code <= 299) detachCache(code, headers, body, MAX_EXPIRES); - break; - } - } - } - - private Response tryReadCacheAfter(int code) { - CacheMode cacheMode = mRequest.cacheMode(); - switch (cacheMode) { - case HTTP: - case HTTP_YES_THEN_WRITE_CACHE: { - if (code == 304) { - Cache cache = mCacheStore.get(mRequest.cacheKey()); - if (cache != null) { - return buildResponse(cache.getCode(), cache.getHeaders(), cache.getBody()); - } - } - break; - } - case NETWORK: - case NETWORK_YES_THEN_HTTP: - case NETWORK_YES_THEN_WRITE_CACHE: { - break; - } - case NETWORK_NO_THEN_READ_CACHE: { - Cache cache = mCacheStore.get(mRequest.cacheKey()); - if (cache != null) { - return buildResponse(cache.getCode(), cache.getHeaders(), cache.getBody()); - } - break; - } - case READ_CACHE: - case READ_CACHE_NO_THEN_NETWORK: { - break; - } - case READ_CACHE_NO_THEN_HTTP: { - if (code == 304) { - Cache cache = mCacheStore.get(mRequest.cacheKey()); - if (cache != null) { - return buildResponse(cache.getCode(), cache.getHeaders(), cache.getBody()); - } - } - break; - } - case READ_CACHE_NO_THEN_NETWORK_THEN_WRITE_CACHE: { - Cache cache = mCacheStore.get(mRequest.cacheKey()); - if (cache != null) { - return buildResponse(cache.getCode(), cache.getHeaders(), cache.getBody()); - } - break; - } - } - return null; - } - - private void attachCache(Headers cacheHeaders) { - Headers headers = mRequest.headers(); - String eTag = cacheHeaders.getETag(); - if (eTag != null) headers.set(KEY_IF_NONE_MATCH, eTag); - - long lastModified = cacheHeaders.getLastModified(); - if (lastModified > 0) - headers.set(KEY_IF_MODIFIED_SINCE, Headers.formatMillisToGMT(lastModified)); - } - - private void detachCache(int code, Headers headers, byte[] body, long expires) { - String cacheKey = mRequest.cacheKey(); - Cache entity = new Cache(); - entity.setKey(cacheKey); - entity.setCode(code); - entity.setHeaders(headers); - entity.setBody(body); - entity.setExpires(expires); - mCacheStore.replace(cacheKey, entity); - } - - private Response buildResponse(int code, Headers headers, byte[] body) { - return Response.newBuilder() - .code(code) - .headers(headers) - .body(new ByteArrayBody(headers.getContentType(), body)) - .build(); - } - - private S buildSimpleResponse(Response response, boolean cache) throws IOException { - Request request = mRequest.request(); - try { - S result = mConverter.convert(mSucceed, request, response, cache); - LogRecorder.recordResponse(request.logId(), request.getTimeMillis(), response.code(), response.headers().toMap(), response.getLog()); - return result; - } catch (NetException e) { - throw e; - } catch (Exception e) { - throw new ParseError(request, "An exception occurred while parsing the data", e); - } - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/simple/BodyWorker.java b/kalle/src/main/java/com/yanzhenjie/kalle/simple/BodyWorker.java deleted file mode 100644 index b1e60363a..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/simple/BodyWorker.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.simple; - -import com.yanzhenjie.kalle.Response; -import com.yanzhenjie.kalle.connect.http.Call; - -import java.io.IOException; -import java.lang.reflect.Type; - -/** - * Created by Zhenjie Yan on 2018/2/13. - */ -final class BodyWorker extends BasicWorker { - - private Call mCall; - - BodyWorker(SimpleBodyRequest request, Type succeed) { - super(request, succeed); - } - - @Override - protected Response requestNetwork(SimpleBodyRequest request) throws IOException { - mCall = new Call(request); - return mCall.execute(); - } - - @Override - public void cancel() { - if (mCall != null && !mCall.isCanceled()) { - mCall.cancel(); - } - } - - @Override - public boolean isCancelled() { - return mCall.isCanceled(); - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/simple/ByteArrayBody.java b/kalle/src/main/java/com/yanzhenjie/kalle/simple/ByteArrayBody.java deleted file mode 100644 index 91f6071a7..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/simple/ByteArrayBody.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.simple; - -import android.text.TextUtils; - -import com.yanzhenjie.kalle.Headers; -import com.yanzhenjie.kalle.ResponseBody; -import com.yanzhenjie.kalle.util.IOUtils; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; - -/** - * Created by Zhenjie Yan on 2018/2/22. - */ -public class ByteArrayBody implements ResponseBody { - - private String mContentType; - private byte[] mData; - - public ByteArrayBody(String contentType, byte[] data) { - this.mContentType = contentType; - this.mData = data; - } - - @Override - public String string() throws IOException { - String charset = Headers.parseSubValue(mContentType, "charset", null); - return TextUtils.isEmpty(charset) ? IOUtils.toString(mData) : IOUtils.toString(mData, charset); - } - - @Override - public byte[] byteArray() throws IOException { - return mData; - } - - @Override - public InputStream stream() throws IOException { - return new ByteArrayInputStream(mData); - } - - @Override - public void close() throws IOException { - mData = null; - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/simple/Converter.kt b/kalle/src/main/java/com/yanzhenjie/kalle/simple/Converter.kt deleted file mode 100644 index d0374bdb9..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/simple/Converter.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.simple - -import com.yanzhenjie.kalle.Request -import com.yanzhenjie.kalle.Response -import com.yanzhenjie.kalle.exception.ParseError -import java.lang.reflect.Type - -@Suppress("UNCHECKED_CAST") -interface Converter { - - @Throws(Exception::class) - fun convert(succeed: Type, request: Request, response: Response, cache: Boolean): S? - - companion object { - - @JvmField - val DEFAULT: Converter = object : Converter { - - override fun convert(succeed: Type, - request: Request, - response: Response, - cache: Boolean): S? { - if (succeed === String::class.java) { - val string = response.body().string() - response.log = string - return string as S - } - throw ParseError(request, "Only strings are supported by default") - } - } - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/simple/RequestManager.java b/kalle/src/main/java/com/yanzhenjie/kalle/simple/RequestManager.java deleted file mode 100644 index 93678691b..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/simple/RequestManager.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.simple; - -import com.yanzhenjie.kalle.NetCancel; - -import java.lang.reflect.Type; - -/** - * Created by Zhenjie Yan on 2018/2/13. - */ -public class RequestManager { - - private static RequestManager sInstance; - - private RequestManager() { - } - - public static RequestManager getInstance() { - if (sInstance == null) { - synchronized (RequestManager.class) { - if (sInstance == null) { - sInstance = new RequestManager(); - } - } - } - return sInstance; - } - - /** - * Execute a request. - * - * @param request request. - * @param succeed the data type when the business succeed. - * @param target object parameter. - * @return the response to this request. - */ - public S perform(SimpleUrlRequest request, Type succeed) throws Exception { - UrlWorker worker = new UrlWorker<>(request, succeed); - NetCancel.INSTANCE.add(request.uid(), worker); - return worker.call(); - } - - /** - * Execute a request. - * - * @param request request. - * @param succeed the data type when the business succeed. - * @param target object parameter. - * @return the response to this request. - */ - public S perform(SimpleBodyRequest request, Type succeed) throws Exception { - BodyWorker worker = new BodyWorker<>(request, succeed); - NetCancel.INSTANCE.add(request.uid(), worker); - return worker.call(); - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/simple/SimpleBodyRequest.java b/kalle/src/main/java/com/yanzhenjie/kalle/simple/SimpleBodyRequest.java deleted file mode 100644 index 5667bbd7d..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/simple/SimpleBodyRequest.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.simple; - -import android.text.TextUtils; - -import com.yanzhenjie.kalle.BodyRequest; -import com.yanzhenjie.kalle.Request; -import com.yanzhenjie.kalle.RequestMethod; -import com.yanzhenjie.kalle.Url; -import com.yanzhenjie.kalle.simple.cache.CacheMode; - -import java.lang.reflect.Type; - -import static com.yanzhenjie.kalle.simple.cache.CacheMode.HTTP; - -/** - * Created by Zhenjie Yan on 2018/2/13. - */ -public class SimpleBodyRequest extends BodyRequest implements SimpleRequest { - - private final CacheMode mCacheMode; - private final String mCacheKey; - private final Converter mConverter; - - private SimpleBodyRequest(Api api) { - super(api); - this.mCacheMode = api.mCacheMode == null ? HTTP : api.mCacheMode; - this.mCacheKey = TextUtils.isEmpty(api.mCacheKey) ? url().toString() : api.mCacheKey; - - this.mConverter = api.mConverter; - } - - @Override - public Request request() { - return this; - } - - public static SimpleBodyRequest.Api newApi(Url url, RequestMethod method) { - return new SimpleBodyRequest.Api(url, method); - } - - @Override - public CacheMode cacheMode() { - return mCacheMode; - } - - @Override - public String cacheKey() { - return mCacheKey; - } - - @Override - public Converter converter() { - return mConverter; - } - - public static class Api extends BodyRequest.Api { - - private CacheMode mCacheMode; - private String mCacheKey; - - private Converter mConverter; - - private Api(Url url, RequestMethod method) { - super(url, method); - } - - public Api cacheMode(CacheMode cacheMode) { - this.mCacheMode = cacheMode; - return this; - } - - public Api cacheKey(String cacheKey) { - this.mCacheKey = cacheKey; - return this; - } - - public Api converter(Converter converter) { - this.mConverter = converter; - return this; - } - - public S perform(Type succeed) throws Exception { - return RequestManager.getInstance().perform(new SimpleBodyRequest(this), succeed); - } - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/simple/SimpleRequest.java b/kalle/src/main/java/com/yanzhenjie/kalle/simple/SimpleRequest.java deleted file mode 100644 index 71fa1ada6..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/simple/SimpleRequest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.simple; - -import com.yanzhenjie.kalle.Headers; -import com.yanzhenjie.kalle.Request; -import com.yanzhenjie.kalle.Url; -import com.yanzhenjie.kalle.simple.cache.CacheMode; - -/** - * Created by Zhenjie Yan on 2018/2/20. - */ -public interface SimpleRequest { - /** - * Get the file download address. - */ - Url url(); - - /** - * Get headers. - */ - Headers headers(); - - /** - * Get cache mode. - */ - CacheMode cacheMode(); - - /** - * Get cache key. - */ - String cacheKey(); - - /** - * Get converter. - */ - Converter converter(); - - Request request(); -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/simple/SimpleUrlRequest.java b/kalle/src/main/java/com/yanzhenjie/kalle/simple/SimpleUrlRequest.java deleted file mode 100644 index 0a1be5d7f..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/simple/SimpleUrlRequest.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.simple; - -import android.text.TextUtils; - -import com.yanzhenjie.kalle.Request; -import com.yanzhenjie.kalle.RequestMethod; -import com.yanzhenjie.kalle.Url; -import com.yanzhenjie.kalle.UrlRequest; -import com.yanzhenjie.kalle.simple.cache.CacheMode; - -import java.lang.reflect.Type; - -import static com.yanzhenjie.kalle.simple.cache.CacheMode.HTTP; - -/** - * Created by Zhenjie Yan on 2018/2/13. - */ -public class SimpleUrlRequest extends UrlRequest implements SimpleRequest { - - private final CacheMode mCacheMode; - private final String mCacheKey; - private final Converter mConverter; - - private SimpleUrlRequest(Api api) { - super(api); - this.mCacheMode = api.mCacheMode == null ? HTTP : api.mCacheMode; - this.mCacheKey = TextUtils.isEmpty(api.mCacheKey) ? url().toString() : api.mCacheKey; - - this.mConverter = api.mConverter; - } - - public static SimpleUrlRequest.Api newApi(Url url, RequestMethod method) { - return new SimpleUrlRequest.Api(url, method); - } - - @Override - public Request request() { - return this; - } - - @Override - public CacheMode cacheMode() { - return mCacheMode; - } - - @Override - public String cacheKey() { - return mCacheKey; - } - - @Override - public Converter converter() { - return mConverter; - } - - public static class Api extends UrlRequest.Api { - - private CacheMode mCacheMode; - private String mCacheKey; - - private Converter mConverter; - - private Api(Url url, RequestMethod method) { - super(url, method); - } - - public Api cacheMode(CacheMode cacheMode) { - this.mCacheMode = cacheMode; - return this; - } - - public Api cacheKey(String cacheKey) { - this.mCacheKey = cacheKey; - return this; - } - - public Api converter(Converter converter) { - this.mConverter = converter; - return this; - } - - public S perform(Type succeed) throws Exception { - return RequestManager.getInstance().perform(new SimpleUrlRequest(this), succeed); - } - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/simple/UrlWorker.java b/kalle/src/main/java/com/yanzhenjie/kalle/simple/UrlWorker.java deleted file mode 100644 index bc67a3bd2..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/simple/UrlWorker.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.simple; - -import com.yanzhenjie.kalle.Response; -import com.yanzhenjie.kalle.connect.http.Call; - -import java.io.IOException; -import java.lang.reflect.Type; - -/** - * Created by Zhenjie Yan on 2018/2/13. - */ -final class UrlWorker extends BasicWorker { - - private Call mCall; - - UrlWorker(SimpleUrlRequest request, Type succeed) { - super(request, succeed); - } - - @Override - protected Response requestNetwork(SimpleUrlRequest request) throws IOException { - mCall = new Call(request); - return mCall.execute(); - } - - @Override - public void cancel() { - if (mCall != null && !mCall.isCanceled()) { - mCall.cancel(); - } - } - - @Override - public boolean isCancelled() { - return mCall.isCanceled(); - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/simple/cache/Cache.java b/kalle/src/main/java/com/yanzhenjie/kalle/simple/cache/Cache.java deleted file mode 100644 index f2c4a7330..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/simple/cache/Cache.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.simple.cache; - -import com.yanzhenjie.kalle.Headers; - -import java.io.Serializable; - -/** - *

- * CacheStore entity class. - *

- * Created in Jan 10, 2016 12:43:10 AM. - */ -public class Cache implements Serializable { - - private String mKey; - private int mCode; - private Headers mHeaders; - private byte[] mBody; - private long mExpires; - - public Cache() { - } - - public String getKey() { - return mKey; - } - - public void setKey(String key) { - this.mKey = key; - } - - public int getCode() { - return mCode; - } - - public void setCode(int code) { - mCode = code; - } - - public Headers getHeaders() { - return mHeaders; - } - - public void setHeaders(Headers headers) { - mHeaders = headers; - } - - public byte[] getBody() { - return mBody; - } - - public void setBody(byte[] body) { - this.mBody = body; - } - - public long getExpires() { - return mExpires; - } - - public void setExpires(long expires) { - this.mExpires = expires; - } -} diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/simple/cache/CacheMode.java b/kalle/src/main/java/com/yanzhenjie/kalle/simple/cache/CacheMode.java deleted file mode 100644 index 37760a35f..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/simple/cache/CacheMode.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.simple.cache; - -/** - * Created by Zhenjie Yan on 2018/2/18. - */ -public enum CacheMode { - /** - * Follow the Http standard protocol. - */ - HTTP, - /** - * Follow the Http standard protocol, but it will be cached. - */ - HTTP_YES_THEN_WRITE_CACHE, - /** - * Only get the results from the network. - */ - NETWORK, - /** - * Just get results from the network, and then decide whether to cache according to the Http protocol. - */ - NETWORK_YES_THEN_HTTP, - /** - * Only get the results from the network, but it will be cached. - */ - NETWORK_YES_THEN_WRITE_CACHE, - /** - * Get results first from the network, and from the cache if the network fails. - */ - NETWORK_NO_THEN_READ_CACHE, - /** - * Just get the result from the cache. - */ - READ_CACHE, - /** - * First get the result from the cache, if the cache does not exist, get the result from the network. - */ - READ_CACHE_NO_THEN_NETWORK, - /** - * First get the result from the cache, if the cache does not exist, get results from the network, and follow the http protocol. - */ - READ_CACHE_NO_THEN_HTTP, - /** - * 本地有缓存则读取缓存,如果没有缓存则读取网络并且写入缓存 - */ - READ_CACHE_NO_THEN_NETWORK_THEN_WRITE_CACHE -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/simple/cache/CacheStore.java b/kalle/src/main/java/com/yanzhenjie/kalle/simple/cache/CacheStore.java deleted file mode 100644 index 4c52079c4..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/simple/cache/CacheStore.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.simple.cache; - -/** - *

- * CacheStore interface. - *

- * Created in Dec 14, 2015 5:52:41 PM. - */ -public interface CacheStore { - - CacheStore DEFAULT = new CacheStore() { - @Override - public Cache get(String key) { - return null; - } - - @Override - public boolean replace(String key, Cache cache) { - return true; - } - - @Override - public boolean remove(String key) { - return true; - } - - @Override - public boolean clear() { - return true; - } - }; - - /** - * Get the cache. - * - * @param key unique key. - * @return cache. - */ - Cache get(String key); - - /** - * Save or set the cache. - * - * @param key unique key. - * @param cache cache. - * @return cache. - */ - boolean replace(String key, Cache cache); - - /** - * Remove cache. - * - * @param key unique. - * @return cache. - */ - boolean remove(String key); - - /** - * Clear all data. - * - * @return returns true if successful, false otherwise. - */ - boolean clear(); -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/simple/cache/DiskCacheStore.java b/kalle/src/main/java/com/yanzhenjie/kalle/simple/cache/DiskCacheStore.java deleted file mode 100644 index 3bec9e806..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/simple/cache/DiskCacheStore.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.simple.cache; - -import android.text.TextUtils; - -import com.yanzhenjie.kalle.Headers; -import com.yanzhenjie.kalle.secure.Encryption; -import com.yanzhenjie.kalle.secure.Secret; -import com.yanzhenjie.kalle.util.IOUtils; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.security.GeneralSecurityException; - -/** - *

- * Cache on disk. - *

- * Created by Zhenjie Yan on 2016/10/15. - */ -public class DiskCacheStore implements CacheStore { - - private Secret mSecret; - private String mDirectory; - private DiskCacheStore(Builder builder) { - mDirectory = builder.mDirectory; - String password = TextUtils.isEmpty(builder.mPassword) ? mDirectory : builder.mPassword; - mSecret = Encryption.createSecret(password); - } - - public static Builder newBuilder(String directory) { - return new Builder(directory); - } - - @Override - public Cache get(String key) { - key = uniqueKey(key); - - BufferedReader reader = null; - try { - File file = new File(mDirectory, key); - if (!file.exists() || file.isDirectory()) return null; - - Cache cache = new Cache(); - reader = new BufferedReader(new FileReader(file)); - cache.setCode(Integer.parseInt(decrypt(reader.readLine()))); - cache.setHeaders(Headers.fromJSONString(decrypt(reader.readLine()))); - cache.setBody(Encryption.hexToByteArray(decrypt(reader.readLine()))); - cache.setExpires(Long.parseLong(decrypt(reader.readLine()))); - return cache; - } catch (Exception e) { - IOUtils.delFileOrFolder(new File(mDirectory, key)); - } finally { - IOUtils.closeQuietly(reader); - } - return null; - } - - @Override - public boolean replace(String key, Cache cache) { - key = uniqueKey(key); - - BufferedWriter writer = null; - try { - if (TextUtils.isEmpty(key) || cache == null) return false; - if (!IOUtils.createFolder(mDirectory)) return false; - - File file = new File(mDirectory, key); - if (!IOUtils.createNewFile(file)) return false; - - writer = IOUtils.toBufferedWriter(new FileWriter(file)); - writer.write(encrypt(Integer.toString(cache.getCode()))); - writer.newLine(); - writer.write(encrypt(Headers.toJSONString(cache.getHeaders()))); - writer.newLine(); - writer.write(encrypt(Encryption.byteArrayToHex(cache.getBody()))); - writer.newLine(); - writer.write(encrypt(Long.toString(cache.getExpires()))); - writer.flush(); - return true; - } catch (Exception e) { - IOUtils.delFileOrFolder(new File(mDirectory, key)); - } finally { - IOUtils.closeQuietly(writer); - } - return false; - } - - @Override - public boolean remove(String key) { - key = uniqueKey(key); - return IOUtils.delFileOrFolder(new File(mDirectory, key)); - } - - @Override - public boolean clear() { - return IOUtils.delFileOrFolder(mDirectory); - } - - private String encrypt(String encryptionText) throws GeneralSecurityException { - return mSecret.encrypt(encryptionText); - } - - private String decrypt(String cipherText) throws GeneralSecurityException { - return mSecret.decrypt(cipherText); - } - - private String uniqueKey(String key) { - return Encryption.getMD5ForString(mDirectory + key); - } - - public static class Builder { - - private String mDirectory; - private String mPassword; - - private Builder(String directory) { - this.mDirectory = directory; - } - - public Builder password(String password) { - this.mPassword = password; - return this; - } - - public DiskCacheStore build() { - return new DiskCacheStore(this); - } - } - -} diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/ssl/CompatSSLSocketFactory.java b/kalle/src/main/java/com/yanzhenjie/kalle/ssl/CompatSSLSocketFactory.java deleted file mode 100644 index 5ebe48d65..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/ssl/CompatSSLSocketFactory.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.ssl; - -/** - *

Add CipherSuites to the lower version.

- * Created by Zhenjie Yan on 2017/6/13. - * - * @deprecated use {@link TLSSocketFactory} instead. - */ -@Deprecated -public class CompatSSLSocketFactory extends TLSSocketFactory { -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/ssl/SSLUtils.java b/kalle/src/main/java/com/yanzhenjie/kalle/ssl/SSLUtils.java deleted file mode 100644 index e6e06fd7c..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/ssl/SSLUtils.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.ssl; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLSession; -import javax.net.ssl.SSLSocketFactory; - -/** - * Created by Zhenjie Yan on 2017/6/13. - */ -public class SSLUtils { - - public static final HostnameVerifier HOSTNAME_VERIFIER = new HostnameVerifier() { - public boolean verify(String hostname, SSLSession session) { - return true; - } - }; - - public static final SSLSocketFactory SSL_SOCKET_FACTORY = new TLSSocketFactory(); -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/ssl/TLSSocketFactory.java b/kalle/src/main/java/com/yanzhenjie/kalle/ssl/TLSSocketFactory.java deleted file mode 100644 index 6de1ea5c2..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/ssl/TLSSocketFactory.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.ssl; - -import android.os.Build; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.Socket; -import java.security.GeneralSecurityException; -import java.security.SecureRandom; -import java.security.cert.X509Certificate; - -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSocket; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; - -/** - * Created by Zhenjie Yan on 2018/5/4. - */ -public class TLSSocketFactory extends SSLSocketFactory { - - private static final String PROTOCOL_ARRAY[]; - private static final X509TrustManager DEFAULT_TRUST_MANAGERS = new X509TrustManager() { - - @Override - public void checkClientTrusted(X509Certificate[] chain, String authType) { - // Trust. - } - - @Override - public void checkServerTrusted(X509Certificate[] chain, String authType) { - // Trust. - } - - @Override - public X509Certificate[] getAcceptedIssuers() { - return new X509Certificate[0]; - } - }; - - static { - // https://developer.android.com/about/versions/android-5.0-changes.html#ssl - // https://developer.android.com/reference/javax/net/ssl/SSLSocket - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - PROTOCOL_ARRAY = new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"}; - } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - PROTOCOL_ARRAY = new String[]{"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"}; - } else { - PROTOCOL_ARRAY = new String[]{"SSLv3", "TLSv1"}; - } - } - - private SSLSocketFactory delegate; - - public TLSSocketFactory() { - try { - SSLContext sslContext = SSLContext.getInstance("TLS"); - sslContext.init(null, new TrustManager[]{DEFAULT_TRUST_MANAGERS}, new SecureRandom()); - delegate = sslContext.getSocketFactory(); - } catch (GeneralSecurityException e) { - throw new AssertionError(); // The system has no TLS. Just give up. - } - } - - public TLSSocketFactory(SSLSocketFactory factory) { - this.delegate = factory; - } - - private static void setSupportProtocolAndCipherSuites(Socket socket) { - if (socket instanceof SSLSocket) { - ((SSLSocket) socket).setEnabledProtocols(PROTOCOL_ARRAY); - } - } - - @Override - public String[] getDefaultCipherSuites() { - return delegate.getDefaultCipherSuites(); - } - - @Override - public String[] getSupportedCipherSuites() { - return delegate.getSupportedCipherSuites(); - } - - @Override - public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException { - Socket ssl = delegate.createSocket(s, host, port, autoClose); - setSupportProtocolAndCipherSuites(ssl); - return ssl; - } - - @Override - public Socket createSocket(String host, int port) throws IOException { - Socket ssl = delegate.createSocket(host, port); - setSupportProtocolAndCipherSuites(ssl); - return ssl; - } - - @Override - public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException { - Socket ssl = delegate.createSocket(host, port, localHost, localPort); - setSupportProtocolAndCipherSuites(ssl); - return ssl; - } - - @Override - public Socket createSocket(InetAddress host, int port) throws IOException { - Socket ssl = delegate.createSocket(host, port); - setSupportProtocolAndCipherSuites(ssl); - return ssl; - } - - @Override - public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException { - Socket ssl = delegate.createSocket(address, port, localAddress, localPort); - setSupportProtocolAndCipherSuites(ssl); - return ssl; - } - - @Override - public Socket createSocket() throws IOException { - Socket ssl = delegate.createSocket(); - setSupportProtocolAndCipherSuites(ssl); - return ssl; - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/urlconnect/URLConnection.java b/kalle/src/main/java/com/yanzhenjie/kalle/urlconnect/URLConnection.java deleted file mode 100644 index 5327fc8e6..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/urlconnect/URLConnection.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.urlconnect; - -import android.text.TextUtils; - -import com.yanzhenjie.kalle.connect.Connection; -import com.yanzhenjie.kalle.connect.stream.NullStream; -import com.yanzhenjie.kalle.connect.stream.SourceStream; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.util.List; -import java.util.Map; -import java.util.zip.GZIPInputStream; - -/** - *

- * Implement the network layer based on HttpURLConnection. - *

- * Created by Zhenjie Yan on 2017/2/12. - */ -public class URLConnection implements Connection { - - private HttpURLConnection mConnection; - - public URLConnection(HttpURLConnection connection) { - this.mConnection = connection; - } - - private static InputStream getInputStream(String contentEncoding, InputStream stream) throws IOException { - if (!TextUtils.isEmpty(contentEncoding) && contentEncoding.contains("gzip")) { - stream = new GZIPInputStream(stream); - } - return stream; - } - - private static boolean hasBody(String method, int code) { - return !"HEAD".equalsIgnoreCase(method) && hasBody(code); - } - - private static boolean hasBody(int code) { - return code > 100 && code != 204 && code != 205 && !(code >= 300 && code < 400); - } - - @Override - public OutputStream getOutputStream() throws IOException { - return mConnection.getOutputStream(); - } - - @Override - public int getCode() throws IOException { - return mConnection.getResponseCode(); - } - - @Override - public Map> getHeaders() throws IOException { - return mConnection.getHeaderFields(); - } - - @Override - public InputStream getInputStream() throws IOException { - int code = mConnection.getResponseCode(); - if (!hasBody(mConnection.getRequestMethod(), code)) return new NullStream(this); - if (code >= 400) { - return getInputStream(mConnection.getContentEncoding(), new SourceStream(this, mConnection.getErrorStream())); - } - return getInputStream(mConnection.getContentEncoding(), new SourceStream(this, mConnection.getInputStream())); - } - - @Override - public void disconnect() { - if (mConnection != null) { - mConnection.disconnect(); - } - } - - @Override - public void close() throws IOException { - if (mConnection != null) { - mConnection.disconnect(); - } - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/urlconnect/URLConnectionFactory.java b/kalle/src/main/java/com/yanzhenjie/kalle/urlconnect/URLConnectionFactory.java deleted file mode 100644 index 2ca94d8e0..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/urlconnect/URLConnectionFactory.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.urlconnect; - -import android.os.Build; - -import com.yanzhenjie.kalle.Headers; -import com.yanzhenjie.kalle.Request; -import com.yanzhenjie.kalle.RequestMethod; -import com.yanzhenjie.kalle.connect.ConnectFactory; -import com.yanzhenjie.kalle.connect.Connection; - -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.Proxy; -import java.net.URL; -import java.util.List; -import java.util.Map; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLSocketFactory; - -import static com.yanzhenjie.kalle.Headers.KEY_CONNECTION; -import static com.yanzhenjie.kalle.Headers.VALUE_CLOSE; - -/** - *

- * Network connection actuator based on URLConnection. - *

- * Created by Zhenjie Yan on 2016/10/15. - */ -public class URLConnectionFactory implements ConnectFactory { - - private URLConnectionFactory(Builder builder) { - } - - public static Builder newBuilder() { - return new Builder(); - } - - @Override - public Connection connect(Request request) throws IOException { - HttpURLConnection connection; - URL url = new URL(request.url().toString(true)); - - Proxy proxy = request.proxy(); - if (proxy == null) - connection = (HttpURLConnection) url.openConnection(); - else - connection = (HttpURLConnection) url.openConnection(proxy); - - connection.setConnectTimeout(request.connectTimeout()); - connection.setReadTimeout(request.readTimeout()); - connection.setInstanceFollowRedirects(false); - - if (connection instanceof HttpsURLConnection) { - SSLSocketFactory sslSocketFactory = request.sslSocketFactory(); - if (sslSocketFactory != null) - ((HttpsURLConnection) connection).setSSLSocketFactory(sslSocketFactory); - HostnameVerifier hostnameVerifier = request.hostnameVerifier(); - if (hostnameVerifier != null) - ((HttpsURLConnection) connection).setHostnameVerifier(hostnameVerifier); - } - - RequestMethod method = request.method(); - connection.setRequestMethod(method.toString()); - connection.setDoInput(true); - boolean isAllowBody = isAllowBody(method); - connection.setDoOutput(isAllowBody); - - Headers headers = request.headers(); - - if (isAllowBody) { - long contentLength = headers.getContentLength(); - if (contentLength <= Integer.MAX_VALUE) - connection.setFixedLengthStreamingMode((int) contentLength); - else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) - connection.setFixedLengthStreamingMode(contentLength); - else connection.setChunkedStreamingMode(256 * 1024); - } - - List values = headers.get(KEY_CONNECTION); - headers.set(KEY_CONNECTION, Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT ? values.get(0) : VALUE_CLOSE); - Map requestHeaders = Headers.getRequestHeaders(headers); - for (Map.Entry entry : requestHeaders.entrySet()) { - connection.setRequestProperty(entry.getKey(), entry.getValue()); - } - - connection.connect(); - return new URLConnection(connection); - } - - private boolean isAllowBody(RequestMethod method) { - boolean allowRequestBody = method.allowBody(); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) - return allowRequestBody && method != RequestMethod.DELETE; - return allowRequestBody; - } - - public static class Builder { - private Builder() { - } - - public URLConnectionFactory build() { - return new URLConnectionFactory(this); - } - } -} diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/util/IOUtils.java b/kalle/src/main/java/com/yanzhenjie/kalle/util/IOUtils.java deleted file mode 100644 index 39a76d676..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/util/IOUtils.java +++ /dev/null @@ -1,598 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.util; - -import android.os.Build; -import android.os.StatFs; -import android.text.TextUtils; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.CharArrayWriter; -import java.io.Closeable; -import java.io.File; -import java.io.Flushable; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Reader; -import java.io.Writer; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; - -/** - * Created in 2016/4/12 21:21. - */ -public class IOUtils { - - public static void closeQuietly(Closeable closeable) { - if (closeable != null) - try { - closeable.close(); - } catch (Exception ignored) { - } - } - - public static void flushQuietly(Flushable flushable) { - if (flushable != null) - try { - flushable.flush(); - } catch (Exception ignored) { - } - } - - public static BufferedInputStream toBufferedInputStream(InputStream inputStream) { - return inputStream instanceof BufferedInputStream ? (BufferedInputStream) inputStream : new BufferedInputStream(inputStream); - } - - public static BufferedOutputStream toBufferedOutputStream(OutputStream outputStream) { - return outputStream instanceof BufferedOutputStream ? (BufferedOutputStream) outputStream : new BufferedOutputStream(outputStream); - } - - public static BufferedReader toBufferedReader(Reader reader) { - return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader); - } - - public static BufferedWriter toBufferedWriter(Writer writer) { - return writer instanceof BufferedWriter ? (BufferedWriter) writer : new BufferedWriter(writer); - } - - public static InputStream toInputStream(CharSequence input) { - return new ByteArrayInputStream(input.toString().getBytes()); - } - - public static InputStream toInputStream(CharSequence input, String charset) { - return toInputStream(input, Charset.forName(charset)); - } - - public static InputStream toInputStream(CharSequence input, Charset charset) { - byte[] bytes = input.toString().getBytes(charset); - return new ByteArrayInputStream(bytes); - } - - public static String toString(InputStream input) throws IOException { - return new String(toByteArray(input)); - } - - public static String toString(InputStream input, String charset) throws IOException { - return new String(toByteArray(input), charset); - } - - public static String toString(InputStream input, Charset charset) throws IOException { - return new String(toByteArray(input), charset); - } - - public static String toString(Reader input) throws IOException { - return new String(toByteArray(input)); - } - - public static String toString(Reader input, String charset) throws IOException { - return new String(toByteArray(input), charset); - } - - public static String toString(Reader input, Charset charset) throws IOException { - return new String(toByteArray(input), charset); - } - - public static String toString(byte[] byteArray) { - return new String(byteArray); - } - - public static String toString(byte[] byteArray, String charset) { - return toString(byteArray, Charset.forName(charset)); - } - - public static String toString(byte[] byteArray, Charset charset) { - return new String(byteArray, charset); - } - - public static byte[] toByteArray(CharSequence input) { - if (input == null) - return new byte[0]; - return input.toString().getBytes(); - } - - public static byte[] toByteArray(CharSequence input, String charset) { - return toByteArray(input, Charset.forName(charset)); - } - - public static byte[] toByteArray(CharSequence input, Charset charset) { - if (input == null) - return new byte[0]; - else - return input.toString().getBytes(charset); - } - - public static byte[] toByteArray(InputStream input) throws IOException { - ByteArrayOutputStream output = new ByteArrayOutputStream(); - write(input, output); - output.close(); - return output.toByteArray(); - } - - public static byte[] toByteArray(InputStream input, int size) throws IOException { - if (size < 0) - throw new IllegalArgumentException("Size must be equal or greater than zero: " + size); - - if (size == 0) return new byte[0]; - - byte[] data = new byte[size]; - int offset = 0; - int byteCount; - while ((offset < size) && (byteCount = input.read(data, offset, size - offset)) != -1) - offset += byteCount; - - if (offset != size) - throw new IOException("Unexpected byte count size. current: " + offset + ", excepted: " + size); - return data; - } - - public static byte[] toByteArray(Reader input) throws IOException { - ByteArrayOutputStream output = new ByteArrayOutputStream(); - write(input, output); - output.close(); - return output.toByteArray(); - } - - public static byte[] toByteArray(Reader input, String charset) throws IOException { - return toByteArray(input, Charset.forName(charset)); - } - - public static byte[] toByteArray(Reader input, Charset charset) throws IOException { - ByteArrayOutputStream output = new ByteArrayOutputStream(); - write(input, output, charset); - output.close(); - return output.toByteArray(); - } - - public static char[] toCharArray(CharSequence input) throws IOException { - CharArrayWriter output = new CharArrayWriter(); - write(output, input); - return output.toCharArray(); - } - - public static char[] toCharArray(InputStream input) throws IOException { - CharArrayWriter output = new CharArrayWriter(); - write(input, output); - return output.toCharArray(); - } - - public static char[] toCharArray(InputStream input, String charset) throws IOException { - return toCharArray(input, Charset.forName(charset)); - } - - public static char[] toCharArray(InputStream input, Charset charset) throws IOException { - CharArrayWriter output = new CharArrayWriter(); - write(input, output, charset); - return output.toCharArray(); - } - - public static char[] toCharArray(Reader input) throws IOException { - CharArrayWriter output = new CharArrayWriter(); - write(input, output); - return output.toCharArray(); - } - - public static List readLines(InputStream input, String charset) throws IOException { - return readLines(input, Charset.forName(charset)); - } - - public static List readLines(InputStream input, Charset charset) throws IOException { - Reader reader = new InputStreamReader(input, charset); - return readLines(reader); - } - - public static List readLines(InputStream input) throws IOException { - Reader reader = new InputStreamReader(input); - return readLines(reader); - } - - public static List readLines(Reader input) throws IOException { - BufferedReader reader = toBufferedReader(input); - List list = new ArrayList<>(); - String line = reader.readLine(); - while (line != null) { - list.add(line); - line = reader.readLine(); - } - return list; - } - - public static void write(OutputStream output, byte[] data) throws IOException { - if (data != null) { - output.write(data); - output.flush(); - } - } - - public static void write(Writer output, byte[] data) throws IOException { - if (data != null) { - output.write(new String(data)); - output.flush(); - } - } - - public static void write(Writer output, byte[] data, String charset) throws IOException { - write(output, data, Charset.forName(charset)); - } - - public static void write(Writer output, byte[] data, Charset charset) throws IOException { - if (data != null) { - output.write(new String(data, charset)); - output.flush(); - } - } - - public static void write(Writer output, char[] data) throws IOException { - if (data != null) { - output.write(data); - output.flush(); - } - } - - public static void write(OutputStream output, char[] data) throws IOException { - if (data != null) { - output.write(new String(data).getBytes()); - output.flush(); - } - } - - public static void write(OutputStream output, char[] data, String charset) throws IOException { - write(output, data, Charset.forName(charset)); - } - - public static void write(OutputStream output, char[] data, Charset charset) throws IOException { - if (data != null) { - output.write(new String(data).getBytes(charset)); - output.flush(); - } - } - - public static void write(Writer output, CharSequence data) throws IOException { - if (data != null) { - output.write(data.toString()); - output.flush(); - } - } - - public static void write(OutputStream output, CharSequence data) throws IOException { - if (data != null) { - output.write(data.toString().getBytes()); - output.flush(); - } - } - - public static void write(OutputStream output, CharSequence data, String charset) throws IOException { - write(output, data, Charset.forName(charset)); - } - - public static void write(OutputStream output, CharSequence data, Charset charset) throws IOException { - if (data != null) { - output.write(data.toString().getBytes(charset)); - output.flush(); - } - } - - public static void write(Reader input, OutputStream output) throws IOException { - Writer out = new OutputStreamWriter(output); - write(input, out); - } - - public static void write(InputStream input, OutputStream output) throws IOException { - int len; - byte[] buffer = new byte[4096]; - while ((len = input.read(buffer)) != -1) { - output.write(buffer, 0, len); - output.flush(); - } - } - - public static void write(InputStream input, Writer output) throws IOException { - Reader in = new InputStreamReader(input); - write(in, output); - } - - public static void write(Reader input, OutputStream output, String charset) throws IOException { - write(input, output, Charset.forName(charset)); - } - - public static void write(Reader input, OutputStream output, Charset charset) throws IOException { - Writer out = new OutputStreamWriter(output, charset); - write(input, out); - } - - public static void write(InputStream input, OutputStream output, String charset) throws IOException { - write(input, output, Charset.forName(charset)); - } - - public static void write(InputStream input, OutputStream output, Charset charset) throws IOException { - Reader in = new InputStreamReader(input, charset); - write(in, output); - } - - public static void write(InputStream input, Writer output, String charset) throws IOException { - write(input, output, Charset.forName(charset)); - } - - public static void write(InputStream input, Writer output, Charset charset) throws IOException { - Reader in = new InputStreamReader(input, charset); - write(in, output); - } - - public static void write(Reader input, Writer output) throws IOException { - int len; - char[] buffer = new char[4096]; - while (-1 != (len = input.read(buffer))) { - output.write(buffer, 0, len); - output.flush(); - } - } - - public static boolean contentEquals(InputStream input1, InputStream input2) throws IOException { - input1 = toBufferedInputStream(input1); - input2 = toBufferedInputStream(input2); - - int ch = input1.read(); - while (-1 != ch) { - int ch2 = input2.read(); - if (ch != ch2) return false; - ch = input1.read(); - } - - int ch2 = input2.read(); - return ch2 == -1; - } - - public static boolean contentEquals(Reader input1, Reader input2) throws IOException { - input1 = toBufferedReader(input1); - input2 = toBufferedReader(input2); - - int ch = input1.read(); - while (-1 != ch) { - int ch2 = input2.read(); - if (ch != ch2) return false; - ch = input1.read(); - } - - int ch2 = input2.read(); - return ch2 == -1; - } - - public static boolean contentEqualsIgnoreEOL(Reader input1, Reader input2) throws IOException { - BufferedReader br1 = toBufferedReader(input1); - BufferedReader br2 = toBufferedReader(input2); - - String line1 = br1.readLine(); - String line2 = br2.readLine(); - while ((line1 != null) && (line2 != null) && (line1.equals(line2))) { - line1 = br1.readLine(); - line2 = br2.readLine(); - } - return line1 != null && (line2 == null || line1.equals(line2)); - } - - /** - * Access to a directory available size. - * - * @param path path. - * @return space size. - */ - public static long getDirSize(String path) { - StatFs stat; - try { - stat = new StatFs(path); - } catch (Exception e) { - return 0; - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) - return stat.getBlockSizeLong() * stat.getAvailableBlocksLong(); - else - return (long) stat.getBlockSize() * (long) stat.getAvailableBlocks(); - } - - /** - * If the folder can be written. - * - * @param path path. - * @return True: success, or false: failure. - */ - public static boolean canWrite(String path) { - return new File(path).canWrite(); - } - - /** - * If the folder can be readResponse. - * - * @param path path. - * @return True: success, or false: failure. - */ - public static boolean canRead(String path) { - return new File(path).canRead(); - } - - /** - * Create a folder, If the folder exists is not created. - * - * @param folderPath folder path. - * @return True: success, or false: failure. - */ - public static boolean createFolder(String folderPath) { - if (!TextUtils.isEmpty(folderPath)) { - File folder = new File(folderPath); - return createFolder(folder); - } - return false; - } - - /** - * Create a folder, If the folder exists is not created. - * - * @param targetFolder folder path. - * @return True: success, or false: failure. - */ - public static boolean createFolder(File targetFolder) { - if (targetFolder.exists()) { - if (targetFolder.isDirectory()) - return true; - //noinspection ResultOfMethodCallIgnored - targetFolder.delete(); - } - return targetFolder.mkdirs(); - } - - /** - * Create a folder, If the folder exists is not created. - * - * @param folderPath folder path. - * @return True: success, or false: failure. - */ - public static boolean createNewFolder(String folderPath) { - return delFileOrFolder(folderPath) && createFolder(folderPath); - } - - /** - * Create a folder, If the folder exists is not created. - * - * @param targetFolder folder path. - * @return True: success, or false: failure. - */ - public static boolean createNewFolder(File targetFolder) { - return delFileOrFolder(targetFolder) && createFolder(targetFolder); - } - - /** - * Create a file, If the file exists is not created. - * - * @param filePath file path. - * @return True: success, or false: failure. - */ - public static boolean createFile(String filePath) { - if (!TextUtils.isEmpty(filePath)) { - File file = new File(filePath); - return createFile(file); - } - return false; - } - - /** - * Create a file, If the file exists is not created. - * - * @param targetFile file. - * @return True: success, or false: failure. - */ - public static boolean createFile(File targetFile) { - if (targetFile.exists()) { - if (targetFile.isFile()) - return true; - delFileOrFolder(targetFile); - } - try { - return targetFile.createNewFile(); - } catch (IOException e) { - return false; - } - } - - /** - * Create a new file, if the file exists, delete and create again. - * - * @param filePath file path. - * @return True: success, or false: failure. - */ - public static boolean createNewFile(String filePath) { - if (!TextUtils.isEmpty(filePath)) { - File file = new File(filePath); - return createNewFile(file); - } - return false; - } - - /** - * Create a new file, if the file exists, delete and create again. - * - * @param targetFile file. - * @return True: success, or false: failure. - */ - public static boolean createNewFile(File targetFile) { - if (targetFile.exists()) - delFileOrFolder(targetFile); - try { - return targetFile.createNewFile(); - } catch (IOException e) { - return false; - } - } - - /** - * Delete file or folder. - * - * @param path path. - * @return is succeed. - * @see #delFileOrFolder(File) - */ - public static boolean delFileOrFolder(String path) { - return delFileOrFolder(new File(path)); - } - - /** - * Delete file or folder. - * - * @param file file. - * @return is succeed. - * @see #delFileOrFolder(String) - */ - public static boolean delFileOrFolder(File file) { - if (file == null || !file.exists()) { - // do nothing - } else if (file.isFile()) - file.delete(); - else if (file.isDirectory()) { - File[] files = file.listFiles(); - if (files != null) - for (File sonFile : files) - delFileOrFolder(sonFile); - file.delete(); - } - return true; - } -} diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/util/LengthOutputStream.java b/kalle/src/main/java/com/yanzhenjie/kalle/util/LengthOutputStream.java deleted file mode 100644 index eb38c4864..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/util/LengthOutputStream.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yanzhenjie.kalle.util; - -import java.io.OutputStream; -import java.util.concurrent.atomic.AtomicLong; - -/** - * Created by Zhenjie Yan on 2019-06-24. - */ -public class LengthOutputStream extends OutputStream { - - private final AtomicLong mLength = new AtomicLong(0L); - - public LengthOutputStream() { - } - - public long getLength() { - return mLength.get(); - } - - public void write(long multiByte) { - mLength.addAndGet(multiByte); - } - - @Override - public void write(int oneByte) { - mLength.addAndGet(1); - } - - @Override - public void write(byte[] buffer) { - mLength.addAndGet(buffer.length); - } - - @Override - public void write(byte[] buffer, int offset, int count) { - mLength.addAndGet(count); - } - - @Override - public void close() { - } - - @Override - public void flush() { - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/util/ListMap.java b/kalle/src/main/java/com/yanzhenjie/kalle/util/ListMap.java deleted file mode 100644 index cfb3bd794..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/util/ListMap.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.util; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Created on 2016/6/23. - */ -public class ListMap { - - private Map> mSource; - - public ListMap(Map> source) { - this.mSource = source; - } - - /** - * Add key-values pair. - * - * @param key key, unique. - * @param value value, a key has multiple values. - */ - public void add(K key, V value) { - if (!mSource.containsKey(key)) - mSource.put(key, new ArrayList(1)); - mSource.get(key).add(value); - } - - /** - * Add key-values pair. - * - * @param key key, unique. - * @param values values, a key has multiple values. - */ - public void add(K key, List values) { - for (V value : values) { - add(key, value); - } - } - - /** - * Replace key-values pair, - * if the key exists to add value, create the key if the key does not exist, add value. - * - * @param key key, unique. - * @param value value, a key has multiple values. - */ - public void set(K key, V value) { - mSource.remove(key); - add(key, value); - } - - /** - * Replace key-values pair, - * if the key exists to add value, create the key if the key does not exist, add value. - * - * @param key key, unique. - * @param values values, a key has multiple values. - */ - public void set(K key, List values) { - mSource.put(key, values); - } - - /** - * Get all values of a key. - * - * @param key key. - * @return if the key does not exist, it may be null. - */ - public List get(K key) { - return mSource.get(key); - } - - /** - * Get the first value of the key. - * - * @param key key. - * @return if the key does not exist, it may be null. - */ - public V getFirst(K key) { - List values = mSource.get(key); - if (values != null && values.size() > 0) - return values.get(0); - return null; - } - - /** - * Get {@link Set} view of the mappings. - * - * @return a set view of the mappings. - * @see Map#entrySet() - */ - public Set>> entrySet() { - return mSource.entrySet(); - } - - /** - * Get {@link Set} view of the keys. - * - * @return a set view of the keys. - * @see Map#keySet() - */ - public Set keySet() { - return mSource.keySet(); - } - - /** - * Get the count of key-values. - * - * @return always greater than or equal to 0. - * @see Map#size() - */ - public int size() { - return mSource.size(); - } - - /** - * Map is empty. - * - * @return true if there are no key-values pairs. - * @see Map#isEmpty() - */ - public boolean isEmpty() { - return mSource.isEmpty(); - } - - /** - * Map contains the key. - * - * @param key key. - * @return true if there contains the key. - */ - public boolean containsKey(K key) { - return mSource.containsKey(key); - } - - /** - * Remove the key and all values of key. - * - * @param key key. - * @return all values. - */ - public List remove(K key) { - return mSource.remove(key); - } - - /** - * Remove all key and all values. - */ - public void clear() { - mSource.clear(); - } - - /** - * Convert to Map. - */ - public Map> toMap() { - return mSource; - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/util/ProgressOutputStream.java b/kalle/src/main/java/com/yanzhenjie/kalle/util/ProgressOutputStream.java deleted file mode 100644 index 23b02a301..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/util/ProgressOutputStream.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yanzhenjie.kalle.util; - -import com.yanzhenjie.kalle.Content; -import com.yanzhenjie.kalle.ProgressBar; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * Created by Zhenjie Yan on 2019-06-24. - */ -public class ProgressOutputStream extends OutputStream { - - private OutputStream mWriter; - private T mOrigin; - private ProgressBar mProgressBar; - - private long mContentLength; - private long mWriteCount; - private int mOldProgress; - - - public ProgressOutputStream(OutputStream writer, T origin, ProgressBar progressBar) { - this.mWriter = writer; - this.mOrigin = origin; - this.mProgressBar = progressBar; - - this.mContentLength = mOrigin.contentLength(); - } - - @Override - public void write(int b) throws IOException { - mWriter.write(b); - mWriteCount += 1; - calcProgress(); - } - - @Override - public void write(byte[] b) throws IOException { - mWriter.write(b); - mWriteCount += b.length; - calcProgress(); - } - - @Override - public void write(byte[] b, int off, int len) throws IOException { - mWriter.write(b, off, len); - mWriteCount += len; - calcProgress(); - } - - @Override - public void flush() throws IOException { - mWriter.flush(); - } - - @Override - public void close() throws IOException { - mWriter.close(); - } - - private void calcProgress() { - if (mContentLength > 0) { - int progress = (int) (mWriteCount * 100 / mContentLength); - if (progress > mOldProgress && progress % 2 == 0) { - mOldProgress = progress; - mProgressBar.progress(mOrigin, mOldProgress); - } - } - } -} diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/util/UrlUtils.java b/kalle/src/main/java/com/yanzhenjie/kalle/util/UrlUtils.java deleted file mode 100644 index c5965f5c5..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/util/UrlUtils.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.util; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.net.URLEncoder; -import java.nio.charset.Charset; - -/** - * Created by Zhenjie Yan on 2018/2/20. - */ -public class UrlUtils { - - public static String urlEncode(String target, String charset) { - try { - return URLEncoder.encode(target, charset); - } catch (UnsupportedEncodingException e) { - return target; - } - } - - public static String urlEncode(String target, Charset charset) { - return urlEncode(target, charset.name()); - } - - public static String urlDecode(String target, String charset) { - try { - return URLDecoder.decode(target, charset); - } catch (UnsupportedEncodingException e) { - return target; - } - } - - public static String urlDecode(String target, Charset charset) { - return urlDecode(target, charset.name()); - } -} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/util/WorkExecutor.java b/kalle/src/main/java/com/yanzhenjie/kalle/util/WorkExecutor.java deleted file mode 100644 index 02117a155..000000000 --- a/kalle/src/main/java/com/yanzhenjie/kalle/util/WorkExecutor.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yanzhenjie.kalle.util; - -import java.util.concurrent.Executor; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Created by Zhenjie Yan on 2018/2/26. - */ -public class WorkExecutor implements Executor { - - private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors(); - - private static final ThreadFactory THREAD_FACTORY = new ThreadFactory() { - private final AtomicInteger mCount = new AtomicInteger(1); - - public Thread newThread(Runnable r) { - return new Thread(r, "Request #" + mCount.getAndIncrement()); - } - }; - - private ThreadPoolExecutor mPoolExecutor; - - public WorkExecutor() { - mPoolExecutor = new ThreadPoolExecutor( - Math.max(2, Math.min(CPU_COUNT - 1, 4)), - CPU_COUNT * 2 + 1, - 60L, - TimeUnit.SECONDS, - new LinkedBlockingQueue(128), - THREAD_FACTORY); - mPoolExecutor.allowCoreThreadTimeOut(true); - } - - @Override - public void execute(Runnable command) { - mPoolExecutor.execute(command); - } -} \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index aa0f757ae..144de8408 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -36,25 +36,33 @@ markdown_extensions: nav: - 使用: index.md - - 并发: parallel.md - - 作用域: scope.md + - 协程请求: parallel.md + - 同步请求: sync-request.md + - 队列请求: enqueue-request.md + - 请求参数: request-params.md + - 创建作用域: scope.md - 全局配置: config.md - - 异常追踪: exception-track.md - - 全局错误处理: global-error-handle.md - - 转换器: convert.md + - OkHttpClient: okhttp-client.md + - 全局错误处理: error-handle.md - 拦截器: interceptor.md + - Https证书: https.md + - 转换器: converter.md + - 异常追踪: exception-track.md - 自动化: - 自动加载框: auto-dialog.md - 自动缺省页: auto-state.md - 自动下拉刷新: auto-refresh.md - 自动分页加载: auto-page.md + - 转换数据: + - 转换Data字段: convert-data-field.md + - 转换JSON数组: convert-json-array.md + - ViewModel: view-model.md - 切换线程: switch-dispatcher.md - 标签: tag.md - 上传文件: upload-file.md - 下载文件: download-file.md - - 下载图片: download-image.md - - 读取缓存: read-cache.md - - 返回集合结果: parse-list.md + - 进度监听: progress.md + # - 读取缓存: read-cache.md - 嵌套作用域: nested-scope.md - 最快请求结果: fastest.md - 重复请求: unique.md diff --git a/net/build.gradle b/net/build.gradle index ae5eec641..5c9dda35d 100644 --- a/net/build.gradle +++ b/net/build.gradle @@ -41,6 +41,10 @@ android { } } + kotlinOptions { + freeCompilerArgs = ["-Xinline-classes"] + } + dokka { outputFormat = 'gfm' outputDirectory = "$rootDir/docs/api" @@ -53,19 +57,14 @@ dependencies { api fileTree(dir: "libs", include: ["*.jar"]) implementation "androidx.appcompat:appcompat:1.2.0" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - testImplementation "junit:junit:4.13.1" + testImplementation "junit:junit:4.13.2" androidTestImplementation "androidx.test:runner:1.3.0" androidTestImplementation "androidx.test.espresso:espresso-core:3.3.0" - - api "com.squareup.okhttp3:okhttp:4.9.0" - implementation "com.github.liangjingkanji:Tooltip:1.1.0" - api project(path: ':kalle') - compileOnly "com.github.liangjingkanji:BRV:$brv_version" - compileOnly "com.github.bumptech.glide:glide:$glide_version" + compileOnly "com.squareup.okhttp3:okhttp:$okhttp_version" + compileOnly "com.github.liangjingkanji:BRV:$brv_version" compileOnly "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutine_version" compileOnly "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine_version" - } diff --git a/net/src/main/AndroidManifest.xml b/net/src/main/AndroidManifest.xml index d188a0b72..6e56578f4 100644 --- a/net/src/main/AndroidManifest.xml +++ b/net/src/main/AndroidManifest.xml @@ -1,25 +1,23 @@ - - + + + + + + + + tools:targetApi="n"> + + \ No newline at end of file diff --git a/net/src/main/java/androidx/lifecycle/Scope.kt b/net/src/main/java/androidx/lifecycle/Scope.kt index 9438ded62..349d41670 100644 --- a/net/src/main/java/androidx/lifecycle/Scope.kt +++ b/net/src/main/java/androidx/lifecycle/Scope.kt @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2018 Drake, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package androidx.lifecycle import com.drake.net.scope.AndroidScope diff --git a/net/src/main/java/com/drake/net/Init.kt b/net/src/main/java/com/drake/net/Init.kt new file mode 100644 index 000000000..d4e27f7d3 --- /dev/null +++ b/net/src/main/java/com/drake/net/Init.kt @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2018 Drake, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.drake.net + +import com.drake.net.okhttp.toNetOkhttp +import okhttp3.OkHttpClient + + +/** + * 初始化框架 + * @param host 请求url的主机名 + * @param config 进行配置网络请求 + * + * 如果想要自动解析数据模型请配置转换器, 可以继承或者参考默认转换器 + * + * @see com.drake.net.convert.JSONConvert + */ +fun initNet(host: String = "", config: OkHttpClient.Builder.() -> Unit = {}) { + NetConfig.host = host + val builder = OkHttpClient.Builder() + builder.config() + NetConfig.okHttpClient = builder.toNetOkhttp().build() +} + +fun initNet(host: String = "", config: OkHttpClient.Builder) { + NetConfig.host = host + NetConfig.okHttpClient = config.toNetOkhttp().build() +} \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/Net.kt b/net/src/main/java/com/drake/net/Net.kt index 23fb7bd85..b3313949f 100644 --- a/net/src/main/java/com/drake/net/Net.kt +++ b/net/src/main/java/com/drake/net/Net.kt @@ -14,705 +14,247 @@ * limitations under the License. */ -@file:Suppress("unused", "FunctionName") +@file:Suppress("unused", "FunctionName") @file:JvmName("NetKt") package com.drake.net -import android.content.Context -import com.bumptech.glide.Glide -import com.yanzhenjie.kalle.NetCancel -import com.yanzhenjie.kalle.RequestMethod -import com.yanzhenjie.kalle.Url -import com.yanzhenjie.kalle.download.BodyDownload -import com.yanzhenjie.kalle.download.UrlDownload -import com.yanzhenjie.kalle.simple.SimpleBodyRequest -import com.yanzhenjie.kalle.simple.SimpleUrlRequest -import com.yanzhenjie.kalle.simple.cache.CacheMode -import kotlinx.coroutines.* -import java.io.File -import java.net.SocketException - -// - - -/** - * 异步网络请求 - * - * @param path String 请求路径, 非绝对路径会加上[NetConfig.host]为前缀 - * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - * @param absolutePath 请求路径是否是绝对路径 - * @param uid 表示请求的唯一id, 和[NetCancel.cancel]中的uid一致, 一般用于指定取消网络请求的唯一id - * @param block 函数中可以配置请求参数 - */ -inline fun CoroutineScope.Get( - path: String, - tag: Any? = null, - cache: CacheMode = CacheMode.HTTP, - absolutePath: Boolean = false, - uid: Any? = coroutineContext[CoroutineExceptionHandler], - noinline block: SimpleUrlRequest.Api.() -> Unit = {} -): Deferred = async(Dispatchers.IO + SupervisorJob()) { - if (!isActive) throw CancellationException() - - val realPath = if (absolutePath) path else (NetConfig.host + path) - - val request = SimpleUrlRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.GET) - .tag(tag) - .uid(uid) - .cacheKey(path) - .cacheMode(cache) - - try { - request.apply(block).perform(M::class.java) - } catch (e: SocketException) { - throw CancellationException() +import com.drake.net.interfaces.ProgressListener +import com.drake.net.request.* +import com.drake.net.tag.NetLabel +import okhttp3.Request +import java.util.* +import kotlin.collections.ArrayList + +object Net { + + // + /** + * 同步网络请求 + * + * @param path 请求路径, 如果其不包含http/https则会自动拼接[NetConfig.host] + * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 + * @param block 函数中可以配置请求参数 + */ + fun get( + path: String, + tag: Any? = null, + block: (UrlRequest.() -> Unit)? = null + ) = UrlRequest().apply { + setPath(path) + method = Method.GET + setTag(tag) + block?.invoke(this) } -} - -/** - * 异步网络请求 - * - * @param path String 请求路径, 非绝对路径会加上[NetConfig.host]为前缀 - * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - * @param absolutePath 请求路径是否是绝对路径 - * @param uid 表示请求的唯一id, 和[NetCancel.cancel]中的uid一致, 一般用于指定取消网络请求的唯一id - * @param block 函数中可以配置请求参数 - */ -inline fun CoroutineScope.Post( - path: String, - tag: Any? = null, - cache: CacheMode = CacheMode.HTTP, - absolutePath: Boolean = false, - uid: Any? = coroutineContext[CoroutineExceptionHandler], - noinline block: SimpleBodyRequest.Api.() -> Unit = {} -): Deferred = async(Dispatchers.IO + SupervisorJob()) { - if (!isActive) throw CancellationException() - - val realPath = if (absolutePath) path else (NetConfig.host + path) - - val request = SimpleBodyRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.POST) - .tag(tag) - .uid(uid) - .cacheKey(path) - .cacheMode(cache) - - try { - request.apply(block).perform(M::class.java) - } catch (e: SocketException) { - throw CancellationException() + fun post( + path: String, + tag: Any? = null, + block: (BodyRequest.() -> Unit)? = null + ) = BodyRequest().apply { + setPath(path) + method = Method.POST + setTag(tag) + block?.invoke(this) } -} - - -/** - * 异步网络请求 - * @param path String 请求路径, 非绝对路径会加上[NetConfig.host]为前缀 - * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - * @param absolutePath 请求路径是否是绝对路径 - * @param uid 表示请求的唯一id, 和[NetCancel.cancel]中的uid一致, 一般用于指定取消网络请求的唯一id - * @param block 函数中可以配置请求参数 - */ -inline fun CoroutineScope.Head( - path: String, - tag: Any? = null, - cache: CacheMode = CacheMode.HTTP, - absolutePath: Boolean = false, - uid: Any? = coroutineContext[CoroutineExceptionHandler], - noinline block: SimpleUrlRequest.Api.() -> Unit = {} -): Deferred = async(Dispatchers.IO + SupervisorJob()) { - if (!isActive) throw CancellationException() - val realPath = if (absolutePath) path else (NetConfig.host + path) - - val request = SimpleUrlRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.HEAD) - .tag(tag) - .uid(uid) - .cacheKey(path) - .cacheMode(cache) - - try { - request.apply(block).perform(M::class.java) - } catch (e: SocketException) { - throw CancellationException() + fun head( + path: String, + tag: Any? = null, + block: (UrlRequest.() -> Unit)? = null + ) = UrlRequest().apply { + setPath(path) + method = Method.HEAD + setTag(tag) + block?.invoke(this) } -} - -/** - * 异步网络请求 - * @param path String 请求路径, 非绝对路径会加上[NetConfig.host]为前缀 - * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - * @param absolutePath 请求路径是否是绝对路径 - * @param uid 表示请求的唯一id, 和[NetCancel.cancel]中的uid一致, 一般用于指定取消网络请求的唯一id - * @param block 函数中可以配置请求参数 - */ -inline fun CoroutineScope.Options( - path: String, - tag: Any? = null, - cache: CacheMode = CacheMode.HTTP, - absolutePath: Boolean = false, - uid: Any? = coroutineContext[CoroutineExceptionHandler], - noinline block: SimpleUrlRequest.Api.() -> Unit = {} -): Deferred = async(Dispatchers.IO + SupervisorJob()) { - if (!isActive) throw CancellationException() - val realPath = if (absolutePath) path else (NetConfig.host + path) - - val request = SimpleUrlRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.OPTIONS) - .tag(tag) - .uid(uid) - .cacheKey(path) - .cacheMode(cache) - - try { - request.apply(block).perform(M::class.java) - } catch (e: SocketException) { - throw CancellationException() + fun options( + path: String, + tag: Any? = null, + block: (UrlRequest.() -> Unit)? = null + ) = UrlRequest().apply { + setPath(path) + method = Method.OPTIONS + setTag(tag) + block?.invoke(this) } -} - -/** - * 异步网络请求 - * @param path String 请求路径, 非绝对路径会加上[NetConfig.host]为前缀 - * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - * @param absolutePath 请求路径是否是绝对路径 - * @param uid 表示请求的唯一id, 和[NetCancel.cancel]中的uid一致, 一般用于指定取消网络请求的唯一id - * @param block 函数中可以配置请求参数 - */ -inline fun CoroutineScope.Trace( - path: String, - tag: Any? = null, - cache: CacheMode = CacheMode.HTTP, - absolutePath: Boolean = false, - uid: Any? = coroutineContext[CoroutineExceptionHandler], - noinline block: SimpleUrlRequest.Api.() -> Unit = {} -): Deferred = async(Dispatchers.IO + SupervisorJob()) { - if (!isActive) throw CancellationException() - - val realPath = if (absolutePath) path else (NetConfig.host + path) - - val request = SimpleUrlRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.TRACE) - .tag(tag) - .uid(uid) - .cacheKey(path) - .cacheMode(cache) - try { - request.apply(block).perform(M::class.java) - } catch (e: SocketException) { - throw CancellationException() + fun trace( + path: String, + tag: Any? = null, + block: (UrlRequest.() -> Unit)? = null + ) = UrlRequest().apply { + setPath(path) + method = Method.TRACE + setTag(tag) + block?.invoke(this) } -} -/** - * 异步网络请求 - * @param path String 请求路径, 非绝对路径会加上[NetConfig.host]为前缀 - * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - * @param absolutePath 请求路径是否是绝对路径 - * @param uid 表示请求的唯一id, 和[NetCancel.cancel]中的uid一致, 一般用于指定取消网络请求的唯一id - * @param block 函数中可以配置请求参数 - */ -inline fun CoroutineScope.Delete( - path: String, - tag: Any? = null, - cache: CacheMode = CacheMode.HTTP, - absolutePath: Boolean = false, - uid: Any? = coroutineContext[CoroutineExceptionHandler], - noinline block: SimpleBodyRequest.Api.() -> Unit = {} -): Deferred = async(Dispatchers.IO + SupervisorJob()) { - if (!isActive) throw CancellationException() - - val realPath = if (absolutePath) path else (NetConfig.host + path) - - val request = SimpleBodyRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.DELETE) - .tag(tag) - .uid(uid) - .cacheKey(path) - .cacheMode(cache) - - try { - request.apply(block).perform(M::class.java) - } catch (e: SocketException) { - throw CancellationException() + fun delete( + path: String, + tag: Any? = null, + block: (BodyRequest.() -> Unit)? = null + ) = BodyRequest().apply { + setPath(path) + method = Method.DELETE + setTag(tag) + block?.invoke(this) } -} -/** - * 异步网络请求 - * @param path String 请求路径, 非绝对路径会加上[NetConfig.host]为前缀 - * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - * @param absolutePath 请求路径是否是绝对路径 - * @param uid 表示请求的唯一id, 和[NetCancel.cancel]中的uid一致, 一般用于指定取消网络请求的唯一id - * @param block 函数中可以配置请求参数 - */ -inline fun CoroutineScope.Put( - path: String, - tag: Any? = null, - cache: CacheMode = CacheMode.HTTP, - absolutePath: Boolean = false, - uid: Any? = coroutineContext[CoroutineExceptionHandler], - noinline block: SimpleBodyRequest.Api.() -> Unit = {} -): Deferred = async(Dispatchers.IO + SupervisorJob()) { - if (!isActive) throw CancellationException() - - val realPath = if (absolutePath) path else (NetConfig.host + path) - - val request = SimpleBodyRequest.newApi( - Url.newBuilder(realPath).build(), - RequestMethod.PUT - ) - .tag(tag) - .uid(uid) - .cacheKey(path) - .cacheMode(cache) - - try { - request.apply(block).perform(M::class.java) - } catch (e: SocketException) { - throw CancellationException() + fun put( + path: String, + tag: Any? = null, + block: (BodyRequest.() -> Unit)? = null + ) = BodyRequest().apply { + setPath(path) + method = Method.PUT + setTag(tag) + block?.invoke(this) } -} - -/** - * 异步网络请求 - * @param path String 请求路径, 非绝对路径会加上[NetConfig.host]为前缀 - * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - * @param absolutePath 请求路径是否是绝对路径 - * @param uid 表示请求的唯一id, 和[NetCancel.cancel]中的uid一致, 一般用于指定取消网络请求的唯一id, 和[NetCancel.cancel]中的uid一致, 一般用于指定取消网络请求的唯一id - * @param block 函数中可以配置请求参数 - */ -inline fun CoroutineScope.Patch( - path: String, - tag: Any? = null, - cache: CacheMode = CacheMode.HTTP, - absolutePath: Boolean = false, - uid: Any? = coroutineContext[CoroutineExceptionHandler], - noinline block: SimpleBodyRequest.Api.() -> Unit = {} -): Deferred = async(Dispatchers.IO + SupervisorJob()) { - if (!isActive) throw CancellationException() - - val realPath = if (absolutePath) path else (NetConfig.host + path) - - val request = SimpleBodyRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.PATCH) - .tag(tag) - .uid(uid) - .cacheKey(path) - .cacheMode(cache) - try { - request.apply(block).perform(M::class.java) - } catch (e: SocketException) { - throw CancellationException() + fun patch( + path: String, + tag: Any? = null, + block: (BodyRequest.() -> Unit)? = null + ) = BodyRequest().apply { + setPath(path) + method = Method.PATCH + setTag(tag) + block?.invoke(this) } -} - -/** - * 用于提交URL体下载文件(默认GET请求) - * - * @param path 请求路径, 非绝对路径会加上HOST[NetConfig.host]为前缀 - * @param method 请求方式, 默认GET - * @param dir 下载文件存放目录 {默认存在android/data/packageName/cache目录} - * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - * @param absolutePath 下载链接是否是绝对路径 - * @param block 请求参数 - */ -fun CoroutineScope.Download( - path: String, - dir: String = NetConfig.app.externalCacheDir!!.absolutePath, - tag: Any? = null, - absolutePath: Boolean = false, - method: RequestMethod = RequestMethod.GET, - uid: Any? = coroutineContext[CoroutineExceptionHandler], - block: UrlDownload.Api.() -> Unit = {} -): Deferred = async(Dispatchers.IO + SupervisorJob()) { - - if (!isActive) throw CancellationException() - - if (method == RequestMethod.POST || method == RequestMethod.DELETE || method == RequestMethod.PUT || method == RequestMethod.PATCH) { - throw UnsupportedOperationException("You should use [DownloadBody] function") + // + + // + /** + * 取消全部网络请求 + */ + fun cancelAll() { + NetConfig.netCalls.forEach { it.get()?.cancel() } + NetConfig.netCalls.clear() + NetConfig.okHttpClient.dispatcher.cancelAll() } - val realPath = if (absolutePath) path else (NetConfig.host + path) - - val download = - UrlDownload.newApi(Url.newBuilder(realPath).build(), method).directory(dir).tag(tag) - .uid(uid) - - try { - download.apply(block).perform() - } catch (e: SocketException) { - throw CancellationException() + /** + * 取消指定的网络请求, Id理论上是唯一的, 所以该函数一次只能取消一个请求 + * @return 如果成功取消返回true + */ + fun cancelId(id: Any?): Boolean { + if (id == null) return false + val iterator = NetConfig.netCalls.iterator() + while (iterator.hasNext()) { + val call = iterator.next().get() ?: continue + if (id == call.request().label()?.value) { + call.cancel() + iterator.remove() + return true + } + } + return false } -} - -/** - * 用于提交请求体下载文件(默认POST请求) - * - * @param path 请求路径, 非绝对路径会加上HOST[NetConfig.host]为前缀 - * @param method 请求方式, 默认GET - * @param dir 下载文件存放目录 {默认存在android/data/packageName/cache目录} - * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - * @param absolutePath 下载链接是否是绝对路径 - * @param block 配置请求参数 - */ -fun CoroutineScope.DownloadBody( - path: String, - dir: String = NetConfig.app.externalCacheDir!!.absolutePath, - tag: Any? = null, - absolutePath: Boolean = false, - method: RequestMethod = RequestMethod.POST, - uid: Any? = coroutineContext[CoroutineExceptionHandler], - block: BodyDownload.Api.() -> Unit = {} -): Deferred = async(Dispatchers.IO + SupervisorJob()) { - if (!isActive) throw CancellationException() - - if (method == RequestMethod.GET || method == RequestMethod.HEAD || method == RequestMethod.OPTIONS || method == RequestMethod.TRACE) { - throw UnsupportedOperationException("You should use [Download] function") + /** + * 根据分组取消网络请求 + * @return 如果成功取消返回true, 无论取消个数 + */ + fun cancelGroup(group: Any?): Boolean { + if (group == null) return false + val iterator = NetConfig.netCalls.iterator() + var hasCancel = false + while (iterator.hasNext()) { + val call = iterator.next().get() ?: continue + val value = call.request().label()?.value + if (group == value) { + call.cancel() + iterator.remove() + hasCancel = true + } + } + return hasCancel } - - val realPath = if (absolutePath) path else (NetConfig.host + path) - - val download = - BodyDownload.newApi(Url.newBuilder(realPath).build(), method).directory(dir).tag(tag) - .uid(uid) - - try { - download.apply(block).perform() - } catch (e: SocketException) { - throw CancellationException() + // + + // + /** + * 监听正在请求的上传进度 + * @param id 请求的Id + * @see com.drake.net.request.BaseRequest.setId + */ + fun addUploadListener(id: Any, progressListener: ProgressListener) { + NetConfig.netCalls.forEach { + val request = it.get()?.request() ?: return@forEach + if (request.id() == id) { + request.addUploadListener(progressListener) + } + } } -} - -/** - * 异步下载图片, 图片宽高要求要么同时指定要么同时不指定 - * 要求依赖 Glide - * - * @param url 请求图片的绝对路径 - * @param with 图片宽度 - * @param height 图片高度 - */ -fun CoroutineScope.DownloadImage(url: String, with: Int = -1, height: Int = -1): Deferred = - async(Dispatchers.IO + SupervisorJob()) { - - val download = Glide.with(NetConfig.app).download(url) - val futureTarget = if (with == -1 && height == -1) { - download.submit() - } else { - download.submit(with, height) + /** + * 删除正在请求的上传进度监听器 + * @param id 请求的Id + * @see com.drake.net.request.BaseRequest.setId + */ + fun removeUploadListener(id: Any, progressListener: ProgressListener) { + NetConfig.netCalls.forEach { + val request = it.get()?.request() ?: return@forEach + if (request.id() == id) { + request.uploadListeners()?.remove(progressListener) } - - futureTarget.get() } + } -// - -// - -/** - * 同步网络请求 - * - * @param path String 请求路径, 非绝对路径会加上[NetConfig.host]为前缀 - * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - * @param absolutePath 请求路径是否是绝对路径 - * @param uid 表示请求的唯一id, 和[NetCancel.cancel]中的uid一致, 一般用于指定取消网络请求的唯一id - * @param block 函数中可以配置请求参数 - */ -inline fun syncGet( - path: String, - tag: Any? = null, - cache: CacheMode = CacheMode.HTTP, - absolutePath: Boolean = false, - uid: Any? = null, - noinline block: SimpleUrlRequest.Api.() -> Unit = {} -): M { - - val realPath = if (absolutePath) path else (NetConfig.host + path) - - val request = SimpleUrlRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.GET) - .tag(tag) - .uid(uid) - .cacheKey(path) - .cacheMode(cache) - - return request.apply(block).perform(M::class.java) -} - -/** - * 同步网络请求 - * @param path String 请求路径, 非绝对路径会加上[NetConfig.host]为前缀 - * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - * @param absolutePath 请求路径是否是绝对路径 - * @param uid 表示请求的唯一id, 和[NetCancel.cancel]中的uid一致, 一般用于指定取消网络请求的唯一id - * @param block 函数中可以配置请求参数 - */ -inline fun syncPost( - path: String, - tag: Any? = null, - cache: CacheMode = CacheMode.HTTP, - absolutePath: Boolean = false, - uid: Any? = null, - noinline block: SimpleBodyRequest.Api.() -> Unit = {} -): M { - - val realPath = if (absolutePath) path else (NetConfig.host + path) - - val request = SimpleBodyRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.POST) - .tag(tag) - .uid(uid) - .cacheKey(path) - .cacheMode(cache) - - return request.apply(block).perform(M::class.java) -} - -/** - * 同步网络请求 - * @param path String 请求路径, 非绝对路径会加上[NetConfig.host]为前缀 - * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - * @param absolutePath 请求路径是否是绝对路径 - * @param uid 表示请求的唯一id, 和[NetCancel.cancel]中的uid一致, 一般用于指定取消网络请求的唯一id - * @param block 函数中可以配置请求参数 - */ -inline fun syncHead( - path: String, - tag: Any? = null, - cache: CacheMode = CacheMode.HTTP, - absolutePath: Boolean = false, - uid: Any? = null, - noinline block: SimpleUrlRequest.Api.() -> Unit = {} -): M { - - val realPath = if (absolutePath) path else (NetConfig.host + path) - - val request = SimpleUrlRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.HEAD) - .tag(tag) - .uid(uid) - .cacheKey(path) - .cacheMode(cache) - - return request.apply(block).perform(M::class.java) -} - -/** - * 同步网络请求 - * @param path String 请求路径, 非绝对路径会加上[NetConfig.host]为前缀 - * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - * @param absolutePath 请求路径是否是绝对路径 - * @param uid 表示请求的唯一id, 和[NetCancel.cancel]中的uid一致, 一般用于指定取消网络请求的唯一id - * @param block 函数中可以配置请求参数 - */ -inline fun syncOptions( - path: String, - tag: Any? = null, - cache: CacheMode = CacheMode.HTTP, - absolutePath: Boolean = false, - uid: Any? = null, - noinline block: SimpleUrlRequest.Api.() -> Unit = {} -): M { - - val realPath = if (absolutePath) path else (NetConfig.host + path) - - val request = SimpleUrlRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.OPTIONS) - .tag(tag) - .uid(uid) - .cacheKey(path) - .cacheMode(cache) - - return request.apply(block).perform(M::class.java) -} - -/** - * 同步网络请求 - * @param path String 请求路径, 非绝对路径会加上[NetConfig.host]为前缀 - * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - * @param absolutePath 请求路径是否是绝对路径 - * @param uid 表示请求的唯一id, 和[NetCancel.cancel]中的uid一致, 一般用于指定取消网络请求的唯一id - * @param block 函数中可以配置请求参数 - */ -inline fun syncTrace( - path: String, - tag: Any? = null, - cache: CacheMode = CacheMode.HTTP, - absolutePath: Boolean = false, - uid: Any? = null, - noinline block: SimpleUrlRequest.Api.() -> Unit = {} -): M { - - val realPath = if (absolutePath) path else (NetConfig.host + path) - - val request = SimpleUrlRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.TRACE) - .tag(tag) - .uid(uid) - .cacheKey(path) - .cacheMode(cache) - - return request.apply(block).perform(M::class.java) -} - -/** - * 同步网络请求 - * @param path String 请求路径, 非绝对路径会加上[NetConfig.host]为前缀 - * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - * @param absolutePath 请求路径是否是绝对路径 - * @param uid 表示请求的唯一id, 和[NetCancel.cancel]中的uid一致, 一般用于指定取消网络请求的唯一id - * @param block 函数中可以配置请求参数 - */ -inline fun syncDelete( - path: String, - tag: Any? = null, - cache: CacheMode = CacheMode.HTTP, - absolutePath: Boolean = false, - uid: Any? = null, - noinline block: SimpleBodyRequest.Api.() -> Unit = {} -): M { - - val realPath = if (absolutePath) path else (NetConfig.host + path) - - val request = SimpleBodyRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.DELETE) - .tag(tag) - .uid(uid) - .cacheKey(path) - .cacheMode(cache) - - return request.apply(block).perform(M::class.java) -} - -/** - * 同步网络请求 - * @param path String 请求路径, 非绝对路径会加上[NetConfig.host]为前缀 - * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - * @param absolutePath 请求路径是否是绝对路径 - * @param uid 表示请求的唯一id, 和[NetCancel.cancel]中的uid一致, 一般用于指定取消网络请求的唯一id - * @param block 函数中可以配置请求参数 - */ -inline fun syncPut( - path: String, - tag: Any? = null, - cache: CacheMode = CacheMode.HTTP, - absolutePath: Boolean = false, - uid: Any? = null, - noinline block: SimpleBodyRequest.Api.() -> Unit = {} -): M { - - val realPath = if (absolutePath) path else (NetConfig.host + path) - - val request = SimpleBodyRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.PUT) - .tag(tag) - .uid(uid) - .cacheKey(path) - .cacheMode(cache) - - return request.apply(block).perform(M::class.java) -} - -/** - * 同步网络请求 - * @param path String 请求路径, 非绝对路径会加上[NetConfig.host]为前缀 - * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - * @param absolutePath 请求路径是否是绝对路径 - * @param uid 表示请求的唯一id, 和[NetCancel.cancel]中的uid一致, 一般用于指定取消网络请求的唯一id - * @param block 函数中可以配置请求参数 - */ -inline fun syncPatch( - path: String, - tag: Any? = null, - cache: CacheMode = CacheMode.HTTP, - absolutePath: Boolean = false, - uid: Any? = null, - noinline block: SimpleBodyRequest.Api.() -> Unit = {} -): M { - - val realPath = if (absolutePath) path else (NetConfig.host + path) - - val request = SimpleBodyRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.PATCH) - .tag(tag) - .uid(uid) - .cacheKey(path) - .cacheMode(cache) - - return request.apply(block).perform(M::class.java) -} - -/** - * 同步文件下载, 默认Get请求 - * - * @param path String 请求路径, 非绝对路径会加上[NetConfig.host]为前缀 - * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - * @param absolutePath 请求路径是否是绝对路径 - * @param uid 表示请求的唯一id, 和[NetCancel.cancel]中的uid一致, 一般用于指定取消网络请求的唯一id - * @param block 函数中可以配置请求参数 - */ -fun syncDownload( - path: String, - dir: String = NetConfig.app.externalCacheDir!!.absolutePath, - tag: Any? = null, - absolutePath: Boolean = false, - method: RequestMethod = RequestMethod.GET, - uid: Any? = null, - block: UrlDownload.Api.() -> Unit = {} -): String { - if (method == RequestMethod.POST || method == RequestMethod.DELETE || method == RequestMethod.PUT || method == RequestMethod.PATCH) { - throw UnsupportedOperationException("You should use [syncDownloadBody] function") + /** + * 监听正在请求的下载进度 + * @param id 请求的Id + * @see com.drake.net.request.BaseRequest.setId + */ + fun addDownloadListener(id: Any, progressListener: ProgressListener) { + NetConfig.netCalls.forEach { + val request = it.get()?.request() ?: return@forEach + if (request.id() == id) { + request.addDownloadListener(progressListener) + } + } } - val realPath = if (absolutePath) path else (NetConfig.host + path) - val download = - UrlDownload.newApi(Url.newBuilder(realPath).build(), method).directory(dir).tag(tag) - .uid(uid) - return download.apply(block).perform() -} -/** - * 同步文件下载, 允许提交请求体方式, 默认Post请求 - * - * @param path String 请求路径, 非绝对路径会加上[NetConfig.host]为前缀 - * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断 - * @param absolutePath 请求路径是否是绝对路径 - * @param uid 表示请求的唯一id, 和[NetCancel.cancel]中的uid一致, 一般用于指定取消网络请求的唯一id - * @param block 函数中可以配置请求参数 - */ -fun syncDownloadBody( - path: String, - dir: String = NetConfig.app.externalCacheDir!!.absolutePath, - tag: Any? = null, - absolutePath: Boolean = false, - method: RequestMethod = RequestMethod.GET, - uid: Any? = null, - block: BodyDownload.Api.() -> Unit = {} -): String { - if (method == RequestMethod.GET || method == RequestMethod.HEAD || method == RequestMethod.OPTIONS || method == RequestMethod.TRACE) { - throw UnsupportedOperationException("You should use [syncDownload] function") + /** + * 删除正在请求的下载进度监听器 + * + * @param id 请求的Id + * @see com.drake.net.request.BaseRequest.setId + */ + fun removeDownloadListener(id: Any, progressListener: ProgressListener) { + NetConfig.netCalls.forEach { + val request = it.get()?.request() ?: return@forEach + if (request.id() == id) { + request.downloadListeners()?.remove(progressListener) + } + } } - val realPath = if (absolutePath) path else (NetConfig.host + path) - val download = - BodyDownload.newApi(Url.newBuilder(realPath).build(), method).directory(dir).tag(tag) - .uid(uid) - return download.apply(block).perform() -} + // -/** - * 同步下载图片, 图片宽高要求要么同时指定要么同时不指定 - * 要求依赖 Glide - * - * @param url 请求图片的绝对路径 - * @param with 图片宽度 - * @param height 图片高度 - */ -fun Context.syncDownloadImage(url: String, with: Int = 0, height: Int = 0): File { + // + /** + * 指定Id的请求 + */ + fun requestById(id: Any): Request? { + NetConfig.netCalls.forEach { + val request = it.get()?.request() ?: return@forEach + if (request.id() == id) return request + } + return null + } - Glide.with(this).downloadOnly() - val download = Glide.with(this).download(url) - val futureTarget = if (with == 0 && height == 0) { - download.submit() - } else { - download.submit(with, height) + /** + * 指定分组的请求 + */ + fun requestByGroup(group: Any): ArrayList { + val requests = ArrayList() + NetConfig.netCalls.forEach { + val request = it?.get()?.request() ?: return@forEach + if (request.group() == group) requests.add(request) + } + return requests } - return futureTarget.get() + // } -// - - - - diff --git a/net/src/main/java/com/drake/net/NetConfig.kt b/net/src/main/java/com/drake/net/NetConfig.kt index 56c305e84..4ba080e64 100644 --- a/net/src/main/java/com/drake/net/NetConfig.kt +++ b/net/src/main/java/com/drake/net/NetConfig.kt @@ -16,6 +16,7 @@ package com.drake.net +import android.annotation.SuppressLint import android.app.Application import android.app.Dialog import android.app.ProgressDialog @@ -26,18 +27,16 @@ import com.drake.net.NetConfig.host import com.drake.net.NetConfig.onDialog import com.drake.net.NetConfig.onError import com.drake.net.NetConfig.onStateError -import com.drake.net.error.RequestParamsException -import com.drake.net.error.ResponseException -import com.drake.net.error.ServerResponseException +import com.drake.net.convert.NetConverter +import com.drake.net.exception.* +import com.drake.net.interceptor.RequestInterceptor import com.drake.net.scope.DialogCoroutineScope import com.drake.tooltip.toast -import com.yanzhenjie.kalle.Kalle -import com.yanzhenjie.kalle.KalleConfig -import com.yanzhenjie.kalle.connect.RealTimeNetwork -import com.yanzhenjie.kalle.connect.http.RedirectInterceptor -import com.yanzhenjie.kalle.exception.* -import com.yanzhenjie.kalle.simple.cache.DiskCacheStore -import java.util.concurrent.ExecutionException +import okhttp3.Call +import okhttp3.OkHttpClient +import java.lang.ref.WeakReference +import java.net.UnknownHostException +import java.util.concurrent.* /** @@ -49,11 +48,17 @@ import java.util.concurrent.ExecutionException * @property onError 全局错误处理 * @property onStateError 全局缺省页错误处理 */ +@SuppressLint("StaticFieldLeak") object NetConfig { lateinit var app: Application + lateinit var okHttpClient: OkHttpClient + var host: String = "" var logEnabled = true + var netCalls: ConcurrentLinkedQueue> = ConcurrentLinkedQueue() + var converter: NetConverter = NetConverter.DEFAULT + var requestInterceptor: RequestInterceptor? = null var onDialog: DialogCoroutineScope.(FragmentActivity) -> Dialog = { val progress = ProgressDialog(activity) @@ -62,36 +67,30 @@ object NetConfig { } var onError: Throwable.() -> Unit = onError@{ - if (logEnabled) printStackTrace() - if (!this@NetConfig::app.isInitialized) return@onError val message = when (this) { - is NetworkError -> app.getString(R.string.net_network_error) - is URLError -> app.getString(R.string.net_url_error) - is HostError -> app.getString(R.string.net_host_error) - is ConnectTimeoutError -> app.getString(R.string.net_connect_timeout_error) - is ReadTimeoutError -> app.getString(R.string.net_read_timeout_error) - is DownloadError -> app.getString(R.string.net_download_error) - is NoCacheError -> app.getString(R.string.net_no_cache_error) - is ParseError -> app.getString(R.string.net_parse_error) + is UnknownHostException -> app.getString(R.string.net_host_error) + is URLParseException -> app.getString(R.string.net_url_error) + is NetConnectException -> app.getString(R.string.net_network_error) + is NetSocketTimeoutException -> app.getString(R.string.net_connect_timeout_error, message) + is DownloadFileException -> app.getString(R.string.net_download_error) + is ConvertException -> app.getString(R.string.net_parse_error) is RequestParamsException -> app.getString(R.string.net_request_error) is ServerResponseException -> app.getString(R.string.net_server_error) - is ExecutionException -> app.getString(R.string.net_image_error) is NullPointerException -> app.getString(R.string.net_null_error) - is ConnectException -> app.getString(R.string.net_connect_exception) - is WriteException -> app.getString(R.string.net_write_exception) - is ReadException -> app.getString(R.string.net_read_exception) - is ResponseException -> msg + is NoCacheException -> app.getString(R.string.net_no_cache_error) + is ResponseException -> message is NetException -> app.getString(R.string.net_error) else -> app.getString(R.string.net_other_error) } + if (logEnabled) printStackTrace() app.toast(message) } var onStateError: Throwable.(view: View) -> Unit = { when (this) { - is ParseError, + is ConvertException, is RequestParamsException, is ResponseException, is NullPointerException -> onError(this) @@ -100,73 +99,3 @@ object NetConfig { } } -/** - * 初始化框架 - * @param host 请求url的主机名 - * @param config 进行配置网络请求 - * - * 如果想要自动解析数据模型请配置转换器, 可以继承或者参考默认转换器 - * - * @see com.drake.net.convert.DefaultConvert - */ -fun Application.initNet(host: String, config: KalleConfig.Builder.() -> Unit = {}) { - NetConfig.host = host - app = this - val builder = KalleConfig.newBuilder() - builder.apply { - network(RealTimeNetwork(this@initNet)) - addInterceptor(RedirectInterceptor()) - config() - } - Kalle.setConfig(builder.build()) -} - - -/** - * 设置全局错误处理 - * - * @see NetConfig.onError - */ -fun KalleConfig.Builder.onError(block: Throwable.() -> Unit) { - NetConfig.onError = block -} - -/** - * 设置缺省页的全局错误处理 - * - * 如果不设置默认只有 解析数据错误 | 后台自定义错误 会显示吐司 - * @see NetConfig.onStateError - */ -fun KalleConfig.Builder.onStateError(block: Throwable.(view: View) -> Unit) { - NetConfig.onStateError = block -} - -/** - * 设置使用DialogObserver默认弹出的加载对话框 - * 默认使用系统自带的ProgressDialog - */ -fun KalleConfig.Builder.onDialog(block: (DialogCoroutineScope.(context: FragmentActivity) -> Dialog)) { - NetConfig.onDialog = block -} - -var KalleConfig.Builder.logEnabled: Boolean - get() = NetConfig.logEnabled - set(value) { - NetConfig.logEnabled = value - } - -/** - * 开启缓存 - * @param path 缓存数据库路径 - * @param password 缓存数据库密码 - */ -fun KalleConfig.Builder.cacheEnabled( - path: String = app.cacheDir.absolutePath, - password: String = "cache" -) { - val cacheStore = DiskCacheStore.newBuilder(path) - .password(password) - .build() - cacheStore(cacheStore) -} - diff --git a/net/src/main/java/com/drake/net/NetCoroutine.kt b/net/src/main/java/com/drake/net/NetCoroutine.kt new file mode 100644 index 000000000..bcdd51adf --- /dev/null +++ b/net/src/main/java/com/drake/net/NetCoroutine.kt @@ -0,0 +1,141 @@ +@file:Suppress("FunctionName") + +package com.drake.net + +import com.drake.net.request.BodyRequest +import com.drake.net.request.Method +import com.drake.net.request.UrlRequest +import kotlinx.coroutines.* + + +// + + +/** + * 异步网络请求 + * + * @param path 请求路径, 如果其不包含http/https则会自动拼接[NetConfig.host] + * @param tag 可以传递对象给Request, 一般用于在拦截器/转换器中进行针对某个接口行为判断 + * @param block 函数中可以配置请求参数 + */ +inline fun CoroutineScope.Get( + path: String, + tag: Any? = null, + noinline block: (UrlRequest.() -> Unit)? = null +): Deferred = async(Dispatchers.IO + SupervisorJob()) { + if (!isActive) throw CancellationException() + UrlRequest().apply { + setPath(path) + method = Method.GET + setGroup(coroutineContext[CoroutineExceptionHandler]) + setTag(tag) + block?.invoke(this) + }.execute() +} + +inline fun CoroutineScope.Post( + path: String, + tag: Any? = null, + noinline block: (BodyRequest.() -> Unit)? = null +): Deferred = async(Dispatchers.IO + SupervisorJob()) { + if (!isActive) throw CancellationException() + BodyRequest().apply { + setPath(path) + method = Method.POST + setGroup(coroutineContext[CoroutineExceptionHandler]) + setTag(tag) + block?.invoke(this) + }.execute() +} + +inline fun CoroutineScope.Head( + path: String, + tag: Any? = null, + noinline block: (UrlRequest.() -> Unit)? = null +): Deferred = async(Dispatchers.IO + SupervisorJob()) { + if (!isActive) throw CancellationException() + UrlRequest().apply { + setPath(path) + method = Method.HEAD + setGroup(coroutineContext[CoroutineExceptionHandler]) + setTag(tag) + block?.invoke(this) + }.execute() +} + +inline fun CoroutineScope.Options( + path: String, + tag: Any? = null, + noinline block: (UrlRequest.() -> Unit)? = null +): Deferred = async(Dispatchers.IO + SupervisorJob()) { + if (!isActive) throw CancellationException() + UrlRequest().apply { + setPath(path) + method = Method.OPTIONS + setGroup(coroutineContext[CoroutineExceptionHandler]) + setTag(tag) + block?.invoke(this) + }.execute() +} + +inline fun CoroutineScope.Trace( + path: String, + tag: Any? = null, + noinline block: (UrlRequest.() -> Unit)? = null +): Deferred = async(Dispatchers.IO + SupervisorJob()) { + if (!isActive) throw CancellationException() + UrlRequest().apply { + setPath(path) + method = Method.TRACE + setGroup(coroutineContext[CoroutineExceptionHandler]) + setTag(tag) + block?.invoke(this) + }.execute() +} + +inline fun CoroutineScope.Delete( + path: String, + tag: Any? = null, + noinline block: (BodyRequest.() -> Unit)? = null +): Deferred = async(Dispatchers.IO + SupervisorJob()) { + if (!isActive) throw CancellationException() + BodyRequest().apply { + setPath(path) + method = Method.DELETE + setGroup(coroutineContext[CoroutineExceptionHandler]) + setTag(tag) + block?.invoke(this) + }.execute() +} + +inline fun CoroutineScope.Put( + path: String, + tag: Any? = null, + noinline block: (BodyRequest.() -> Unit)? = null +): Deferred = async(Dispatchers.IO + SupervisorJob()) { + if (!isActive) throw CancellationException() + BodyRequest().apply { + setPath(path) + method = Method.PUT + setGroup(coroutineContext[CoroutineExceptionHandler]) + setTag(tag) + block?.invoke(this) + }.execute() +} + +inline fun CoroutineScope.Patch( + path: String, + tag: Any? = null, + noinline block: (BodyRequest.() -> Unit)? = null +): Deferred = async(Dispatchers.IO + SupervisorJob()) { + if (!isActive) throw CancellationException() + BodyRequest().apply { + setPath(path) + method = Method.PATCH + setGroup(coroutineContext[CoroutineExceptionHandler]) + setTag(tag) + block?.invoke(this) + }.execute() +} + +// \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/body/BodyExtension.kt b/net/src/main/java/com/drake/net/body/BodyExtension.kt new file mode 100644 index 000000000..05d0cd542 --- /dev/null +++ b/net/src/main/java/com/drake/net/body/BodyExtension.kt @@ -0,0 +1,55 @@ +package com.drake.net.body + +import com.drake.net.request.downloadListeners +import com.drake.net.request.uploadListeners +import okhttp3.Request +import okhttp3.RequestBody +import okhttp3.ResponseBody +import okhttp3.ResponseBody.Companion.asResponseBody +import okio.Buffer + +fun RequestBody.toNetRequestBody(request: Request) = + run { NetRequestBody(this, request.uploadListeners()) } + +fun ResponseBody.toNetResponseBody(request: Request, complete: (() -> Unit)? = null) = + run { NetResponseBody(this, request.downloadListeners(), complete) } + +/** + * 复制一段指定长度的字符串内容 + * @param byteCount 复制的字节长度. 如果-1则返回完整的字符串内容 + */ +@JvmName("peekString") +fun RequestBody?.peekString(byteCount: Long = 1024 * 1024, discard: Boolean = false): String? { + return when { + this == null -> return null + this is NetRequestBody -> peekString(byteCount, discard) + else -> { + val buffer = Buffer() + writeTo(buffer) + if (discard && buffer.size > byteCount) return "" + val byteCountFinal = if (byteCount < 0) buffer.size else minOf(buffer.size, byteCount) + buffer.readUtf8(byteCountFinal) + } + } +} + +/** + * 复制一段指定长度的字符串内容 + * @param byteCount 复制的字节长度. 如果-1则返回完整的字符串内容 + */ +fun ResponseBody?.peekString(byteCount: Long = 1024 * 1024 * 4, discard: Boolean = false): String? { + return when { + this == null -> return null + this is NetResponseBody -> peekString(byteCount, discard) + else -> { + val peeked = source().peek() + val buffer = Buffer() + peeked.request(byteCount) + val byteCountFinal = + if (byteCount < 0) peeked.buffer.size else minOf(byteCount, peeked.buffer.size) + buffer.write(peeked, byteCountFinal) + if (discard && buffer.size > byteCount) return "" + buffer.asResponseBody(contentType(), byteCountFinal).string() + } + } +} \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/body/NetRequestBody.kt b/net/src/main/java/com/drake/net/body/NetRequestBody.kt new file mode 100644 index 000000000..81fd12a3c --- /dev/null +++ b/net/src/main/java/com/drake/net/body/NetRequestBody.kt @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2018 Drake, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.drake.net.body + +import android.os.SystemClock +import com.drake.net.component.Progress +import com.drake.net.interfaces.ProgressListener +import okhttp3.MediaType +import okhttp3.RequestBody +import okio.* +import java.io.IOException +import java.util.concurrent.ConcurrentLinkedQueue + +class NetRequestBody( + private val requestBody: RequestBody, + private val progressListeners: ConcurrentLinkedQueue? = null +) : RequestBody() { + + private val progress: Progress by lazy { Progress() } + private var bufferedSink: BufferedSink? = null + val contentLength by lazy { requestBody.contentLength() } + + override fun contentType(): MediaType? { + return requestBody.contentType() + } + + @Throws(IOException::class) + override fun contentLength(): Long { + return contentLength + } + + @Throws(IOException::class) + override fun writeTo(sink: BufferedSink) { + if (bufferedSink == null) bufferedSink = sink.progress().buffer() + bufferedSink?.let { + requestBody.writeTo(it) + it.flush() + } + } + + /** + * 复制一段指定长度的字符串内容 + * @param byteCount 复制的字节长度. 如果-1则返回完整的字符串内容 + * @param discard 如果实际长度大于指定长度则直接返回null. 可以保证数据完整性 + */ + fun peekString(byteCount: Long = 1024 * 1024, discard: Boolean = false): String { + val buffer = Buffer() + requestBody.writeTo(buffer) + if (discard && buffer.size > byteCount) return "" + val byteCountFinal = if (byteCount < 0) buffer.size else minOf(buffer.size, byteCount) + return buffer.readUtf8(byteCountFinal) + } + + private fun Sink.progress() = object : ForwardingSink(this) { + var writeByteCount = 0L + + @Throws(IOException::class) + override fun write(source: Buffer, byteCount: Long) { + super.write(source, byteCount) + writeByteCount += byteCount + if (progressListeners != null) { + val currentElapsedTime = SystemClock.elapsedRealtime() + progressListeners.forEach { progressListener -> + progressListener.intervalByteCount += byteCount + val currentInterval = currentElapsedTime - progressListener.elapsedTime + if (currentInterval >= progressListener.interval || writeByteCount == contentLength) { + progressListener.onProgress( + progress.apply { + currentByteCount = writeByteCount + totalByteCount = contentLength + intervalByteCount = progressListener.intervalByteCount + intervalTime = currentInterval + } + ) + progressListener.elapsedTime = currentElapsedTime + progressListener.intervalByteCount = 0L + } + } + } + } + } +} \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/body/NetResponseBody.kt b/net/src/main/java/com/drake/net/body/NetResponseBody.kt new file mode 100644 index 000000000..bc02dddb6 --- /dev/null +++ b/net/src/main/java/com/drake/net/body/NetResponseBody.kt @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2018 Drake, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.drake.net.body + +import android.os.SystemClock +import com.drake.net.component.Progress +import com.drake.net.interfaces.ProgressListener +import okhttp3.MediaType +import okhttp3.ResponseBody +import okio.* +import java.io.IOException +import java.util.concurrent.ConcurrentLinkedQueue + +class NetResponseBody( + private val responseBody: ResponseBody, + private val progressListeners: ConcurrentLinkedQueue? = null, + private val complete: (() -> Unit)? = null +) : ResponseBody() { + + private val progress: Progress by lazy { Progress() } + private val bufferedSource by lazy { responseBody.source().progress().buffer() } + private val contentLength by lazy { responseBody.contentLength() } + + override fun contentType(): MediaType? { + return responseBody.contentType() + } + + override fun contentLength(): Long { + return contentLength + } + + override fun source(): BufferedSource { + return bufferedSource + } + + /** + * 复制一段指定长度的字符串内容 + * @param byteCount 复制的字节长度. 如果-1则返回完整的字符串内容 + * @param discard 如果实际长度大于指定长度则直接返回null. 可以保证数据完整性 + */ + fun peekString(byteCount: Long = 1024 * 1024 * 4, discard: Boolean = false): String { + val peeked = responseBody.source().peek() + val buffer = Buffer() + peeked.request(byteCount) + if (discard && buffer.size > byteCount) return "" + val byteCountFinal = + if (byteCount < 0) peeked.buffer.size else minOf(byteCount, peeked.buffer.size) + buffer.write(peeked, byteCountFinal) + return buffer.readUtf8(byteCountFinal) + } + + private fun Source.progress() = object : ForwardingSource(this) { + var readByteCount: Long = 0 + + @Throws(IOException::class) + override fun read(sink: Buffer, byteCount: Long): Long { + try { + val bytesRead = super.read(sink, byteCount) + readByteCount += if (bytesRead != -1L) bytesRead else 0 + if (progressListeners != null) { + val currentElapsedTime = SystemClock.elapsedRealtime() + progressListeners.forEach { progressListener -> + progressListener.intervalByteCount += if (bytesRead != -1L) bytesRead else 0 + val currentInterval = currentElapsedTime - progressListener.elapsedTime + if (currentInterval >= progressListener.interval || readByteCount == contentLength) { + progressListener.onProgress( + progress.apply { + currentByteCount = readByteCount + totalByteCount = contentLength + intervalByteCount = progressListener.intervalByteCount + intervalTime = currentInterval + } + ) + progressListener.elapsedTime = currentElapsedTime + progressListener.intervalByteCount = 0L + } + } + } + if (bytesRead == -1L) complete?.invoke() + return bytesRead + } catch (e: Exception) { + complete?.invoke() + throw e + } + } + } +} \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/component/InitContentProvider.kt b/net/src/main/java/com/drake/net/component/InitContentProvider.kt new file mode 100644 index 000000000..ffbb10503 --- /dev/null +++ b/net/src/main/java/com/drake/net/component/InitContentProvider.kt @@ -0,0 +1,46 @@ +package com.drake.net.component + +import android.app.Application +import android.content.ContentProvider +import android.content.ContentValues +import android.database.Cursor +import android.net.Uri +import com.drake.net.NetConfig + +/** + * 用于初始化[NetConfig.app] + */ +class InitContentProvider : ContentProvider() { + + override fun onCreate(): Boolean { + val application = context?.applicationContext as? Application ?: return false + NetConfig.app = application + return false + } + + override fun delete(uri: Uri, selection: String?, selectionArgs: Array?): Int { + return 0 + } + + override fun getType(uri: Uri): String? { + return null + } + + override fun insert(uri: Uri, values: ContentValues?): Uri? { + return null + } + + override fun query( + uri: Uri, projection: Array?, selection: String?, + selectionArgs: Array?, sortOrder: String? + ): Cursor? { + return null + } + + override fun update( + uri: Uri, values: ContentValues?, selection: String?, + selectionArgs: Array? + ): Int { + return 0 + } +} \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/component/Progress.kt b/net/src/main/java/com/drake/net/component/Progress.kt new file mode 100644 index 000000000..fbae7b344 --- /dev/null +++ b/net/src/main/java/com/drake/net/component/Progress.kt @@ -0,0 +1,131 @@ +@file:Suppress("unused", "MemberVisibilityCanBePrivate", "NAME_SHADOWING", "RedundantSetter") + +package com.drake.net.component + +import android.os.SystemClock +import android.text.format.DateUtils +import android.text.format.Formatter +import com.drake.net.NetConfig + +/** + * @property currentByteCount 当前已经完成的字节数 + * @property totalByteCount 当前已经完成的字节数 + * @property intervalByteCount 进度间隔时间内完成的字节数 + * @property intervalTime 距离上次进度变化间隔时间 + * @property startElapsedRealtime 开始下载的时间 + */ +data class Progress( + var currentByteCount: Long = 0, + var totalByteCount: Long = 0, + var intervalByteCount: Long = 0, + var intervalTime: Long = 0, + val startElapsedRealtime: Long = SystemClock.elapsedRealtime() +) { + + /** + * 文件全部大小 + * 根据字节数自动显示内存单位, 例如 19MB 或者 27KB + */ + fun totalSize(): String { + val totalBytes = if (totalByteCount <= 0) 0 else totalByteCount + return Formatter.formatFileSize(NetConfig.app, totalBytes) + } + + /** + * 已完成文件大小 + * 根据字节数自动显示内存单位, 例如 19MB 或者 27KB + */ + fun currentSize(): String { + return Formatter.formatFileSize(NetConfig.app, currentByteCount) + } + + /** + * 剩余大小 + * 根据字节数自动显示内存单位, 例如 19MB 或者 27KB + */ + fun remainSize(): String { + val remain = if (totalByteCount <= 0) 0 else totalByteCount - currentByteCount + return Formatter.formatFileSize(NetConfig.app, remain) + } + + /** + * 每秒下载速度 + * 根据字节数自动显示内存单位, 例如 19MB 或者 27KB + */ + fun speedSize(): String { + return Formatter.formatFileSize(NetConfig.app, speedBytes) + } + + + /** + * 每秒下载速度, 字节单位 + */ + var speedBytes = 0L + get() { + return if (intervalTime <= 0L || intervalByteCount <= 0) { + field + } else { + field = intervalByteCount * 1000 / intervalTime + field + } + } + + /** + * 请求或者响应的进度, 值范围在0-100 + */ + fun progress(): Int { + return when { + currentByteCount == totalByteCount -> 100 + totalByteCount <= 0 -> 0 + else -> (currentByteCount * 100 / totalByteCount).toInt() + } + } + + /** + * 是否完成 + */ + fun finish(): Boolean { + return currentByteCount == totalByteCount || totalByteCount <= 0 + } + + /** + * 已使用时间 + */ + fun useTime(): String { + return DateUtils.formatElapsedTime((SystemClock.elapsedRealtime() - startElapsedRealtime) / 1000) + } + + /** + * 已使用时间 + * @return 秒 + */ + fun useTimeSeconds(): Long { + return (SystemClock.elapsedRealtime() - startElapsedRealtime) / 1000 + } + + /** + * 剩余时间 + */ + fun remainTime(): String { + val speedBytes = speedBytes + val remainSeconds = if (totalByteCount <= 0 || speedBytes <= 0L) { + 0 + } else { + (totalByteCount - currentByteCount) / speedBytes + } + return DateUtils.formatElapsedTime(remainSeconds) + } + + /** + * 剩余时间 + * @return 秒 + */ + fun remainTimeSeconds(): Long { + val speedBytes = this.speedBytes + return if (totalByteCount <= 0 || speedBytes <= 0L) { + 0 + } else { + (totalByteCount - currentByteCount) / speedBytes + } + } +} \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/convert/DefaultConvert.kt b/net/src/main/java/com/drake/net/convert/DefaultConvert.kt deleted file mode 100644 index 0f4a9fdd5..000000000 --- a/net/src/main/java/com/drake/net/convert/DefaultConvert.kt +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@file:Suppress("MemberVisibilityCanBePrivate") - -package com.drake.net.convert - -import com.drake.net.error.RequestParamsException -import com.drake.net.error.ResponseException -import com.drake.net.error.ServerResponseException -import com.yanzhenjie.kalle.Request -import com.yanzhenjie.kalle.Response -import com.yanzhenjie.kalle.exception.ParseError -import com.yanzhenjie.kalle.simple.Converter -import org.json.JSONObject -import java.lang.reflect.Type - - -/** - * 默认的转换器实现, 如果不满足需求建议将该文件复制到项目中修改 - * - * @param success 后端定义为成功状态的错误码值 - * @param code 错误码在JSON中的字段名 - * @param message 错误信息在JSON中的字段名 - */ -@Suppress("UNCHECKED_CAST") -abstract class DefaultConvert( - val success: String = "0", - val code: String = "code", - val message: String = "msg" -) : Converter { - - override fun convert( - succeed: Type, - request: Request, - response: Response, - cache: Boolean - ): S? { - val body = response.body().string() - response.log = body // 日志记录响应信息 - val code = response.code() - when { - code in 200..299 -> { // 请求成功 - if (succeed === String::class.java) return body as S - val jsonObject = JSONObject(body) // 获取JSON中后端定义的错误码和错误信息 - if (jsonObject.getString(this.code) == success) { // 对比后端自定义错误码 - return body.parseBody(succeed) - } else { // 错误码匹配失败, 开始写入错误异常 - throw ResponseException(code, jsonObject.getString(message), request, body) - } - } - code in 400..499 -> throw RequestParamsException(code, request) // 请求参数错误 - code >= 500 -> throw ServerResponseException(code, request) // 服务器异常错误 - else -> throw ParseError(request) - } - } - - /** - * 解析字符串数据 - * 一般用于解析JSON - * @param succeed 请求函数定义的泛型, 例如一般的Moshi/Gson解析数据需要使用 - * @receiver 原始字符串 - */ - abstract fun String.parseBody(succeed: Type): S? -} diff --git a/net/src/main/java/com/drake/net/convert/JSONConvert.kt b/net/src/main/java/com/drake/net/convert/JSONConvert.kt new file mode 100644 index 000000000..43b07fdd7 --- /dev/null +++ b/net/src/main/java/com/drake/net/convert/JSONConvert.kt @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2018 Drake, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@file:Suppress("MemberVisibilityCanBePrivate", "UNCHECKED_CAST") + +package com.drake.net.convert + +import com.drake.net.NetConfig +import com.drake.net.exception.ConvertException +import com.drake.net.exception.RequestParamsException +import com.drake.net.exception.ResponseException +import com.drake.net.exception.ServerResponseException +import okhttp3.Response +import org.json.JSONObject +import java.lang.reflect.Type + + +/** + * 常见的JSON转换器实现, 如果不满意继承实现自定义的业务逻辑 + * + * @param success 后端定义为成功状态的错误码值 + * @param code 错误码在JSON中的字段名 + * @param message 错误信息在JSON中的字段名 + */ +abstract class JSONConvert( + val success: String = "0", + val code: String = "code", + val message: String = "msg" +) : NetConverter { + + override fun onConvert(succeed: Type, response: Response): R? { + try { + return NetConverter.DEFAULT.onConvert(succeed, response) + } catch (e: ConvertException) { + val code = response.code + when { + code in 200..299 -> { // 请求成功 + val body = response.body?.string() ?: return null + if (succeed === String::class.java) return body as R + val jsonObject = JSONObject(body) // 获取JSON中后端定义的错误码和错误信息 + if (jsonObject.getString(this.code) == success) { // 对比后端自定义错误码 + return body.parseBody(succeed) + } else { // 错误码匹配失败, 开始写入错误异常 + throw ResponseException(response, jsonObject.optString(message, NetConfig.app.getString(com.drake.net.R.string.no_error_message))) + } + } + code in 400..499 -> throw RequestParamsException(response) // 请求参数错误 + code >= 500 -> throw ServerResponseException(response) // 服务器异常错误 + else -> throw ConvertException(response) + } + } + } + + /** + * 反序列化JSON + * + * @param succeed JSON对象的类型 + * @receiver 原始字符串 + */ + abstract fun String.parseBody(succeed: Type): S? +} diff --git a/net/src/main/java/com/drake/net/convert/NetConverter.kt b/net/src/main/java/com/drake/net/convert/NetConverter.kt new file mode 100644 index 000000000..9e3a6fd6a --- /dev/null +++ b/net/src/main/java/com/drake/net/convert/NetConverter.kt @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2018 Drake, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.drake.net.convert + +import com.drake.net.exception.ConvertException +import com.drake.net.response.file +import okhttp3.Response +import okio.ByteString +import java.io.File +import java.lang.reflect.Type + +@Suppress("UNCHECKED_CAST") +interface NetConverter { + + @Throws(Exception::class) + fun onConvert(succeed: Type, response: Response): R? + + companion object { + /** + * 返回数据为字符串内容 + */ + @JvmField + val DEFAULT = object : NetConverter { + + override fun onConvert( + succeed: Type, + response: Response + ): R? { + return when (succeed) { + String::class.java -> response.body?.string() as R + ByteString::class.java -> response.body?.byteString() as R + ByteArray::class.java -> response.body?.bytes() as R + Response::class.java -> response as R + File::class.java -> response.file() as R + else -> throw ConvertException(response, "The default converter does not support this type") + } + } + } + + } +} \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/error/ResponseException.kt b/net/src/main/java/com/drake/net/error/ResponseException.kt deleted file mode 100644 index 5de0ce046..000000000 --- a/net/src/main/java/com/drake/net/error/ResponseException.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@file:Suppress("MemberVisibilityCanBePrivate") - -package com.drake.net.error - -import com.yanzhenjie.kalle.Request -import com.yanzhenjie.kalle.exception.NetException - -/** - * 对应网络请求后台定义的错误信息 - * @param msg 网络请求错误信息 - * @param code 网络请求错误码 - * @param tag 应对错误码判断为错时但是后端又返回了需要使用的数据(建议后端修改). 一般在Convert中设置数据 - */ -class ResponseException( - val code: Int, - val msg: String, - request: Request, - val tag: Any? = null -) : NetException(request, "$code $msg") \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/error/ServerResponseException.kt b/net/src/main/java/com/drake/net/error/ServerResponseException.kt deleted file mode 100644 index 1e5a464d6..000000000 --- a/net/src/main/java/com/drake/net/error/ServerResponseException.kt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.drake.net.error - -import com.yanzhenjie.kalle.Request -import com.yanzhenjie.kalle.exception.NetException - -/** - * 500 - */ -class ServerResponseException( - val code: Int, - request: Request -) : NetException(request, code.toString()) \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/exception/ParseError.kt b/net/src/main/java/com/drake/net/exception/ConvertException.kt similarity index 71% rename from kalle/src/main/java/com/yanzhenjie/kalle/exception/ParseError.kt rename to net/src/main/java/com/drake/net/exception/ConvertException.kt index 069e989e4..544a9cd14 100644 --- a/kalle/src/main/java/com/yanzhenjie/kalle/exception/ParseError.kt +++ b/net/src/main/java/com/drake/net/exception/ConvertException.kt @@ -13,13 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.yanzhenjie.kalle.exception +package com.drake.net.exception -import com.yanzhenjie.kalle.Request +import okhttp3.Response -class ParseError( - request: Request, - message: String = "An exception occurred while parsing the data", +/** + * 转换数据异常 + */ +class ConvertException( + val response: Response, + info: String = "An exception occurred while converting the data", cause: Throwable? = null -) : NetException(request, message, cause) \ No newline at end of file +) : NetException(response.request, info, cause) \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/exception/DownloadFileException.kt b/net/src/main/java/com/drake/net/exception/DownloadFileException.kt new file mode 100644 index 000000000..5e3664fb6 --- /dev/null +++ b/net/src/main/java/com/drake/net/exception/DownloadFileException.kt @@ -0,0 +1,12 @@ +package com.drake.net.exception + +import okhttp3.Response + +/** + * 下载文件异常 + */ +class DownloadFileException( + response: Response, + info: String? = null, + cause: Throwable? = null +) : NetException(response.request, info, cause) \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/error/NetCancellationException.kt b/net/src/main/java/com/drake/net/exception/NetCancellationException.kt similarity index 88% rename from net/src/main/java/com/drake/net/error/NetCancellationException.kt rename to net/src/main/java/com/drake/net/exception/NetCancellationException.kt index 21a63075d..c19a931c4 100644 --- a/net/src/main/java/com/drake/net/error/NetCancellationException.kt +++ b/net/src/main/java/com/drake/net/exception/NetCancellationException.kt @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.drake.net.error +package com.drake.net.exception -import com.yanzhenjie.kalle.NetCancel +import com.drake.net.Net import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.CoroutineScope import java.util.concurrent.CancellationException @@ -27,7 +27,7 @@ import java.util.concurrent.CancellationException class NetCancellationException(coroutineScope: CoroutineScope, message: String? = null) : CancellationException(message) { init { - NetCancel.cancel(coroutineScope.coroutineContext[CoroutineExceptionHandler]) + Net.cancelGroup(coroutineScope.coroutineContext[CoroutineExceptionHandler]) } } diff --git a/net/src/main/java/com/drake/net/exception/NetConnectException.kt b/net/src/main/java/com/drake/net/exception/NetConnectException.kt new file mode 100644 index 000000000..d809e69d6 --- /dev/null +++ b/net/src/main/java/com/drake/net/exception/NetConnectException.kt @@ -0,0 +1,8 @@ +package com.drake.net.exception + +import okhttp3.Request + +class NetConnectException( + request: Request, + cause: Throwable? = null +) : NetException(request, cause = cause) \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/exception/NetException.kt b/net/src/main/java/com/drake/net/exception/NetException.kt similarity index 68% rename from kalle/src/main/java/com/yanzhenjie/kalle/exception/NetException.kt rename to net/src/main/java/com/drake/net/exception/NetException.kt index 63c1b83f9..72d918547 100644 --- a/kalle/src/main/java/com/yanzhenjie/kalle/exception/NetException.kt +++ b/net/src/main/java/com/drake/net/exception/NetException.kt @@ -14,14 +14,25 @@ * limitations under the License. */ -package com.yanzhenjie.kalle.exception +package com.drake.net.exception -import com.yanzhenjie.kalle.Request +import okhttp3.Request import java.io.IOException +/** + * Net网络异常 + * + * @param request 请求信息 + * @param info 异常信息 + */ open class NetException( val request: Request, - message: String = "", + val info: String? = null, cause: Throwable? = null -) : IOException("$message [${request.location()}]", cause) \ No newline at end of file +) : IOException(cause) { + + override fun getLocalizedMessage(): String? { + return info?.let { "$it [${request.url}]" } ?: "[${request.url}]" + } +} \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/exception/NetSocketTimeoutException.kt b/net/src/main/java/com/drake/net/exception/NetSocketTimeoutException.kt new file mode 100644 index 000000000..7af38341a --- /dev/null +++ b/net/src/main/java/com/drake/net/exception/NetSocketTimeoutException.kt @@ -0,0 +1,9 @@ +package com.drake.net.exception + +import okhttp3.Request + +class NetSocketTimeoutException( + request: Request, + info: String? = null, + cause: Throwable? = null +) : NetException(request, info, cause) \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/exception/NetUnknownHostException.kt b/net/src/main/java/com/drake/net/exception/NetUnknownHostException.kt new file mode 100644 index 000000000..57b62f128 --- /dev/null +++ b/net/src/main/java/com/drake/net/exception/NetUnknownHostException.kt @@ -0,0 +1,8 @@ +package com.drake.net.exception + +import okhttp3.Request + +class NetUnknownHostException( + request: Request, + cause: Throwable? = null +) : NetException(request, cause = cause) \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/exception/NoCacheException.kt b/net/src/main/java/com/drake/net/exception/NoCacheException.kt new file mode 100644 index 000000000..eb311b38b --- /dev/null +++ b/net/src/main/java/com/drake/net/exception/NoCacheException.kt @@ -0,0 +1,9 @@ +package com.drake.net.exception + +import okhttp3.Request + +class NoCacheException( + request: Request, + info: String? = null, + cause: Throwable? = null +) : NetException(request, info, cause) \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/tag/RESPONSE.kt b/net/src/main/java/com/drake/net/exception/RequestParamsException.kt similarity index 77% rename from net/src/main/java/com/drake/net/tag/RESPONSE.kt rename to net/src/main/java/com/drake/net/exception/RequestParamsException.kt index 79cdc405e..00b1ab9b3 100644 --- a/net/src/main/java/com/drake/net/tag/RESPONSE.kt +++ b/net/src/main/java/com/drake/net/exception/RequestParamsException.kt @@ -14,9 +14,11 @@ * limitations under the License. */ -package com.drake.net.tag +package com.drake.net.exception + +import okhttp3.Response /** - * 响应体打印标签 + * 400 - 499 客户端请求异常 */ -object RESPONSE : TAG() +class RequestParamsException(val response: Response) : NetException(response.request) \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/error/RequestParamsException.kt b/net/src/main/java/com/drake/net/exception/ResponseException.kt similarity index 67% rename from net/src/main/java/com/drake/net/error/RequestParamsException.kt rename to net/src/main/java/com/drake/net/exception/ResponseException.kt index 085b0a2fa..c66488016 100644 --- a/net/src/main/java/com/drake/net/error/RequestParamsException.kt +++ b/net/src/main/java/com/drake/net/exception/ResponseException.kt @@ -14,15 +14,16 @@ * limitations under the License. */ -package com.drake.net.error +@file:Suppress("MemberVisibilityCanBePrivate") -import com.yanzhenjie.kalle.Request -import com.yanzhenjie.kalle.exception.NetException +package com.drake.net.exception + +import okhttp3.Response /** - * 404 + * 如果返回200但是返回数据不符合业务要求可以抛出该异常 */ -class RequestParamsException( - val code: Int, - request: Request -) : NetException(request, code.toString()) \ No newline at end of file +class ResponseException( + response: Response, + info: String? +) : NetException(response.request, info) \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/tag/REQUEST.kt b/net/src/main/java/com/drake/net/exception/ServerResponseException.kt similarity index 78% rename from net/src/main/java/com/drake/net/tag/REQUEST.kt rename to net/src/main/java/com/drake/net/exception/ServerResponseException.kt index bb51a5932..47b477c88 100644 --- a/net/src/main/java/com/drake/net/tag/REQUEST.kt +++ b/net/src/main/java/com/drake/net/exception/ServerResponseException.kt @@ -14,9 +14,12 @@ * limitations under the License. */ -package com.drake.net.tag +package com.drake.net.exception + +import okhttp3.Response + /** - * 请求参数打印标签 + * >= 500 服务器异常 */ -object REQUEST : TAG() \ No newline at end of file +class ServerResponseException(val response: Response) : NetException(response.request) \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/exception/URLParseException.kt b/net/src/main/java/com/drake/net/exception/URLParseException.kt new file mode 100644 index 000000000..03da5cef0 --- /dev/null +++ b/net/src/main/java/com/drake/net/exception/URLParseException.kt @@ -0,0 +1,9 @@ +package com.drake.net.exception + +/** + * URL地址错误 + */ +open class URLParseException( + val url: String, + cause: Throwable? = null +) : Exception(url, cause) \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/interceptor/LogRecordInterceptor.kt b/net/src/main/java/com/drake/net/interceptor/LogRecordInterceptor.kt new file mode 100644 index 000000000..bc9847ee0 --- /dev/null +++ b/net/src/main/java/com/drake/net/interceptor/LogRecordInterceptor.kt @@ -0,0 +1,70 @@ +package com.drake.net.interceptor + +import android.util.Log +import com.drake.net.log.LogRecorder +import com.drake.net.request.isLogRecord +import com.drake.net.request.label +import com.drake.net.request.logString +import com.drake.net.response.logString +import com.drake.net.tag.NetLabel +import okhttp3.Interceptor +import okhttp3.Response + +/** + * 网络日志记录器 + * 可以参考此拦截器为项目中其他网络请求库配置. 本拦截器属于标准的OkHttp拦截器适用于所有OkHttp拦截器内核的网络请求库 + * + * 在正式环境下请禁用此日志记录器. 因为他会消耗少量网络速度 + * + * @property enabled 是否启用日志输出 + * @property requestByteCount 请求日志输出字节数 + * @property responseByteCount 响应日志输出字节数 + */ +class LogRecordInterceptor( + val enabled: Boolean, + val requestByteCount: Long = 1024 * 1024, + val responseByteCount: Long = 1024 * 1024 * 4 +) : Interceptor { + + init { + LogRecorder.enabled = enabled + } + + override fun intercept(chain: Interceptor.Chain): Response { + val request = chain.request() + request.label() + + if (request.isLogRecord() == false) { + return chain.proceed(request) + } + + val generateId = LogRecorder.generateId() + LogRecorder.recordRequest( + generateId, + request.url.toString(), + request.method, + request.headers.toMultimap(), + request.logString(requestByteCount) + ) + try { + val response = chain.proceed(request) + LogRecorder.recordResponse( + generateId, + System.currentTimeMillis(), + response.code, + response.headers.toMultimap(), + response.logString(responseByteCount) + ) + return response + } catch (e: Exception) { + LogRecorder.recordException( + generateId, + System.currentTimeMillis(), + -1, + null, + Log.getStackTraceString(e) + ) + throw e + } + } +} \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/interceptor/NetOkHttpInterceptor.kt b/net/src/main/java/com/drake/net/interceptor/NetOkHttpInterceptor.kt new file mode 100644 index 000000000..a5706224b --- /dev/null +++ b/net/src/main/java/com/drake/net/interceptor/NetOkHttpInterceptor.kt @@ -0,0 +1,50 @@ +package com.drake.net.interceptor + +import com.drake.net.body.toNetRequestBody +import com.drake.net.body.toNetResponseBody +import com.drake.net.exception.NetConnectException +import com.drake.net.exception.NetException +import com.drake.net.exception.NetSocketTimeoutException +import com.drake.net.exception.NetUnknownHostException +import com.drake.net.okhttp.attachToNet +import com.drake.net.okhttp.detachFromNet +import com.drake.net.request.downloadListeners +import com.drake.net.request.setLabel +import com.drake.net.request.uploadListeners +import com.drake.net.tag.NetLabel +import okhttp3.Interceptor +import okhttp3.Response +import java.net.ConnectException +import java.net.SocketTimeoutException +import java.net.UnknownHostException + +/** + * Net代理OkHttp的拦截器 + */ +object NetOkHttpInterceptor : Interceptor { + + override fun intercept(chain: Interceptor.Chain): Response { + var request = chain.request() + val netRequestBody = request.body?.toNetRequestBody(request) + request = request.newBuilder().method(request.method, netRequestBody).apply { + if (request.uploadListeners() == null) setLabel(NetLabel.UploadListeners()) + if (request.downloadListeners() == null) setLabel(NetLabel.DownloadListeners()) + }.build() + val response = try { + chain.call().attachToNet() + chain.proceed(request) + } catch (e: SocketTimeoutException) { + throw NetSocketTimeoutException(request, e.message, e) + } catch (e: ConnectException) { + throw NetConnectException(request, cause = e) + } catch (e: UnknownHostException) { + throw NetUnknownHostException(request, e) + } catch (e: Throwable) { + throw NetException(request, cause = e) + } + val netResponseBody = response.body?.toNetResponseBody(request) { + chain.call().detachFromNet() + } + return response.newBuilder().body(netResponseBody).build() + } +} \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/interceptor/RequestInterceptor.kt b/net/src/main/java/com/drake/net/interceptor/RequestInterceptor.kt new file mode 100644 index 000000000..43542a525 --- /dev/null +++ b/net/src/main/java/com/drake/net/interceptor/RequestInterceptor.kt @@ -0,0 +1,13 @@ +package com.drake.net.interceptor + +import com.drake.net.request.BaseRequest + +interface RequestInterceptor { + + /** + * 当你使用Net发起请求的时候就会触发该拦截器 + * 该拦截器属于轻量级不具备重发的功能, 一般用于请求参数的修改 + * 请勿在这里进行请求重发可能会导致死循环 + */ + fun interceptor(request: BaseRequest) +} \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/interceptor/RetryInterceptor.kt b/net/src/main/java/com/drake/net/interceptor/RetryInterceptor.kt new file mode 100644 index 000000000..b4199f7a1 --- /dev/null +++ b/net/src/main/java/com/drake/net/interceptor/RetryInterceptor.kt @@ -0,0 +1,26 @@ +package com.drake.net.interceptor + +import androidx.annotation.IntRange +import okhttp3.Interceptor +import okhttp3.Response +import okhttp3.internal.closeQuietly + +/** + * 重试次数拦截器 + * + * @property retryCount 重试次数 + */ +class RetryInterceptor(@IntRange(from = 1) val retryCount: Int = 3) : Interceptor { + + override fun intercept(chain: Interceptor.Chain): Response { + var retryCount = 0 + val request = chain.request() + var response = chain.proceed(request) + while (!response.isSuccessful && retryCount < this.retryCount) { + retryCount++ + response.closeQuietly() + response = chain.proceed(request) + } + return response + } +} \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/interfaces/NetCallback.kt b/net/src/main/java/com/drake/net/interfaces/NetCallback.kt new file mode 100644 index 000000000..d91ee3189 --- /dev/null +++ b/net/src/main/java/com/drake/net/interfaces/NetCallback.kt @@ -0,0 +1,53 @@ +package com.drake.net.interfaces + +import com.drake.net.NetConfig +import com.drake.net.request.converter +import com.drake.net.utils.runMain +import okhttp3.Call +import okhttp3.Callback +import okhttp3.Response +import java.io.IOException +import java.lang.reflect.ParameterizedType + +/** + * 提供泛型转换特性 + * 相对于OkHttp的Callback新增三个回调函数: [onSuccess] [onError] [onComplete] + * 这三个函数都运行在主线程上 + */ +abstract class NetCallback : Callback { + + override fun onResponse(call: Call, response: Response) { + val succeed = (javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0] + val data = response.request.converter()?.onConvert(succeed, response) ?: return + runMain { + onSuccess(call, data) + onComplete(call, null) + } + } + + override fun onFailure(call: Call, e: IOException) { + runMain { + onError(call, e) + onComplete(call, e) + } + } + + /** + * 请求成功 + */ + abstract fun onSuccess(call: Call, data: T) + + /** + * 请求错误 + */ + fun onError(call: Call, e: IOException) { + NetConfig.onError.invoke(e) + } + + /** + * 请求完成 + * + * @param e 正常结束则为NULL, 发生异常结束则为异常对象 + */ + fun onComplete(call: Call, e: IOException?) {} +} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/ResponseBody.java b/net/src/main/java/com/drake/net/interfaces/ProgressListener.kt similarity index 54% rename from kalle/src/main/java/com/yanzhenjie/kalle/ResponseBody.java rename to net/src/main/java/com/drake/net/interfaces/ProgressListener.kt index f3b28cb4b..5cff25d8e 100644 --- a/kalle/src/main/java/com/yanzhenjie/kalle/ResponseBody.java +++ b/net/src/main/java/com/drake/net/interfaces/ProgressListener.kt @@ -13,29 +13,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.yanzhenjie.kalle; +package com.drake.net.interfaces -import java.io.Closeable; -import java.io.IOException; -import java.io.InputStream; +import com.drake.net.component.Progress /** - * Created by Zhenjie Yan on 2018/2/22. + * 进度监听器, 为下载和上传两者 + * + * @param interval 进度监听器刷新的间隔时间, 单位为毫秒, 默认值为500ms */ -public interface ResponseBody extends Closeable { - - /** - * Transform the response data into a string. - */ - String string() throws IOException; +abstract class ProgressListener( + var interval: Long = 500, +) { + // 上次触发监听器时的开机时间 + var elapsedTime = 0L - /** - * Transform the response data into a byte array. - */ - byte[] byteArray() throws IOException; + // 距离上次触发监听器的间隔字节数 + var intervalByteCount = 0L /** - * Transform the response data into a stream. + * 监听上传/下载进度回调函数 */ - InputStream stream() throws IOException; + abstract fun onProgress(p: Progress) } \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/recorder/LogRecorder.kt b/net/src/main/java/com/drake/net/log/LogRecorder.kt similarity index 95% rename from kalle/src/main/java/com/yanzhenjie/kalle/recorder/LogRecorder.kt rename to net/src/main/java/com/drake/net/log/LogRecorder.kt index 244f19c13..e645c3d60 100644 --- a/kalle/src/main/java/com/yanzhenjie/kalle/recorder/LogRecorder.kt +++ b/net/src/main/java/com/drake/net/log/LogRecorder.kt @@ -1,9 +1,9 @@ -package com.yanzhenjie.kalle.recorder +package com.drake.net.log import android.annotation.SuppressLint import android.os.* import android.util.Log -import com.yanzhenjie.kalle.recorder.LogRecorder.enabled +import com.drake.net.log.LogRecorder.enabled import java.text.DateFormat import java.text.SimpleDateFormat import java.util.* @@ -45,11 +45,11 @@ object LogRecorder { fun generateId(): String { if (!enabled) return "" var currentTime: Long = format.format(Date()).toLong() - var previousTime: Long = this.previousTime.get() + var previousTime: Long = previousTime.get() if (currentTime <= previousTime) { currentTime = ++previousTime } - this.previousTime.set(currentTime) + LogRecorder.previousTime.set(currentTime) return currentTime.toString(Character.MAX_RADIX) } @@ -71,7 +71,6 @@ object LogRecorder { body: String? ) { if (!enabled) return - fastLog(id, MessageType.REQUEST_METHOD, method) fastLog(id, MessageType.REQUEST_URL, url) fastLog(id, MessageType.REQUEST_TIME, System.currentTimeMillis().toString()) @@ -83,8 +82,6 @@ object LogRecorder { } if (body != null) { largeLog(id, MessageType.REQUEST_BODY, body) - } else { - largeLog(id, MessageType.REQUEST_BODY, url) } } diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/recorder/MessageType.kt b/net/src/main/java/com/drake/net/log/MessageType.kt similarity index 90% rename from kalle/src/main/java/com/yanzhenjie/kalle/recorder/MessageType.kt rename to net/src/main/java/com/drake/net/log/MessageType.kt index 3d1a8cbfc..c20050018 100644 --- a/kalle/src/main/java/com/yanzhenjie/kalle/recorder/MessageType.kt +++ b/net/src/main/java/com/drake/net/log/MessageType.kt @@ -1,4 +1,4 @@ -package com.yanzhenjie.kalle.recorder +package com.drake.net.log enum class MessageType(var type: String) { REQUEST_URL("RQU"), diff --git a/net/src/main/java/com/drake/net/okhttp/CallExtension.kt b/net/src/main/java/com/drake/net/okhttp/CallExtension.kt new file mode 100644 index 000000000..4747e3b01 --- /dev/null +++ b/net/src/main/java/com/drake/net/okhttp/CallExtension.kt @@ -0,0 +1,25 @@ +package com.drake.net.okhttp + +import com.drake.net.NetConfig +import okhttp3.Call +import java.lang.ref.WeakReference + +/** + * Call附着到Net上 + */ +fun Call.attachToNet() { + NetConfig.netCalls.add(WeakReference(this)) +} + +/** + * Call从Net上分离释放引用 + */ +fun Call.detachFromNet() { + val iterator = NetConfig.netCalls.iterator() + while (iterator.hasNext()) { + if (iterator.next().get() == this) { + iterator.remove() + return + } + } +} \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/okhttp/OkHttpExtension.kt b/net/src/main/java/com/drake/net/okhttp/OkHttpExtension.kt new file mode 100644 index 000000000..aff213857 --- /dev/null +++ b/net/src/main/java/com/drake/net/okhttp/OkHttpExtension.kt @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2018 Drake, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.drake.net.okhttp + +import android.app.Dialog +import android.view.View +import androidx.fragment.app.FragmentActivity +import com.drake.net.NetConfig +import com.drake.net.convert.NetConverter +import com.drake.net.interceptor.NetOkHttpInterceptor +import com.drake.net.interceptor.RequestInterceptor +import com.drake.net.request.label +import com.drake.net.scope.DialogCoroutineScope +import com.drake.net.tag.NetLabel +import com.drake.net.utils.Https +import com.drake.net.utils.chooseTrustManager +import com.drake.net.utils.prepareKeyManager +import com.drake.net.utils.prepareTrustManager +import okhttp3.OkHttpClient +import java.io.InputStream +import java.security.KeyManagementException +import java.security.NoSuchAlgorithmException +import javax.net.ssl.SSLContext +import javax.net.ssl.TrustManager +import javax.net.ssl.X509TrustManager + +/** + * 开启日志 + */ +fun OkHttpClient.Builder.setLog(enabled: Boolean) = apply { + NetConfig.logEnabled = enabled +} + +/** + * 设置全局默认的Host, 在使用[com.drake.net.request.BaseRequest.setPath]的时候会成为默认的Host + */ +fun OkHttpClient.Builder.setHost(host: String) = apply { + NetConfig.host = host +} + +/** + * Net拦截器代理OkHttp + */ +fun OkHttpClient.Builder.toNetOkhttp() = apply { + val interceptors = interceptors() + if (!interceptors.contains(NetOkHttpInterceptor)) { + addInterceptor(NetOkHttpInterceptor) + } +} + +fun OkHttpClient.toNetOkhttp() = run { + if (!interceptors.contains(NetOkHttpInterceptor)) { + newBuilder().addInterceptor(NetOkHttpInterceptor).build() + } else this +} + +/** + * @param trustManager 如果需要自己校验,那么可以自己实现相关校验,如果不需要自己校验,那么传null即可 + * @param bksFile 客户端使用bks证书校验服务端证书 + * @param password bks证书的密码 + */ +fun OkHttpClient.Builder.setSSLCertificate( + trustManager: X509TrustManager?, + bksFile: InputStream? = null, + password: String? = null, +) = apply { + try { + val trustManagerFinal: X509TrustManager = trustManager ?: Https.UnSafeTrustManager + + val keyManagers = prepareKeyManager(bksFile, password) + val sslContext = SSLContext.getInstance("TLS") + // 用上面得到的trustManagers初始化SSLContext,这样sslContext就会信任keyStore中的证书 + // 第一个参数是授权的密钥管理器,用来授权验证,比如授权自签名的证书验证。第二个是被授权的证书管理器,用来验证服务器端的证书 + sslContext.init(keyManagers, arrayOf(trustManagerFinal), null) + // 通过sslContext获取SSLSocketFactory对象 + + sslSocketFactory(sslContext.socketFactory, trustManagerFinal) + } catch (e: NoSuchAlgorithmException) { + throw AssertionError(e) + } catch (e: KeyManagementException) { + throw AssertionError(e) + } +} + +/** + * @param certificates 含有服务端公钥的证书校验服务端证书 + * @param bksFile 客户端使用bks证书校验服务端证书 + * @param password bks证书的密码 + */ +fun OkHttpClient.Builder.setSSLCertificate( + vararg certificates: InputStream, + bksFile: InputStream? = null, + password: String? = null +) = apply { + val trustManager = prepareTrustManager(*certificates)?.let { chooseTrustManager(it) } + setSSLCertificate(trustManager, bksFile, password) +} + + +/** + * 信任所有证书 + */ +fun OkHttpClient.Builder.trustSSLCertificate() = apply { + hostnameVerifier(Https.UnSafeHostnameVerifier) + setSSLCertificate(null) +} + +/** + * 转换器 + */ +fun OkHttpClient.Builder.setConverter(converter: NetConverter) = apply { + NetConfig.converter = converter +} + +/** + * 添加轻量级的请求拦截器, 可以在每次请求之前修改参数或者客户端配置 + * 该拦截器不同于OkHttp的Interceptor无需处理请求动作 + */ +fun OkHttpClient.Builder.setRequestInterceptor(interceptor: RequestInterceptor) = apply { + NetConfig.requestInterceptor = interceptor +} + +/** + * 全局网络请求错误捕获 + */ +fun OkHttpClient.Builder.onError(block: Throwable.() -> Unit) = apply { + NetConfig.onError = block +} + +/** + * 全局缺省页错误捕获 + */ +fun OkHttpClient.Builder.onStateError(block: Throwable.(view: View) -> Unit) = apply { + NetConfig.onStateError = block +} + +/** + * 全局加载对话框设置 + * 设置在使用scopeDialog自动弹出的加载对话框 + */ +fun OkHttpClient.Builder.onDialog(block: DialogCoroutineScope.(FragmentActivity) -> Dialog) = + apply { + NetConfig.onDialog = block + } + +/** + * 取消OkHttp客户端中指定Id的请求 + * 如果使用的是Net创建的网络请求请使用[com.drake.net.Net.cancelId] + */ +fun OkHttpClient.cancelId(id: Any?) { + id ?: return + dispatcher.runningCalls().forEach { + if (id === it.request().label()?.value) { + it.cancel() + } + } + dispatcher.queuedCalls().forEach { + if (id === it.request().label()?.value) { + it.cancel() + } + } +} + +/** + * 取消OkHttp客户端中指定Group的请求 + * 如果使用的是Net创建的网络请求请使用[com.drake.net.Net.cancelGroup] + */ +fun OkHttpClient.cancelGroup(group: Any?) { + group ?: return + dispatcher.runningCalls().forEach { + if (group === it.request().label()?.value) { + it.cancel() + } + } + dispatcher.queuedCalls().forEach { + if (group === it.request().label()?.value) { + it.cancel() + } + } +} diff --git a/net/src/main/java/com/drake/net/request/BaseRequest.kt b/net/src/main/java/com/drake/net/request/BaseRequest.kt new file mode 100644 index 000000000..74acfd5a9 --- /dev/null +++ b/net/src/main/java/com/drake/net/request/BaseRequest.kt @@ -0,0 +1,291 @@ +/* + * Copyright (C) 2018 Drake, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@file:Suppress("unused", "MemberVisibilityCanBePrivate", "NAME_SHADOWING", "RedundantSetter") + +package com.drake.net.request + +import com.drake.net.NetConfig +import com.drake.net.convert.NetConverter +import com.drake.net.exception.URLParseException +import com.drake.net.interfaces.ProgressListener +import com.drake.net.okhttp.toNetOkhttp +import com.drake.net.tag.NetLabel +import okhttp3.* +import okhttp3.HttpUrl.Companion.toHttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull +import java.io.File +import java.net.URL + +abstract class BaseRequest { + + open var httpUrl: HttpUrl.Builder = HttpUrl.Builder() + open var converter: NetConverter = NetConfig.converter + open var method = Method.GET + open var tags: NetLabel.TagHashMap = NetLabel.TagHashMap() + + // + open var okHttpRequest: Request.Builder = Request.Builder() + open var okHttpClient = NetConfig.okHttpClient + set(value) { + field = value.toNetOkhttp() + } + + /** + * 修改当前Request的OkHttpClient配置, 不会影响全局默认的OkHttpClient + */ + fun setClient(block: OkHttpClient.Builder.() -> Unit) { + okHttpClient = okHttpClient.newBuilder().apply(block).toNetOkhttp().build() + } + // + + // + + /** + * 设置一个Url字符串, 其参数不会和你初始化时设置的主域名[NetConfig.host]进行拼接 + * 一般情况下我建议使用更为聪明的[setPath] + */ + open fun setUrl(url: String) { + try { + httpUrl = url.toHttpUrl().newBuilder() + } catch (e: Exception) { + throw URLParseException(url, e) + } + } + + open fun setUrl(url: HttpUrl) { + httpUrl = url.newBuilder() + } + + open fun setUrl(url: URL) { + setUrl(url.toString()) + } + + /** + * @param path 如果其不包含http/https则会自动拼接[NetConfig.host] + * @param encoded 是否已经进行过URLEncoder编码 + */ + fun setPath(path: String, encoded: Boolean = false) { + val httpUrlTemp = path.toHttpUrlOrNull() + if (httpUrlTemp == null) { + try { + httpUrl = NetConfig.host.toHttpUrl().newBuilder() + } catch (e: Throwable) { + throw URLParseException(NetConfig.host.ifEmpty { "NetConfig.host is empty" }, e) + } + if (encoded) { + httpUrl.addEncodedPathSegments(path) + } else httpUrl.addPathSegments(path) + } else { + this.httpUrl = httpUrlTemp.newBuilder() + } + } + + fun setQuery(name: String, value: String?, encoded: Boolean = false) { + if (encoded) { + httpUrl.setEncodedQueryParameter(name, value) + } else httpUrl.setQueryParameter(name, value) + } + + // + + // + + abstract fun param(name: String, value: String?, encoded: Boolean = false) + + abstract fun param(name: String, value: Number?) + + abstract fun param(name: String, value: Boolean?) + + // + + // + + /** + * 将一个任意对象添加到Request对象中, 一般用于在拦截器或者转换器中被获取到标签, 针对某个请求的特殊业务逻辑 + * 使用`Request.tag()`获取标签 + */ + fun setTag(tag: Any?) { + okHttpRequest.tag(tag) + } + + /** + * 添加标签 + * 使用`Request.tag(name)`得到指定标签 + * + * @param name 标签名称 + * @param tag 标签 + */ + fun setTag(name: String, tag: Any?) { + tags[name] = tag + } + + // + + // + + /** + * 添加请求头 + * 如果已存在相同`name`的请求头会添加而不会覆盖, 因为请求头本身存在多个值 + */ + fun addHeader(name: String, value: String) { + okHttpRequest.addHeader(name, value) + } + + /** + * 设置请求头, 会覆盖请求头而不像[addHeader]是添加 + */ + fun setHeader(name: String, value: String) { + okHttpRequest.header(name, value) + } + + /** + * 删除请求头 + */ + fun removeHeader(name: String) { + okHttpRequest.removeHeader(name) + } + + /** + * 批量设置请求头 + */ + fun setHeaders(headers: Headers) { + okHttpRequest.headers(headers) + } + + // + + // + + /** + * 设置请求头的缓存控制 + */ + fun setCacheControl(cacheControl: CacheControl) { + okHttpRequest.cacheControl(cacheControl) + } + // + + // + + /** + * 下载文件名 + */ + fun setDownloadFileName(name: String?) { + okHttpRequest.setLabel(NetLabel.DownloadFileName(name)) + } + + /** + * 下载文件的保存目录 + */ + fun setDownloadDir(name: String?) { + okHttpRequest.setLabel(NetLabel.DownloadFileDir(name)) + } + + fun setDownloadDir(name: File?) { + okHttpRequest.setLabel(NetLabel.DownloadFileDir(name)) + } + + /** + * 如果服务器返回 "Content-MD5"响应头和制定路径已经存在的文件MD5相同是否直接返回File + */ + fun setDownloadMd5Verify(enabled: Boolean = true) { + okHttpRequest.setLabel(NetLabel.DownloadFileMD5Verify(enabled)) + } + + /** + * 假设下载文件路径已存在同名文件是否重命名, 例如`file_name(1).apk` + */ + fun setDownloadFileNameConflict(enabled: Boolean = true) { + okHttpRequest.setLabel(NetLabel.DownloadFileConflictRename(enabled)) + } + + /** + * 文件名称是否使用URL解码 + * 例如下载的文件名如果是中文, 服务器传输给你的会是被URL编码的字符串. 你使用URL解码后才是可读的中文名称 + */ + fun setDownloadFileNameDecode(enabled: Boolean = true) { + okHttpRequest.setLabel(NetLabel.DownloadFileNameDecode(enabled)) + } + + /** + * 下载是否使用临时文件 + * 避免下载失败后覆盖同名文件或者无法判别是否已下载完整, 仅在下载完整以后才会显示为原有文件名 + * 临时文件命名规则: 文件名 + .net-download + * 下载文件名: install.apk, 临时文件名: install.apk.net-download + */ + fun setDownloadTempFile(enabled: Boolean = true) { + okHttpRequest.setLabel(NetLabel.DownloadTempFile(enabled)) + } + + /** + * 下载监听器 + */ + fun addDownloadListener(progressListener: ProgressListener) { + downloadListeners.add(progressListener) + } + + protected val downloadListeners = NetLabel.DownloadListeners() + + // + /** + * 唯一的Id + */ + fun setId(id: Any?) { + okHttpRequest.setId(id) + } + + /** + * 分组 + */ + fun setGroup(group: Any?) { + okHttpRequest.setGroup(group) + } + + /** + * 是否启用日志记录器 + */ + fun setLogRecord(enabled: Boolean) { + okHttpRequest.setLogRecord(enabled) + } + + open fun buildRequest(): Request { + return okHttpRequest.method(method.name, null) + .url(httpUrl.build()) + .setLabel(tags) + .setConverter(converter) + .setLabel(downloadListeners) + .build() + } + + /** + * 执行请求 + */ + inline fun execute(): R { + NetConfig.requestInterceptor?.interceptor(this) + val request = buildRequest() + val newCall = okHttpClient.newCall(request) + return newCall.execute().use { + converter.onConvert(R::class.java, it) as R + } + } + + fun enqueue(block: Callback): Call { + NetConfig.requestInterceptor?.interceptor(this) + val newCall = okHttpClient.newCall(buildRequest()) + newCall.enqueue(block) + return newCall + } +} + diff --git a/net/src/main/java/com/drake/net/request/BodyRequest.kt b/net/src/main/java/com/drake/net/request/BodyRequest.kt new file mode 100644 index 000000000..0d121f3d6 --- /dev/null +++ b/net/src/main/java/com/drake/net/request/BodyRequest.kt @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2018 Drake, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@file:Suppress("MemberVisibilityCanBePrivate") + +package com.drake.net.request + +import com.drake.net.interfaces.ProgressListener +import com.drake.net.tag.NetLabel +import com.drake.net.utils.lazyField +import okhttp3.* +import okhttp3.RequestBody.Companion.asRequestBody +import okhttp3.RequestBody.Companion.toRequestBody +import okio.ByteString +import org.json.JSONArray +import org.json.JSONObject +import java.io.File + +open class BodyRequest : BaseRequest() { + + open var body: RequestBody? = null + open var partBody: MultipartBody.Builder by lazyField { MultipartBody.Builder() } + open var formBody: FormBody.Builder by lazyField { FormBody.Builder() } + open var mediaType: MediaType = MediaType.FORM + override var method = Method.POST + + // + override fun param(name: String, value: String?, encoded: Boolean) { + if (encoded) { + formBody.addEncoded(name, value ?: return) + } else formBody.add(name, value ?: return) + } + + override fun param(name: String, value: Number?) { + formBody.add(name, value.toString()) + } + + override fun param(name: String, value: Boolean?) { + formBody.add(name, value.toString()) + } + + fun param(name: String, value: RequestBody?) { + partBody.addFormDataPart(name, null, value ?: return) + } + + fun param(name: String, value: ByteString?) { + partBody.addFormDataPart(name, null, value?.toRequestBody() ?: return) + } + + fun param(name: String, value: ByteArray?) { + partBody.addFormDataPart(name, null, value?.toRequestBody() ?: return) + } + + fun param(name: String, value: File?) { + partBody.addFormDataPart(name, null, value?.asRequestBody() ?: return) + } + + fun param(name: String, values: List?) { + values?.forEach { value -> + value?.asRequestBody()?.let { partBody.addFormDataPart(name, null, it) } + } + } + + fun param(name: String, fileName: String?, value: File?) { + partBody.addFormDataPart(name, fileName, value?.asRequestBody() ?: return) + } + + fun param(body: RequestBody, header: Headers? = null) { + partBody.addPart(header, body) + } + + fun param(body: MultipartBody.Part) { + partBody.addPart(body) + } + + // + + // + fun json(body: JSONObject?) { + body?.let { partBody.addPart(it.toString().toRequestBody(MediaType.Companion.JSON)) } + } + + fun json(body: JSONArray?) { + body?.let { partBody.addPart(it.toString().toRequestBody(MediaType.Companion.JSON)) } + } + + fun json(body: String?) { + body?.let { partBody.addPart(it.toRequestBody(MediaType.Companion.JSON)) } + } + + fun json(body: Map?) { + body?.let { + partBody.addPart(JSONObject(it).toString().toRequestBody(MediaType.Companion.JSON)) + } + } + + fun json(vararg body: Pair) { + body.toMap().let { + partBody.addPart(JSONObject(it).toString().toRequestBody(MediaType.Companion.JSON)) + } + } + // + + /** + * 上传进度监听器 + */ + fun addUploadListener(progressListener: ProgressListener) { + uploadListeners.add(progressListener) + } + + private val uploadListeners = NetLabel.UploadListeners() + + override fun buildRequest(): Request { + val body = if (body != null) body else { + val form = formBody.build() + try { + partBody.build() + for (i in 0 until form.size) { + val name = form.encodedName(i) + val value = form.encodedValue(i) + partBody.addFormDataPart(name, value) + } + partBody.setType(mediaType).build() + } catch (e: IllegalStateException) { + form + } + } + + return okHttpRequest.method(method.name, body) + .url(httpUrl.build()) + .setLabel(tags) + .setConverter(converter) + .setLabel(downloadListeners) + .setLabel(uploadListeners) + .build() + } +} \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/request/MediaType.kt b/net/src/main/java/com/drake/net/request/MediaType.kt new file mode 100644 index 000000000..58f680886 --- /dev/null +++ b/net/src/main/java/com/drake/net/request/MediaType.kt @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2018 Drake, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.drake.net.request + +import okhttp3.MediaType + + +val MediaType.Companion.IMG: MediaType + get() = "image/*".toMediaType() + +val MediaType.Companion.GIF: MediaType + get() = "image/gif".toMediaType() + +val MediaType.Companion.JPEG: MediaType + get() = "image/jpeg".toMediaType() + +val MediaType.Companion.PNG: MediaType + get() = "image/png".toMediaType() + +val MediaType.Companion.MP4: MediaType + get() = "video/mpeg".toMediaType() + +val MediaType.Companion.TXT: MediaType + get() = "text/plain".toMediaType() + +val MediaType.Companion.JSON: MediaType + get() = "application/json; charset=utf-8".toMediaType() + +val MediaType.Companion.XML: MediaType + get() = "application/xml".toMediaType() + +val MediaType.Companion.HTML: MediaType + get() = "text/html".toMediaType() + +val MediaType.Companion.FORM: MediaType + get() = "multipart/form-data".toMediaType() + +val MediaType.Companion.URLENCODED: MediaType + get() = "application/x-www-form-urlencoded".toMediaType() diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/Canceller.kt b/net/src/main/java/com/drake/net/request/Method.kt similarity index 80% rename from kalle/src/main/java/com/yanzhenjie/kalle/Canceller.kt rename to net/src/main/java/com/drake/net/request/Method.kt index c3d6da7cc..59c7d245f 100644 --- a/kalle/src/main/java/com/yanzhenjie/kalle/Canceller.kt +++ b/net/src/main/java/com/drake/net/request/Method.kt @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.yanzhenjie.kalle -interface Canceller { +package com.drake.net.request - fun cancel() - val isCancelled: Boolean +enum class Method { + GET, HEAD, OPTIONS, TRACE, // Url request + POST, DELETE, PUT, PATCH // Body request } \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/request/RequestExtension.kt b/net/src/main/java/com/drake/net/request/RequestExtension.kt new file mode 100644 index 000000000..26e4877fb --- /dev/null +++ b/net/src/main/java/com/drake/net/request/RequestExtension.kt @@ -0,0 +1,182 @@ +/* + * Copyright (C) 2018 Drake, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.drake.net.request + +import com.drake.net.NetConfig +import com.drake.net.body.peekString +import com.drake.net.convert.NetConverter +import com.drake.net.interfaces.ProgressListener +import com.drake.net.tag.NetLabel +import okhttp3.FormBody +import okhttp3.Request +import java.util.concurrent.ConcurrentLinkedQueue + +// +/** + * 请求的Id + */ +fun Request.id(): Any? { + return label()?.value +} + +fun Request.Builder.setId(id: Any?) = apply { + setLabel(NetLabel.RequestId(id)) +} + +/** + * 请求的分组名 + */ +fun Request.group(): Any? { + return label()?.value +} + +fun Request.Builder.setGroup(group: Any?) = apply { + setLabel(NetLabel.RequestGroup(group)) +} + +/** + * 请求标签 + */ +fun Request.tag(name: String): Any? { + return label()?.get(name) +} + +/** + * 请求标签 + */ +fun Request.setTag(name: String, value: Any?) = apply { + label()?.put(name, value) +} + +/** + * 设置是否记录日志 + */ +fun Request.Builder.setLogRecord(enabled: Boolean) = apply { + setLabel(NetLabel.RecordLog(enabled)) +} + +/** + * 是否记录日志 + */ +fun Request.isLogRecord() = run { + label()?.enabled +} + +inline fun Request.Builder.setLabel(any: T) = apply { + tag(T::class.java, any) +} + +inline fun Request.label(): T? { + return tag(T::class.java) +} +// + +// +/** + * 当指定下载目录存在同名文件是覆盖还是进行重命名, 重命名规则是: $文件名_($序号).$后缀 + */ +fun Request.downloadConflictRename(): Boolean { + return label()?.enabled == true +} + +/** + * 是否进行校验文件md5, 如果校验则匹配上既马上返回文件而不会进行下载 + */ +fun Request.downloadMd5Verify(): Boolean { + return label()?.enabled == true +} + +/** + * 下载文件目录 + */ +fun Request.downloadFileDir(): String { + return label()?.dir ?: NetConfig.app.filesDir.absolutePath +} + +/** + * 下载文件名 + */ +fun Request.downloadFileName(): String? { + return label()?.name +} + +/** + * 下载的文件名称是否解码 + * 例如下载的文件名如果是中文, 服务器传输给你的会是被URL编码的字符串. 你使用URL解码后才是可读的中文名称 + */ +fun Request.downloadFileNameDecode(): Boolean { + return label()?.enabled == true +} + +/** + * 下载是否使用临时文件 + * 避免下载失败后覆盖同名文件或者无法判别是否已下载完整, 仅在下载完整以后才会显示为原有文件名 + * 临时文件命名规则: 文件名 + .net-download + * 下载文件名: install.apk, 临时文件名: install.apk.net-download + */ +fun Request.downloadTempFile(): Boolean { + return label()?.enabled == true +} +// + +// +/** + * 上传监听器 + */ +fun Request.uploadListeners(): ConcurrentLinkedQueue? { + return label() +} + +/** + * 下载监听器 + */ +fun Request.downloadListeners(): ConcurrentLinkedQueue? { + return label() +} + +fun Request.addUploadListener(progressListener: ProgressListener) { + uploadListeners()?.add(progressListener) +} + +fun Request.addDownloadListener(progressListener: ProgressListener) { + downloadListeners()?.add(progressListener) +} +// + +/** + * 转换器 + */ +fun Request.converter(): NetConverter? { + return label() +} + +fun Request.Builder.setConverter(converter: NetConverter) = apply { + setLabel(converter) +} + +/** + * 请求日志信息 + * 只会输出纯表单(form)的请求参数 + */ +fun Request.logString(byteCount: Long = 1024 * 1024): String? { + val mediaType = body?.contentType() ?: return null + return if (body is FormBody) { + body?.peekString(byteCount) + } else { + "LogRecordInterceptor not support this type $mediaType" + } +} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/util/MainExecutor.java b/net/src/main/java/com/drake/net/request/UrlRequest.kt similarity index 54% rename from kalle/src/main/java/com/yanzhenjie/kalle/util/MainExecutor.java rename to net/src/main/java/com/drake/net/request/UrlRequest.kt index 064972918..108d529b1 100644 --- a/kalle/src/main/java/com/yanzhenjie/kalle/util/MainExecutor.java +++ b/net/src/main/java/com/drake/net/request/UrlRequest.kt @@ -13,26 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.yanzhenjie.kalle.util; -import android.os.Handler; -import android.os.Looper; +package com.drake.net.request -import java.util.concurrent.Executor; +open class UrlRequest : BaseRequest() { -/** - * Created by Zhenjie Yan on 2018/3/14. - */ -public class MainExecutor implements Executor { - - private Handler mHandler; + override fun param(name: String, value: String?, encoded: Boolean) { + if (encoded) { + httpUrl.setQueryParameter(name, value) + } else httpUrl.setEncodedQueryParameter(name, value) + } - public MainExecutor() { - mHandler = new Handler(Looper.getMainLooper()); + override fun param(name: String, value: Number?) { + httpUrl.setQueryParameter(name, value.toString()) } - @Override - public void execute(Runnable command) { - mHandler.post(command); + override fun param(name: String, value: Boolean?) { + httpUrl.setQueryParameter(name, value.toString()) } } \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/response/ResponseExtention.kt b/net/src/main/java/com/drake/net/response/ResponseExtention.kt new file mode 100644 index 000000000..b91f7884f --- /dev/null +++ b/net/src/main/java/com/drake/net/response/ResponseExtention.kt @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2018 Drake, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.drake.net.response + +import com.drake.net.body.peekString +import com.drake.net.exception.DownloadFileException +import com.drake.net.request.* +import com.drake.net.utils.isValid +import com.drake.net.utils.md5 +import okhttp3.Response +import okio.buffer +import okio.sink +import java.io.File +import java.net.SocketException +import java.net.URLDecoder +import kotlin.coroutines.cancellation.CancellationException + +/** + * 按照以下顺序返回最终的下载文件的名称 + * + * 1. 指定文件名 + * 2. 响应头文件名 + * 3. 请求URL路径 + * 4. 时间戳 + */ +fun Response.fileName(): String { + request.downloadFileName().isValid { return it } + val disposition = header("Content-Disposition") + if (disposition != null) { + disposition.substringAfter("filename=", "").isValid { return it } + disposition.substringAfter("filename*=", "").trimStart(*"UTF-8''".toCharArray()) + .isValid { return it } + } + + var fileName: String = request.url.pathSegments.last().substringBefore("?") + fileName = if (fileName.isBlank()) "unknown_${System.currentTimeMillis()}" else { + if (request.downloadFileNameDecode()) { + try { + URLDecoder.decode(fileName, "UTF8") + } catch (e: Exception) { + fileName + } + } else fileName + } + return fileName +} + +/** + * 下载到指定文件 + */ +@Throws(DownloadFileException::class) +fun Response.file(): File? { + val downloadDir = request.downloadFileDir() + val fileName = fileName() + var file = File(downloadDir, fileName) + try { + if (file.exists()) { + // MD5校验匹配文件 + if (request.downloadMd5Verify()) { + val md5Header = request.header("Content-MD5") + if (file.md5() == md5Header) return file + } + // 命名冲突添加序列数字的后缀 + if (request.downloadConflictRename() && file.name == fileName) { + val fileExtension = file.extension + val fileNameWithoutExtension = file.nameWithoutExtension + fun rename(index: Long): File { + file = File(downloadDir, fileNameWithoutExtension + "_($index)" + fileExtension) + return if (file.exists()) { + rename(index + 1) + } else file + } + return rename(1) + } + request.downloadFileNameDecode() + } + + // 临时文件 + if (request.downloadTempFile()) { + file = File(downloadDir, file.name + ".net-download") + } + val source = body?.source() ?: return null + if (!file.exists()) file.createNewFile() + file.sink().buffer().use { + it.writeAll(source) + } + // 下载完毕删除临时文件 + if (request.downloadTempFile()) { + file.renameTo(File(downloadDir, fileName)) + } + return file + } catch (e: SocketException) { + // 取消请求需要删除下载临时文件 + if (request.downloadTempFile()) file.delete() + throw CancellationException(e) + } catch (e: Exception) { + throw DownloadFileException(this, "An exception occurred while download file", e) + } +} + +/** + * 响应日志信息 + * 只会输出JSON(application/json)和文本(text/\*)字符串日志 + */ +fun Response.logString(byteCount: Long = 1024 * 1024 * 4): String? { + val mediaType = body?.contentType() ?: return null + return if (mediaType.subtype == "json" || mediaType.type == "text") { + body?.peekString(byteCount) + } else { + "LogRecordInterceptor not support this type $mediaType" + } +} \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/scope/AndroidScope.kt b/net/src/main/java/com/drake/net/scope/AndroidScope.kt index 000379a02..0a6779872 100644 --- a/net/src/main/java/com/drake/net/scope/AndroidScope.kt +++ b/net/src/main/java/com/drake/net/scope/AndroidScope.kt @@ -49,7 +49,7 @@ open class AndroidScope( catch(throwable) } - val uid = exceptionHandler + val scopeGroup = exceptionHandler override val coroutineContext: CoroutineContext = dispatcher + exceptionHandler + SupervisorJob() diff --git a/net/src/main/java/com/drake/net/scope/NetCoroutineScope.kt b/net/src/main/java/com/drake/net/scope/NetCoroutineScope.kt index 47e4480d1..d84b9577d 100644 --- a/net/src/main/java/com/drake/net/scope/NetCoroutineScope.kt +++ b/net/src/main/java/com/drake/net/scope/NetCoroutineScope.kt @@ -18,8 +18,8 @@ package com.drake.net.scope import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleOwner +import com.drake.net.Net import com.drake.net.NetConfig -import com.yanzhenjie.kalle.NetCancel import kotlinx.coroutines.* import kotlin.coroutines.EmptyCoroutineContext @@ -71,11 +71,6 @@ open class NetCoroutineScope( } - override fun finally(e: Throwable?) { - super.finally(e) - NetCancel.cancel(uid) - } - /** * 读取缓存回调 * @param succeed 缓存是否成功 @@ -113,7 +108,7 @@ open class NetCoroutineScope( } override fun cancel(cause: CancellationException?) { - NetCancel.cancel(uid) + Net.cancelGroup(scopeGroup) super.cancel(cause) } } \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/tag/NetLabel.kt b/net/src/main/java/com/drake/net/tag/NetLabel.kt new file mode 100644 index 000000000..c6cefc50a --- /dev/null +++ b/net/src/main/java/com/drake/net/tag/NetLabel.kt @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2018 Drake, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.drake.net.tag + +import com.drake.net.interfaces.ProgressListener +import java.io.File +import java.util.concurrent.ConcurrentLinkedQueue + +sealed class NetLabel { + inline class RequestId(val value: Any?) + inline class RequestGroup(val value: Any?) + inline class RecordLog(val enabled: Boolean) + + inline class DownloadFileDir(val dir: String?) { + constructor(fileDir: File?) : this(fileDir?.absolutePath) + } + + inline class DownloadFileMD5Verify(val enabled: Boolean = true) + inline class DownloadFileNameDecode(val enabled: Boolean = true) + inline class DownloadTempFile(val enabled: Boolean = true) + inline class DownloadFileConflictRename(val enabled: Boolean = true) + inline class DownloadFileName(val name: String?) + class DownloadListeners : ConcurrentLinkedQueue() + class UploadListeners : ConcurrentLinkedQueue() + class TagHashMap : HashMap() +} diff --git a/net/src/main/java/com/drake/net/tag/TAG.kt b/net/src/main/java/com/drake/net/tag/TAG.kt deleted file mode 100644 index 267399ecf..000000000 --- a/net/src/main/java/com/drake/net/tag/TAG.kt +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.drake.net.tag - -import kotlin.reflect.KClass - - -abstract class TAG { - - protected var list: MutableList? = null - - operator fun get(key: KClass): TAG? { - - list?.forEach { - if (it::class == key) return it - } - - return if (this::class == key) this else null - } - - operator fun plus(tag: TAG): TAG { - - if (this == tag) return this - if (list == null) list = mutableListOf(this) - - list?.apply { - add(this@TAG) - - if (tag.list.isNullOrEmpty()) { - if (tag !in this) add(tag) - } else { - addAll(tag.list!!) - } - } - - return this - } - - operator fun minus(tag: TAG): TAG { - - if (this == tag) return this - - val right = tag.list - - if (right.isNullOrEmpty()) { - list?.remove(tag) - } else { - list?.removeAll(right) - } - - return this - } - - operator fun contains(tag: @UnsafeVariance TAG): Boolean { - - if (tag == this) return true - - val right = tag.list - - return if (right.isNullOrEmpty()) { - list?.contains(tag) ?: false - } else { - list?.containsAll(right) ?: false - } - } - -} \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/utils/Fastest.kt b/net/src/main/java/com/drake/net/utils/Fastest.kt index 8eabf7c00..40c427053 100644 --- a/net/src/main/java/com/drake/net/utils/Fastest.kt +++ b/net/src/main/java/com/drake/net/utils/Fastest.kt @@ -16,9 +16,9 @@ package com.drake.net.utils +import com.drake.net.Net import com.drake.net.NetConfig import com.drake.net.transform.DeferredTransform -import com.yanzhenjie.kalle.NetCancel import kotlinx.coroutines.* import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock @@ -29,14 +29,14 @@ import java.util.concurrent.CancellationException * 该函数将选择[listDeferred]中的Deferred执行[Deferred.await], 然后将返回最快的结果 * 执行过程中的异常将被忽略, 如果全部抛出异常则将抛出最后一个Deferred的异常 * - * @param uid 指定该值将在成功返回结果后取消掉对应uid的网络请求 + * @param group 指定该值将在成功返回结果后取消掉对应uid的网络请求 * @param listDeferred 一系列并发任务 */ @OptIn(ExperimentalCoroutinesApi::class) @Suppress("SuspendFunctionOnCoroutineScope") suspend fun CoroutineScope.fastest( listDeferred: List>, - uid: Any? = null + group: Any? = null ): T { val deferred = CompletableDeferred() if (listDeferred.isNullOrEmpty()) { @@ -48,7 +48,7 @@ suspend fun CoroutineScope.fastest( try { val result = it.await() mutex.withLock { - NetCancel.cancel(uid) + Net.cancelGroup(group) deferred.complete(result) } } catch (e: Exception) { @@ -72,7 +72,7 @@ suspend fun CoroutineScope.fastest( * * @see DeferredTransform 允许监听[Deferred]返回数据回调 * - * @param uid 指定该值将在成功返回结果后取消掉对应uid的网络请求 + * @param group 指定该值将在成功返回结果后取消掉对应uid的网络请求 * @param listDeferred 一系列并发任务 */ @JvmName("fastestTransform") @@ -80,7 +80,7 @@ suspend fun CoroutineScope.fastest( @Suppress("SuspendFunctionOnCoroutineScope") suspend fun CoroutineScope.fastest( listDeferred: List>?, - uid: Any? = null + group: Any? = null ): R { val deferred = CompletableDeferred() if (listDeferred.isNullOrEmpty()) { @@ -92,7 +92,7 @@ suspend fun CoroutineScope.fastest( try { val result = it.deferred.await() mutex.withLock { - NetCancel.cancel(uid) + Net.cancelGroup(group) if (!deferred.isCompleted) { val transformResult = it.block(result) deferred.complete(transformResult) diff --git a/net/src/main/java/com/drake/net/utils/FileUtils.kt b/net/src/main/java/com/drake/net/utils/FileUtils.kt new file mode 100644 index 000000000..c3678aeee --- /dev/null +++ b/net/src/main/java/com/drake/net/utils/FileUtils.kt @@ -0,0 +1,30 @@ +package com.drake.net.utils + +import java.io.File +import java.io.FileInputStream +import java.io.IOException +import java.security.DigestInputStream +import java.security.MessageDigest +import java.util.* + +/** + * 返回文件的MD5值 + */ +fun File?.md5(): String? { + this ?: return null + try { + val fileInputStream = FileInputStream(this) + val digestInputStream = DigestInputStream(fileInputStream, MessageDigest.getInstance("MD5")) + val buffer = ByteArray(1024 * 256) + digestInputStream.use { + while (true) if (digestInputStream.read(buffer) <= 0) break + } + val md5 = digestInputStream.messageDigest.digest() + val stringBuilder = StringBuilder() + for (b in md5) stringBuilder.append(String.format("%02X", b)) + return stringBuilder.toString().toLowerCase(Locale.ROOT) + } catch (e: IOException) { + e.printStackTrace() + } + return null +} \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/utils/Https.kt b/net/src/main/java/com/drake/net/utils/Https.kt new file mode 100644 index 000000000..586c773fe --- /dev/null +++ b/net/src/main/java/com/drake/net/utils/Https.kt @@ -0,0 +1,107 @@ +/* + * Copyright 2016 jeasonlzy(廖子尧) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.drake.net.utils + +import java.io.IOException +import java.io.InputStream +import java.security.KeyStore +import java.security.cert.CertificateException +import java.security.cert.CertificateFactory +import java.security.cert.X509Certificate +import javax.net.ssl.* + + +object Https { + + /** + * 此类是用于主机名验证的基接口。 在握手期间,如果 URL 的主机名和服务器的标识主机名不匹配, + * 则验证机制可以回调此接口的实现程序来确定是否应该允许此连接。策略可以是基于证书的或依赖于其他验证方案。 + * 当验证 URL 主机名使用的默认规则失败时使用这些回调。如果主机名是可接受的,则返回 true + */ + var UnSafeHostnameVerifier = HostnameVerifier { _, _ -> true } + + /** + * 为了解决客户端不信任服务器数字证书的问题,网络上大部分的解决方案都是让客户端不对证书做任何检查, + * 这是一种有很大安全漏洞的办法 + */ + var UnSafeTrustManager: X509TrustManager = object : X509TrustManager { + @Throws(CertificateException::class) + override fun checkClientTrusted(chain: Array, authType: String) { + } + + @Throws(CertificateException::class) + override fun checkServerTrusted(chain: Array, authType: String) { + } + + override fun getAcceptedIssuers(): Array { + return arrayOf() + } + } +} + +internal fun prepareKeyManager(bksFile: InputStream?, password: String?): Array? { + try { + if (bksFile == null || password == null) return null + val clientKeyStore = KeyStore.getInstance("BKS") + clientKeyStore.load(bksFile, password.toCharArray()) + val kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()) + kmf.init(clientKeyStore, password.toCharArray()) + return kmf.keyManagers + } catch (e: Exception) { + e.printStackTrace() + } + return null +} + +internal fun prepareTrustManager(vararg certificates: InputStream?): Array? { + if (certificates.isEmpty()) return null + try { + val certificateFactory = CertificateFactory.getInstance("X.509") + // 创建一个默认类型的KeyStore,存储我们信任的证书 + val keyStore = KeyStore.getInstance(KeyStore.getDefaultType()) + keyStore.load(null) + for ((index, certStream) in certificates.withIndex()) { + val certificateAlias = (index).toString() + // 证书工厂根据证书文件的流生成证书 cert + val cert = certificateFactory.generateCertificate(certStream) + // 将cert作为可信证书放入到keyStore中 + keyStore.setCertificateEntry(certificateAlias, cert) + try { + certStream?.close() + } catch (e: IOException) { + e.printStackTrace() + } + } + // 我们创建一个默认类型的TrustManagerFactory + val tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()) + // 用我们之前的keyStore实例初始化TrustManagerFactory,这样tmf就会信任keyStore中的证书 + tmf.init(keyStore) + // 通过tmf获取TrustManager数组,TrustManager也会信任keyStore中的证书 + return tmf.trustManagers + } catch (e: Exception) { + e.printStackTrace() + } + return null +} + +internal fun chooseTrustManager(trustManagers: Array): X509TrustManager? { + for (trustManager in trustManagers) { + if (trustManager is X509TrustManager) { + return trustManager + } + } + return null +} \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/utils/LazyField.kt b/net/src/main/java/com/drake/net/utils/LazyField.kt new file mode 100644 index 000000000..b5f383aea --- /dev/null +++ b/net/src/main/java/com/drake/net/utils/LazyField.kt @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2018 Drake, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.drake.net.utils + +import kotlin.properties.ReadWriteProperty +import kotlin.reflect.KProperty + +/** + * 延迟初始化 + * 线程安全 + * 等效于[lazy], 但是可以获取委托字段属性 + */ +@Suppress("UNCHECKED_CAST") +fun T.lazyField(block: T.(KProperty<*>) -> V) = object : ReadWriteProperty { + @Volatile + private var value: V? = null + override fun getValue(thisRef: T, property: KProperty<*>): V { + + return synchronized(this) { + if (value == null) { + value = block(thisRef, property) + value as V + } else value as V + } + } + + override fun setValue(thisRef: T, property: KProperty<*>, value: V) { + this.value = value + } +} \ No newline at end of file diff --git a/kalle/src/main/java/com/yanzhenjie/kalle/exception/NoCacheError.kt b/net/src/main/java/com/drake/net/utils/String.kt similarity index 74% rename from kalle/src/main/java/com/yanzhenjie/kalle/exception/NoCacheError.kt rename to net/src/main/java/com/drake/net/utils/String.kt index a2e7840dd..0855a28d5 100644 --- a/kalle/src/main/java/com/yanzhenjie/kalle/exception/NoCacheError.kt +++ b/net/src/main/java/com/drake/net/utils/String.kt @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.yanzhenjie.kalle.exception -import com.yanzhenjie.kalle.Request +package com.drake.net.utils -class NoCacheError( - request: Request, - message: String = "" -) : NetException(request, message) \ No newline at end of file +inline fun String?.isValid(block: (String) -> Unit) { + takeUnless { it.isNullOrBlank() }?.let(block) +} + +inline val String?.isValid + get() = takeUnless { it.isNullOrBlank() } \ No newline at end of file diff --git a/net/src/main/java/com/drake/net/utils/ThrottleClickListener.kt b/net/src/main/java/com/drake/net/utils/ThrottleClickListener.kt index 895e434d8..c34c1148a 100644 --- a/net/src/main/java/com/drake/net/utils/ThrottleClickListener.kt +++ b/net/src/main/java/com/drake/net/utils/ThrottleClickListener.kt @@ -19,6 +19,11 @@ package com.drake.net.utils import android.view.View import java.util.concurrent.TimeUnit +/** + * 点击事件防抖动 + * @param interval 间隔时间, 如果为500表示500毫秒内只允许触发一次点击事件 + * @param unit 时间单位 + */ internal fun View.throttleClick( interval: Long = 500, unit: TimeUnit = TimeUnit.MILLISECONDS, diff --git a/net/src/main/res/values/strings.xml b/net/src/main/res/values/strings.xml index 951d521b3..dc4575ed0 100644 --- a/net/src/main/res/values/strings.xml +++ b/net/src/main/res/values/strings.xml @@ -21,25 +21,24 @@ 当前网络不可用 请求资源地址错误 无法找到指定服务器主机 - 连接服务器超时,请重试 - 请检查网络连接 - 读取数据错误 - 发送数据错误 - 读取服务器数据超时,请检查网络 + 连接服务器超时,%s 下载过程发生错误 读取缓存错误 解析数据时发生异常 请求参数错误 服务响应错误 - 图片下载错误 数据为空 未知网络错误 未知错误 + 无错误信息 + + + + + + 加载中 - - - diff --git a/sample/build.gradle b/sample/build.gradle index f4d4bcae4..3abb82eb4 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -18,6 +18,7 @@ apply plugin: "com.android.application" apply plugin: "kotlin-android" apply plugin: "kotlin-android-extensions" apply plugin: "kotlin-kapt" +apply plugin: 'kotlinx-serialization' android { compileSdkVersion 30 @@ -62,27 +63,30 @@ dependencies { testImplementation "junit:junit:4.13.2" androidTestImplementation "androidx.test:runner:1.3.0" androidTestImplementation "androidx.test.espresso:espresso-core:3.3.0" - implementation "androidx.recyclerview:recyclerview:1.1.0" + implementation "androidx.recyclerview:recyclerview:1.2.0" implementation "com.google.android.material:material:1.3.0" - implementation 'androidx.navigation:navigation-fragment-ktx:2.3.4' - implementation 'androidx.navigation:navigation-ui-ktx:2.3.4' + implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5' + implementation 'androidx.navigation:navigation-ui-ktx:2.3.5' implementation project(path: ":net") + implementation "com.squareup.okhttp3:okhttp:$okhttp_version" // ------------------------------配合Net使用的库------------------------------------- implementation "com.github.liangjingkanji:BRV:$brv_version" // 提供自动分页/缺省页/自动下拉刷新功能 - implementation "com.github.bumptech.glide:glide:$glide_version" // 提供下载图片功能 implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutine_version" // 协程基础库 implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine_version" + // ------------------------------JSON解析------------------------------------- implementation "com.squareup.moshi:moshi-kotlin:1.8.0" kapt "com.squareup.moshi:moshi-kotlin-codegen:1.8.0" implementation 'com.google.code.gson:gson:2.8.6' - implementation 'com.alibaba:fastjson:1.2.48' + implementation 'com.alibaba:fastjson:1.2.73' + implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.0" - // ------------------------------我的其他库------------------------------------- - implementation 'com.github.liangjingkanji:StatusBar:1.1.0' // 透明状态栏 + // ------------------------------其他库------------------------------------- + implementation "com.github.bumptech.glide:glide:$glide_version" // 提供下载图片功能 + implementation 'com.github.liangjingkanji:StatusBar:1.1.1' // 透明状态栏 implementation 'com.github.liangjingkanji:debugkit:1.2.10' // 开发调试窗口工具 implementation 'com.github.liangjingkanji:Tooltip:1.1.0' // 吐司工具 diff --git a/sample/src/main/assets/upload_file.jpg b/sample/src/main/assets/upload_file.jpg old mode 100755 new mode 100644 index 2e023b9b9..6ac808d47 Binary files a/sample/src/main/assets/upload_file.jpg and b/sample/src/main/assets/upload_file.jpg differ diff --git a/sample/src/main/java/com/drake/net/sample/base/App.kt b/sample/src/main/java/com/drake/net/sample/base/App.kt index ff0555063..7a55d52fb 100644 --- a/sample/src/main/java/com/drake/net/sample/base/App.kt +++ b/sample/src/main/java/com/drake/net/sample/base/App.kt @@ -17,15 +17,18 @@ package com.drake.net.sample.base import android.app.Application -import com.drake.net.cacheEnabled +import android.app.ProgressDialog +import com.drake.brv.BindingAdapter import com.drake.net.initNet -import com.drake.net.logEnabled +import com.drake.net.interceptor.LogRecordInterceptor +import com.drake.net.interceptor.RequestInterceptor +import com.drake.net.okhttp.onDialog +import com.drake.net.okhttp.setLog +import com.drake.net.okhttp.setRequestInterceptor +import com.drake.net.request.BaseRequest import com.drake.net.sample.BR import com.drake.net.sample.BuildConfig import com.drake.net.sample.R -import com.drake.net.sample.convert.MoshiConvert -import com.drake.net.sample.interceptor.DynamicParameterInterceptor -import com.drake.net.sample.interceptor.NetTagInterceptor import com.drake.statelayout.StateConfig import com.scwang.smart.refresh.footer.ClassicsFooter import com.scwang.smart.refresh.header.MaterialHeader @@ -36,6 +39,32 @@ class App : Application() { override fun onCreate() { super.onCreate() + initNet("http://43.128.31.195/") { + + setLog(BuildConfig.DEBUG) // LogCat异常日志 + addInterceptor(LogRecordInterceptor(BuildConfig.DEBUG)) // 添加日志记录器 + + setRequestInterceptor(object : RequestInterceptor { // 添加请求拦截器 + override fun interceptor(request: BaseRequest) { + request.param("client", "Net") + request.setHeader("token", "123456") + } + }) + + onDialog { // 全局加载对话框 + ProgressDialog(it).apply { + setMessage("我是全局自定义的加载对话框...") + } + } + } + initDependent() + } + + /** + * 初始化Net的可选附属库 + */ + private fun initDependent() { + // 全局缺省页配置 [https://github.com/liangjingkanji/StateLayout] StateConfig.apply { emptyLayout = R.layout.layout_empty @@ -43,24 +72,17 @@ class App : Application() { errorLayout = R.layout.layout_error } - initNet("http://43.128.31.195/") { - converter(MoshiConvert()) // 自动解析JSON映射到实体类中, 转换器分为全局和单例, 覆盖生效(拦截器允许多个) - cacheEnabled() - addInterceptor(NetTagInterceptor()) - addInterceptor(DynamicParameterInterceptor()) - setLogRecord(BuildConfig.DEBUG) // 日志记录器 - logEnabled = BuildConfig.DEBUG // LogCat异常日志 - } // 初始化SmartRefreshLayout, 这是自动下拉刷新和上拉加载采用的第三方库 [https://github.com/scwang90/SmartRefreshLayout/tree/master] V2版本 SmartRefreshLayout.setDefaultRefreshHeaderCreator { context, _ -> MaterialHeader(context) } + SmartRefreshLayout.setDefaultRefreshFooterCreator { context, _ -> ClassicsFooter(context) } - com.drake.brv.BindingAdapter.modelId = BR.m - + BindingAdapter.modelId = BR.m } -} \ No newline at end of file +} + diff --git a/sample/src/main/java/com/drake/net/sample/convert/FastJsonConvert.kt b/sample/src/main/java/com/drake/net/sample/convert/FastJsonConvert.kt index 46389e6d7..033fc56cf 100644 --- a/sample/src/main/java/com/drake/net/sample/convert/FastJsonConvert.kt +++ b/sample/src/main/java/com/drake/net/sample/convert/FastJsonConvert.kt @@ -17,13 +17,12 @@ package com.drake.net.sample.convert import com.alibaba.fastjson.JSON -import com.drake.net.convert.DefaultConvert +import com.drake.net.convert.JSONConvert import java.lang.reflect.Type -class FastJsonConvert : DefaultConvert(code = "code", message = "msg", success = "200") { +class FastJsonConvert : JSONConvert(code = "code", message = "msg", success = "200") { override fun String.parseBody(succeed: Type): S? { - return JSON.parseObject(this, succeed) } } \ No newline at end of file diff --git a/sample/src/main/java/com/drake/net/sample/convert/GsonConvert.kt b/sample/src/main/java/com/drake/net/sample/convert/GsonConvert.kt index 612615dc6..9ba001f88 100644 --- a/sample/src/main/java/com/drake/net/sample/convert/GsonConvert.kt +++ b/sample/src/main/java/com/drake/net/sample/convert/GsonConvert.kt @@ -16,12 +16,12 @@ package com.drake.net.sample.convert -import com.drake.net.convert.DefaultConvert +import com.drake.net.convert.JSONConvert import com.google.gson.GsonBuilder import java.lang.reflect.Type -class GsonConvert : DefaultConvert(code = "code", message = "msg", success = "200") { - val gson = GsonBuilder().serializeNulls().create() +class GsonConvert : JSONConvert(code = "code", message = "msg", success = "200") { + private val gson = GsonBuilder().serializeNulls().create() override fun String.parseBody(succeed: Type): S? { return gson.fromJson(this, succeed) diff --git a/sample/src/main/java/com/drake/net/sample/convert/MoshiConvert.kt b/sample/src/main/java/com/drake/net/sample/convert/MoshiConvert.kt index d40187c01..b94b0d3a0 100644 --- a/sample/src/main/java/com/drake/net/sample/convert/MoshiConvert.kt +++ b/sample/src/main/java/com/drake/net/sample/convert/MoshiConvert.kt @@ -16,15 +16,14 @@ package com.drake.net.sample.convert -import com.drake.net.convert.DefaultConvert +import com.drake.net.convert.JSONConvert import com.squareup.moshi.Moshi import java.lang.reflect.Type -class MoshiConvert : DefaultConvert(code = "code", message = "msg", success = "200") { - val moshi = Moshi.Builder().build() +class MoshiConvert : JSONConvert(code = "code", message = "msg", success = "200") { + private val moshi = Moshi.Builder().build() override fun String.parseBody(succeed: Type): S? { - return moshi.adapter(succeed).fromJson(this) } } \ No newline at end of file diff --git a/sample/src/main/java/com/drake/net/sample/interceptor/DynamicParameterInterceptor.kt b/sample/src/main/java/com/drake/net/sample/interceptor/DynamicParameterInterceptor.kt deleted file mode 100644 index 06396fb60..000000000 --- a/sample/src/main/java/com/drake/net/sample/interceptor/DynamicParameterInterceptor.kt +++ /dev/null @@ -1,38 +0,0 @@ -package com.drake.net.sample.interceptor - -import com.yanzhenjie.kalle.RequestMethod -import com.yanzhenjie.kalle.Response -import com.yanzhenjie.kalle.connect.Interceptor -import com.yanzhenjie.kalle.connect.http.Chain -import com.yanzhenjie.kalle.simple.SimpleBodyRequest -import com.yanzhenjie.kalle.simple.SimpleUrlRequest - -class DynamicParameterInterceptor : Interceptor { - override fun intercept(chain: Chain): Response { - var request = chain.request() - - // 除非是Download*函数否则都仅有两种Request: SimpleBodyRequest/SimpleUrlRequest - request = when (request.method()) { - RequestMethod.POST -> { - val copyParams = - request.copyParams().builder().add("token", "dsgfahfty1231").build() // 添加一个参数 - SimpleBodyRequest.newBuilder(request.url(), request.method()) - .setParams(copyParams) - .setHeaders(request.headers()) - .tag(request.tag()) - .build() - } - RequestMethod.GET -> { - val copyParams = - request.copyParams().builder().add("ip", "127.0.0.1").build() - SimpleUrlRequest.newBuilder(request.url(), request.method()) - .setParams(copyParams) - .setHeaders(request.headers()) - .tag(request.tag()) - .build() - } - else -> request - } - return chain.proceed(request) - } -} \ No newline at end of file diff --git a/sample/src/main/java/com/drake/net/sample/interceptor/NetTagInterceptor.kt b/sample/src/main/java/com/drake/net/sample/interceptor/NetTagInterceptor.kt deleted file mode 100644 index 3f01bd0fc..000000000 --- a/sample/src/main/java/com/drake/net/sample/interceptor/NetTagInterceptor.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@file:Suppress("ControlFlowWithEmptyBody") - -package com.drake.net.sample.interceptor - -import com.drake.net.tag.REQUEST -import com.drake.net.tag.RESPONSE -import com.drake.net.tag.TAG -import com.yanzhenjie.kalle.Response -import com.yanzhenjie.kalle.connect.Interceptor -import com.yanzhenjie.kalle.connect.http.Chain - -class NetTagInterceptor : Interceptor { - override fun intercept(chain: Chain): Response { - val request = chain.request() - - val tag = request.tag() as? TAG - - tag?.let { - if (it.contains(REQUEST)) { - // 可以打印响应体或者其他逻辑 - } - - if (it.contains(RESPONSE)) { - // 可以打印请求体或者其他逻辑 - } - } - - return chain.proceed(request) - } -} \ No newline at end of file diff --git a/sample/src/main/java/com/drake/net/sample/model/BaseResult.kt b/sample/src/main/java/com/drake/net/sample/model/BaseResult.kt new file mode 100644 index 000000000..7eb8e1b55 --- /dev/null +++ b/sample/src/main/java/com/drake/net/sample/model/BaseResult.kt @@ -0,0 +1,7 @@ +package com.drake.net.sample.model + +open class BaseResult { + var code: Int = 0 + var msg: String = "" + var data: T? = null +} \ No newline at end of file diff --git a/sample/src/main/java/com/drake/net/sample/mod/ListModel.kt b/sample/src/main/java/com/drake/net/sample/model/ListModel.kt similarity index 95% rename from sample/src/main/java/com/drake/net/sample/mod/ListModel.kt rename to sample/src/main/java/com/drake/net/sample/model/ListModel.kt index e36276662..5d0f37e19 100644 --- a/sample/src/main/java/com/drake/net/sample/mod/ListModel.kt +++ b/sample/src/main/java/com/drake/net/sample/model/ListModel.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.drake.net.sample.mod +package com.drake.net.sample.model data class ListModel(var code: Int, var msg: String, var data: Data) { data class Data(var total: Int, var list: List) diff --git a/sample/src/main/java/com/drake/net/sample/mod/Model.kt b/sample/src/main/java/com/drake/net/sample/model/Model.kt similarity index 95% rename from sample/src/main/java/com/drake/net/sample/mod/Model.kt rename to sample/src/main/java/com/drake/net/sample/model/Model.kt index 9bdd27488..b102a242e 100644 --- a/sample/src/main/java/com/drake/net/sample/mod/Model.kt +++ b/sample/src/main/java/com/drake/net/sample/model/Model.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.drake.net.sample.mod +package com.drake.net.sample.model data class Model(var code: Int, var msg: String, var data: Data) { data class Data(var request_method: String) diff --git a/sample/src/main/java/com/drake/net/sample/model/Result.kt b/sample/src/main/java/com/drake/net/sample/model/Result.kt new file mode 100644 index 000000000..154b66f3b --- /dev/null +++ b/sample/src/main/java/com/drake/net/sample/model/Result.kt @@ -0,0 +1,3 @@ +package com.drake.net.sample.model + +class Result(var request_method: String) : BaseResult() \ No newline at end of file diff --git a/sample/src/main/java/com/drake/net/sample/model/UserViewModel.kt b/sample/src/main/java/com/drake/net/sample/model/UserViewModel.kt new file mode 100644 index 000000000..c3790deb4 --- /dev/null +++ b/sample/src/main/java/com/drake/net/sample/model/UserViewModel.kt @@ -0,0 +1,19 @@ +package com.drake.net.sample.model + +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import androidx.lifecycle.scopeNetLife +import com.drake.net.Get + +class UserViewModel : ViewModel() { + + // 用户信息 + var userInfo: MutableLiveData = MutableLiveData() + + /** + * 拉取用户信息, 会自动通知页面更新, 同时页面销毁会自动取消网络请求 + */ + fun fetchUserInfo() = scopeNetLife { + userInfo.value = Get("api").await() + } +} \ No newline at end of file diff --git a/sample/src/main/java/com/drake/net/sample/ui/fragment/CustomConvertFragment.kt b/sample/src/main/java/com/drake/net/sample/ui/fragment/CustomConvertFragment.kt index 56704251d..57b53b2bf 100644 --- a/sample/src/main/java/com/drake/net/sample/ui/fragment/CustomConvertFragment.kt +++ b/sample/src/main/java/com/drake/net/sample/ui/fragment/CustomConvertFragment.kt @@ -22,7 +22,7 @@ import androidx.fragment.app.Fragment import com.drake.net.Get import com.drake.net.sample.R import com.drake.net.sample.convert.GsonConvert -import com.drake.net.sample.mod.Model +import com.drake.net.sample.model.Model import com.drake.net.utils.scopeNetLife import kotlinx.android.synthetic.main.fragment_custom_convert.* @@ -32,7 +32,7 @@ class CustomConvertFragment : Fragment(R.layout.fragment_custom_convert) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { scopeNetLife { tv_fragment.text = Get("api") { - converter(GsonConvert()) // 单例转换器, 此时会忽略全局转换器 + converter = GsonConvert() // 单例转换器, 此时会忽略全局转换器 }.await().data.request_method } } diff --git a/sample/src/main/java/com/drake/net/sample/ui/fragment/DownloadFileFragment.kt b/sample/src/main/java/com/drake/net/sample/ui/fragment/DownloadFileFragment.kt index 48362dd51..6d62638f9 100644 --- a/sample/src/main/java/com/drake/net/sample/ui/fragment/DownloadFileFragment.kt +++ b/sample/src/main/java/com/drake/net/sample/ui/fragment/DownloadFileFragment.kt @@ -17,41 +17,53 @@ package com.drake.net.sample.ui.fragment import android.os.Bundle -import android.text.format.Formatter +import android.util.Log import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import android.view.View import androidx.fragment.app.Fragment -import com.drake.net.Download +import com.drake.net.Get +import com.drake.net.component.Progress +import com.drake.net.interfaces.ProgressListener import com.drake.net.sample.R import com.drake.net.scope.NetCoroutineScope import com.drake.net.utils.scopeNetLife import kotlinx.android.synthetic.main.fragment_download_file.* +import java.io.File +import kotlin.time.ExperimentalTime class DownloadFileFragment : Fragment(R.layout.fragment_download_file) { private lateinit var downloadScope: NetCoroutineScope + @ExperimentalTime override fun onViewCreated(view: View, savedInstanceState: Bundle?) { setHasOptionsMenu(true) - downloadScope = scopeNetLife { - val filePath = Download("download", requireContext().filesDir.path) { - // 下载进度回调 - onProgress { progress, byteCount, speed -> - // 进度条 - seek.progress = progress - - // 格式化显示单位 - val downloadSize = Formatter.formatFileSize(requireContext(), byteCount) - val downloadSpeed = Formatter.formatFileSize(requireContext(), speed) - // 显示下载信息 - tv_progress.text = "下载进度: $progress% 已下载: $downloadSize 下载速度: $downloadSpeed" - } - }.await() + downloadScope = scopeNetLife { + val file = + Get("https://download.sublimetext.com/Sublime%20Text%20Build%203211.dmg") { + setDownloadFileName("net.apk") + setDownloadDir(requireContext().filesDir) + setDownloadMd5Verify() + setDownloadTempFile() + addDownloadListener(object : ProgressListener() { + override fun onProgress(p: Progress) { + Log.d("日志", "(DownloadFileFragment.kt:52) p = ${p}") + seek?.post { + val progress = p.progress() + seek.progress = progress + tv_progress.text = + "下载进度: $progress% 下载速度: ${p.speedSize()} " + + "\n\n文件大小: ${p.totalSize()} 已下载: ${p.currentSize()} 剩余大小: ${p.remainSize()}" + + "\n\n已使用时间: ${p.useTime()} 剩余时间: ${p.remainTime()}" + } + } + }) + }.await() } } diff --git a/sample/src/main/java/com/drake/net/sample/ui/fragment/DownloadImageFragment.kt b/sample/src/main/java/com/drake/net/sample/ui/fragment/DownloadImageFragment.kt deleted file mode 100644 index 87f406d06..000000000 --- a/sample/src/main/java/com/drake/net/sample/ui/fragment/DownloadImageFragment.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2018 Drake, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.drake.net.sample.ui.fragment - -import android.net.Uri -import android.os.Bundle -import android.view.View -import androidx.fragment.app.Fragment -import com.drake.net.DownloadImage -import com.drake.net.NetConfig -import com.drake.net.sample.R -import com.drake.net.utils.scopeDialog -import kotlinx.android.synthetic.main.fragment_download_image.* - - -class DownloadImageFragment : Fragment(R.layout.fragment_download_image) { - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - scopeDialog { - val file = DownloadImage(NetConfig.host + "download/img", 100, 100).await() - val uri = Uri.fromFile(file) - iv_img.setImageURI(uri) - } - } -} diff --git a/sample/src/main/java/com/drake/net/sample/ui/fragment/EditDebounceFragment.kt b/sample/src/main/java/com/drake/net/sample/ui/fragment/EditDebounceFragment.kt index 2cfdaaa90..51e902967 100644 --- a/sample/src/main/java/com/drake/net/sample/ui/fragment/EditDebounceFragment.kt +++ b/sample/src/main/java/com/drake/net/sample/ui/fragment/EditDebounceFragment.kt @@ -23,8 +23,7 @@ class EditDebounceFragment : Fragment(R.layout.fragment_edit_debounce) { scope?.cancel() // 发起新的请求前取消旧的请求, 避免旧数据覆盖新数据 scope = scopeNetLife { // 保存旧的请求到一个变量中 tv_request_content.text = "请求中" - val data = Get("http://api.k780.com/?app=life.time&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json", - absolutePath = true).await() + val data = Get("http://api.k780.com/?app=life.time&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json").await() tv_request_content.text = JSONObject(data).getJSONObject("result").getString("datetime_2") } } diff --git a/sample/src/main/java/com/drake/net/sample/ui/fragment/EnqueueRequestFragment.kt b/sample/src/main/java/com/drake/net/sample/ui/fragment/EnqueueRequestFragment.kt new file mode 100644 index 000000000..2a0f615a7 --- /dev/null +++ b/sample/src/main/java/com/drake/net/sample/ui/fragment/EnqueueRequestFragment.kt @@ -0,0 +1,35 @@ +package com.drake.net.sample.ui.fragment + +import android.os.Bundle +import android.view.View +import androidx.fragment.app.Fragment +import com.drake.net.Net +import com.drake.net.interfaces.NetCallback +import com.drake.net.sample.R +import kotlinx.android.synthetic.main.fragment_fastest.* +import okhttp3.Call + +class EnqueueRequestFragment : Fragment(R.layout.fragment_enqueue_request) { + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + + // Net同样支持OkHttp的队列任务 + + // Net.post("api").enqueue(object : Callback { + // override fun onFailure(call: Call, e: IOException) { + // } + // + // override fun onResponse(call: Call, response: Response) { + // } + // }) + + // NetCallback支持数据转换 + Net.post("api") { + param("password", "Net123") + }.enqueue(object : NetCallback() { + override fun onSuccess(call: Call, data: String) { + tv_fragment.text = data // onSuccess 属于主线程 + } + }) + } +} \ No newline at end of file diff --git a/sample/src/main/java/com/drake/net/sample/ui/fragment/ExceptionTraceFragment.kt b/sample/src/main/java/com/drake/net/sample/ui/fragment/ExceptionTraceFragment.kt index 42ea93540..4c367be47 100644 --- a/sample/src/main/java/com/drake/net/sample/ui/fragment/ExceptionTraceFragment.kt +++ b/sample/src/main/java/com/drake/net/sample/ui/fragment/ExceptionTraceFragment.kt @@ -29,8 +29,8 @@ class ExceptionTraceFragment : Fragment(R.layout.fragment_exception_trace) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { scopeNetLife { - // 这是一个错误的地址, 请查看LogCat的错误信息, 在[Convert]中你也可以进行自定义错误信息打印 - tv_fragment.text = Get("error").await() + // 这是一个错误的地址, 请查看LogCat的错误信息, 在[initNet]函数中的[onError]回调中你也可以进行自定义错误信息打印 + tv_fragment.text = Get("https://githuberror.com/liangjingkanji/Net/").await() } } diff --git a/sample/src/main/java/com/drake/net/sample/ui/fragment/FastestFragment.kt b/sample/src/main/java/com/drake/net/sample/ui/fragment/FastestFragment.kt index 25f40dd19..8b54cb1da 100644 --- a/sample/src/main/java/com/drake/net/sample/ui/fragment/FastestFragment.kt +++ b/sample/src/main/java/com/drake/net/sample/ui/fragment/FastestFragment.kt @@ -36,10 +36,10 @@ class FastestFragment : Fragment(R.layout.fragment_fastest) { */ // 同时发起四个网络请求 - val deferred2 = Get("api", uid = "最快") - val deferred3 = Post("api", uid = "最快") - val deferred = Get("api0", uid = "最快") // 错误接口 - val deferred1 = Get("api1", uid = "最快") // 错误接口 + val deferred2 = Get("api") { setGroup("最快") } + val deferred3 = Post("api") { setGroup("最快") } + val deferred = Get("api0") { setGroup("最快") } // 错误接口 + val deferred1 = Get("api1") { setGroup("最快") } // 错误接口 // 只返回最快的请求结果 tv_fragment.text = fastest(listOf(deferred, deferred1, deferred2, deferred3), "最快") diff --git a/sample/src/main/java/com/drake/net/sample/ui/fragment/HttpsCertificateFragment.kt b/sample/src/main/java/com/drake/net/sample/ui/fragment/HttpsCertificateFragment.kt new file mode 100644 index 000000000..4e53008b3 --- /dev/null +++ b/sample/src/main/java/com/drake/net/sample/ui/fragment/HttpsCertificateFragment.kt @@ -0,0 +1,48 @@ +package com.drake.net.sample.ui.fragment + +import android.os.Bundle +import android.view.View +import androidx.fragment.app.Fragment +import com.drake.net.Get +import com.drake.net.okhttp.setSSLCertificate +import com.drake.net.sample.R +import com.drake.net.utils.scopeNetLife +import com.drake.tooltip.toast +import kotlinx.android.synthetic.main.fragment_https_certificate.* +import okhttp3.OkHttpClient + +class HttpsCertificateFragment : Fragment(R.layout.fragment_https_certificate) { + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + btn_trust_certificate.setOnClickListener(this::trustAllCertificate) + btn_import_certificate.setOnClickListener(this::importCertificate) + } + + /** + * 信任全部证书 + */ + fun trustAllCertificate(view: View) { + scopeNetLife { + tv_response.text = Get("https://github.com/") { + okHttpClient = OkHttpClient.Builder().build() + }.await() + } + } + + /** + * 导入私有证书 + */ + fun importCertificate(view: View) { + scopeNetLife { + Get("https://github.com/") { + setClient { + val privateCertificate = resources.assets.open("https.certificate") + setSSLCertificate(privateCertificate) + } + }.await() + }.catch { + toast("作者没有证书, 只是演示代码, O(∩_∩)O哈哈~") + } + } + +} \ No newline at end of file diff --git a/sample/src/main/java/com/drake/net/sample/ui/fragment/PullRefreshFragment.kt b/sample/src/main/java/com/drake/net/sample/ui/fragment/PullRefreshFragment.kt index 5fc5567da..040f9a004 100644 --- a/sample/src/main/java/com/drake/net/sample/ui/fragment/PullRefreshFragment.kt +++ b/sample/src/main/java/com/drake/net/sample/ui/fragment/PullRefreshFragment.kt @@ -21,10 +21,7 @@ import android.view.View import androidx.fragment.app.Fragment import com.drake.brv.utils.linear import com.drake.brv.utils.setup -import com.drake.net.Get import com.drake.net.sample.R -import com.drake.net.sample.mod.ListModel -import com.drake.net.utils.scope import kotlinx.android.synthetic.main.fragment_pull_refresh.* @@ -35,16 +32,16 @@ class PullRefreshFragment : Fragment(R.layout.fragment_pull_refresh) { addType(R.layout.item_list) } - page.onRefresh { - scope { - val data = Get("list") { - param("page", index) - }.await().data - addData(data.list) { - index < data.total - } - } - }.autoRefresh() + // page.onRefresh { + // scope { + // val data = Get("list") { + // param("page", index) + // }.await().data + // addData(data.list) { + // index < data.total + // } + // } + // }.autoRefresh() } } diff --git a/sample/src/main/java/com/drake/net/sample/ui/fragment/PushRefreshFragment.kt b/sample/src/main/java/com/drake/net/sample/ui/fragment/PushRefreshFragment.kt index f2b830f42..fbd5d2196 100644 --- a/sample/src/main/java/com/drake/net/sample/ui/fragment/PushRefreshFragment.kt +++ b/sample/src/main/java/com/drake/net/sample/ui/fragment/PushRefreshFragment.kt @@ -20,11 +20,8 @@ import android.os.Bundle import android.view.View import androidx.fragment.app.Fragment import com.drake.brv.utils.linear -import com.drake.brv.utils.models import com.drake.brv.utils.setup -import com.drake.net.Get import com.drake.net.sample.R -import com.drake.net.sample.mod.ListModel import com.drake.net.utils.scope import kotlinx.android.synthetic.main.fragment_push_refresh.* @@ -38,7 +35,7 @@ class PushRefreshFragment : Fragment(R.layout.fragment_push_refresh) { page.onRefresh { scope { - rv_push.models = Get("list").await().data.list + // rv_push.models = Get("list").await().data.list } }.autoRefresh() } diff --git a/sample/src/main/java/com/drake/net/sample/ui/fragment/ReadCacheFragment.kt b/sample/src/main/java/com/drake/net/sample/ui/fragment/ReadCacheFragment.kt index 7d534ab09..ce313e68e 100644 --- a/sample/src/main/java/com/drake/net/sample/ui/fragment/ReadCacheFragment.kt +++ b/sample/src/main/java/com/drake/net/sample/ui/fragment/ReadCacheFragment.kt @@ -24,7 +24,6 @@ import com.drake.net.Get import com.drake.net.Post import com.drake.net.sample.R import com.drake.net.utils.scopeNetLife -import com.yanzhenjie.kalle.simple.cache.CacheMode import kotlinx.android.synthetic.main.fragment_read_cache.* @@ -34,11 +33,11 @@ class ReadCacheFragment : Fragment(R.layout.fragment_read_cache) { scopeNetLife { // 然后执行这里(网络请求) tv_fragment.text = - Post("api", cache = CacheMode.NETWORK_YES_THEN_WRITE_CACHE).await() + Post("api").await() Log.d("日志", "网络请求") }.preview { // 先执行这里(仅读缓存), 任何异常都视为读取缓存失败 - tv_fragment.text = Get("api", cache = CacheMode.READ_CACHE).await() + tv_fragment.text = Get("api").await() Log.d("日志", "读取缓存") } } diff --git a/sample/src/main/java/com/drake/net/sample/ui/fragment/RequestMethodFragment.kt b/sample/src/main/java/com/drake/net/sample/ui/fragment/RequestMethodFragment.kt index 53ea5faa2..afac2beb0 100644 --- a/sample/src/main/java/com/drake/net/sample/ui/fragment/RequestMethodFragment.kt +++ b/sample/src/main/java/com/drake/net/sample/ui/fragment/RequestMethodFragment.kt @@ -34,6 +34,8 @@ class RequestMethodFragment : Fragment(R.layout.fragment_request_method) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { setHasOptionsMenu(true) + + GET() } private fun GET() { @@ -64,6 +66,8 @@ class RequestMethodFragment : Fragment(R.layout.fragment_request_method) { scopeNetLife { tv_fragment.text = Patch("api").await() } + + arrayOf(1).toMutableList() } private fun DELETE() { @@ -121,11 +125,11 @@ class RequestMethodFragment : Fragment(R.layout.fragment_request_method) { R.id.get -> GET() R.id.post -> POST() R.id.head -> HEAD() - R.id.put -> PUT() - R.id.patch -> PATCH() - R.id.delete -> DELETE() R.id.trace -> TRACE() R.id.options -> OPTIONS() + R.id.delete -> DELETE() + R.id.put -> PUT() + R.id.patch -> PATCH() R.id.json -> JSON() } return super.onOptionsItemSelected(item) diff --git a/sample/src/main/java/com/drake/net/sample/ui/fragment/SyncRequestFragment.kt b/sample/src/main/java/com/drake/net/sample/ui/fragment/SyncRequestFragment.kt new file mode 100644 index 000000000..5c102bcfb --- /dev/null +++ b/sample/src/main/java/com/drake/net/sample/ui/fragment/SyncRequestFragment.kt @@ -0,0 +1,22 @@ +package com.drake.net.sample.ui.fragment + +import android.os.Bundle +import android.view.View +import androidx.fragment.app.Fragment +import com.drake.net.Net +import com.drake.net.sample.R +import kotlinx.android.synthetic.main.fragment_sync_request.* +import kotlin.concurrent.thread + +class SyncRequestFragment : Fragment(R.layout.fragment_sync_request) { + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + + thread { + val result = Net.post("api").execute() // 网络请求不允许在主线程 + tv_fragment?.post { + tv_fragment?.text = result // view要求在主线程更新 + } + } + } +} \ No newline at end of file diff --git a/sample/src/main/java/com/drake/net/sample/ui/fragment/UploadFileFragment.kt b/sample/src/main/java/com/drake/net/sample/ui/fragment/UploadFileFragment.kt index 00c9517cb..1f6561957 100644 --- a/sample/src/main/java/com/drake/net/sample/ui/fragment/UploadFileFragment.kt +++ b/sample/src/main/java/com/drake/net/sample/ui/fragment/UploadFileFragment.kt @@ -20,54 +20,45 @@ import android.os.Bundle import android.view.View import androidx.fragment.app.Fragment import com.drake.net.Post +import com.drake.net.component.Progress +import com.drake.net.interfaces.ProgressListener import com.drake.net.sample.R import com.drake.net.utils.scopeNetLife -import com.yanzhenjie.kalle.FormBody import kotlinx.android.synthetic.main.fragment_upload_file.* +import okio.buffer +import okio.sink +import okio.source import java.io.File -import java.io.FileOutputStream class UploadFileFragment : Fragment(R.layout.fragment_upload_file) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { scopeNetLife { - Post("upload") { - val saveFile = getFile() - val form = FormBody.newBuilder().file("file", saveFile).build() - - form.onProgress { origin, progress -> - - seek.progress = progress // 进度条 - // 格式化显示单位 - val downloadSize = - android.text.format.Formatter.formatFileSize(requireContext(), 23) - val downloadSpeed = - android.text.format.Formatter.formatFileSize(requireContext(), 23) - - // 显示下载信息 - tv_progress.text = "上传进度: $progress% 已下载: $downloadSize 下载速度: $downloadSpeed" - } - - body(form) - + Post("https://download.sublimetext.com/Sublime%20Text%20Build%203211.dmg") { + param("file", assetsFile()) + addUploadListener(object : ProgressListener() { + override fun onProgress(p: Progress) { + seek.post { + seek.progress = p.progress() + tv_progress.text = + "上传进度: ${p.progress()}% 上传速度: ${p.speedSize()} " + + "\n\n文件大小: ${p.totalSize()} 已上传: ${p.currentSize()} 剩余大小: ${p.remainSize()}" + + "\n\n已使用时间: ${p.useTime()} 剩余时间: ${p.remainTime()}" + } + } + }) }.await() } } - /** - * @return 上传的文件 - */ - private fun getFile(): File { - val open = resources.assets.open("upload_file.jpg") - val saveFile = File("${requireContext().filesDir.path}/upload_file.jpg") - val buffer = ByteArray(open.available()) - open.read(buffer) - val fileOutputStream = FileOutputStream(saveFile) - fileOutputStream.write(buffer) - open.close() - fileOutputStream.close() - return saveFile + private fun assetsFile(): File { + val fileName = "upload_file.jpg" + val inputStream = resources.assets.open(fileName) + val file = File(requireContext().filesDir.path, fileName) + inputStream.source().buffer().use { + it.readAll(file.sink()) + } + return file } - } diff --git a/sample/src/main/java/com/drake/net/sample/ui/fragment/ViewModelRequestFragment.kt b/sample/src/main/java/com/drake/net/sample/ui/fragment/ViewModelRequestFragment.kt new file mode 100644 index 000000000..98e0151d7 --- /dev/null +++ b/sample/src/main/java/com/drake/net/sample/ui/fragment/ViewModelRequestFragment.kt @@ -0,0 +1,30 @@ +package com.drake.net.sample.ui.fragment + +import android.os.Bundle +import android.view.View +import androidx.databinding.DataBindingUtil +import androidx.fragment.app.Fragment +import androidx.fragment.app.viewModels +import com.drake.net.sample.R +import com.drake.net.sample.databinding.FragmentViewModelRequestBinding +import com.drake.net.sample.model.UserViewModel +import kotlinx.android.synthetic.main.fragment_view_model_request.* + +class ViewModelRequestFragment : Fragment(R.layout.fragment_view_model_request) { + + + val userViewModel: UserViewModel by viewModels() // 创建ViewModel + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + + // 绑定DataBinding + val bind = DataBindingUtil.bind(view)!! + bind.lifecycleOwner = this + bind.m = userViewModel + + // 动作开始拉取服务器数据 + btn_fetch_userinfo.setOnClickListener { + userViewModel.fetchUserInfo() + } + } +} \ No newline at end of file diff --git a/sample/src/main/res/drawable/ic_download_img.xml b/sample/src/main/res/drawable/ic_download_img.xml deleted file mode 100644 index 93155e840..000000000 --- a/sample/src/main/res/drawable/ic_download_img.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - diff --git a/sample/src/main/res/drawable/ic_enqueue_request.xml b/sample/src/main/res/drawable/ic_enqueue_request.xml new file mode 100644 index 000000000..c90c677b5 --- /dev/null +++ b/sample/src/main/res/drawable/ic_enqueue_request.xml @@ -0,0 +1,10 @@ + + + diff --git a/sample/src/main/res/drawable/ic_https.xml b/sample/src/main/res/drawable/ic_https.xml new file mode 100644 index 000000000..b8332de63 --- /dev/null +++ b/sample/src/main/res/drawable/ic_https.xml @@ -0,0 +1,10 @@ + + + diff --git a/sample/src/main/res/drawable/ic_sync_request.xml b/sample/src/main/res/drawable/ic_sync_request.xml new file mode 100644 index 000000000..cf2f91e87 --- /dev/null +++ b/sample/src/main/res/drawable/ic_sync_request.xml @@ -0,0 +1,10 @@ + + + diff --git a/sample/src/main/res/drawable/ic_view_model.xml b/sample/src/main/res/drawable/ic_view_model.xml new file mode 100644 index 000000000..aeffac259 --- /dev/null +++ b/sample/src/main/res/drawable/ic_view_model.xml @@ -0,0 +1,10 @@ + + + diff --git a/sample/src/main/res/layout/fragment_download_file.xml b/sample/src/main/res/layout/fragment_download_file.xml index 6ed72f24c..d3198dca4 100644 --- a/sample/src/main/res/layout/fragment_download_file.xml +++ b/sample/src/main/res/layout/fragment_download_file.xml @@ -38,9 +38,11 @@ - - - - - - \ No newline at end of file diff --git a/sample/src/main/res/layout/fragment_enqueue_request.xml b/sample/src/main/res/layout/fragment_enqueue_request.xml new file mode 100644 index 000000000..065c19f04 --- /dev/null +++ b/sample/src/main/res/layout/fragment_enqueue_request.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/sample/src/main/res/layout/fragment_https_certificate.xml b/sample/src/main/res/layout/fragment_https_certificate.xml new file mode 100644 index 000000000..6b3474a95 --- /dev/null +++ b/sample/src/main/res/layout/fragment_https_certificate.xml @@ -0,0 +1,33 @@ + + + +