### start() Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.time/-interval/start.html Restarts the polling interval if it is currently paused. ```APIDOC ## start() ### Description Restarts the polling interval if it is currently paused. ### Method fun start(): ### Description 开始 如果当前为暂停状态将重新开始轮询 ``` -------------------------------- ### startElapsedRealtime Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.component/-progress/start-elapsed-realtime.html Represents the time in milliseconds since the system was booted when the download started. This is a read-only property of type Long. ```APIDOC ## startElapsedRealtime ### Description Represents the time in milliseconds since the system was booted when the download started. This is a read-only property of type Long. ### Property - **startElapsedRealtime** (Long) - The time in milliseconds when the download began. ``` -------------------------------- ### get Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net/-net/index.html Performs a synchronous GET network request. ```APIDOC ## get ### Description Synchronous network request using the GET method. ### Method Signature `fun get(path: String, tag: Any? = null, block: UrlRequest.() -> Unit? = null): ` ### Parameters * **path** (String) - The endpoint path for the request. * **tag** (Any?, optional) - An optional tag for the request. * **block** (UrlRequest.() -> Unit?, optional) - A lambda function to configure URL parameters. ``` -------------------------------- ### Get Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net/-get.html Performs an asynchronous network request using the GET method. The path can be a full URL or a relative path that will be appended with the NetConfig.host. A tag can be provided for request identification, and a block lambda can configure request parameters. ```APIDOC ## Get ### Description Performs an asynchronous network request using the GET method. The path can be a full URL or a relative path that will be appended with the NetConfig.host. A tag can be provided for request identification, and a block lambda can configure request parameters. ### Method GET ### Endpoint /{path} ### Parameters #### Path Parameters - **path** (String) - Required - The request path. If it does not contain http/https, NetConfig.host will be automatically prepended. - **tag** (Any?) - Optional - An object that can be passed to the Request, generally used in interceptors/converters for specific interface behavior judgment. #### Query Parameters None explicitly documented. #### Request Body None explicitly documented. ### Request Example ```kotlin coroutineScope.Get("your/api/path") { // Configure request parameters here, e.g., headers, query parameters } ``` ### Response #### Success Response (200) - **M** (Generic Type) - The response data of the requested type. #### Response Example ```json { "example": "response data" } ``` ``` -------------------------------- ### Download Progress Listener Source: https://github.com/liangjingkanji/net/blob/master/docs/progress.md Monitor the progress of file downloads. This example shows how to use `addDownloadListener` with a `ProgressListener` to update the UI with download status, including percentage, speed, and file sizes. ```kotlin scopeNetLife { val file = Get("https://github.com/liangjingkanji/Net/releases/latest/download/net-sample.apk") { setDownloadFileName("net.apk") setDownloadDir(requireContext().filesDir) addDownloadListener(object : ProgressListener() { override fun onProgress(p: Progress) { seek?.post { val progress = p.progress() seek.progress = progress tvProgress.text = "下载进度: $progress% 下载速度: ${p.speedSize()} " + "\n\n文件大小: ${p.totalSize()} 已下载: ${p.currentSize()} 剩余大小: ${p.remainSize()}" + "\n\n已使用时间: ${p.useTime()} 剩余时间: ${p.remainTime()}" } } }) }.await() } ``` -------------------------------- ### setPath Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.request/-base-request/set-path.html Configures the request path. If the provided path does not start with 'http' or 'https', it will be automatically prefixed with NetConfig.host. ```APIDOC ## setPath ### Description Parses and configures the path for a network request. It automatically handles the concatenation of the host if the provided path is not an absolute URL. ### Method fun ### Parameters #### Path Parameters * **path** (String?) - The path to be set for the request. If it does not contain 'http' or 'https', it will be automatically prefixed with `NetConfig.host`. ``` -------------------------------- ### Net.get Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net/-net/get.html Performs a synchronous network request. The 'path' parameter is the request path, and if it doesn't start with 'http' or 'https', the NetConfig.host will be automatically prepended. The 'tag' parameter can be used to pass an object for specific interface behavior judgment in interceptors or converters. The 'block' parameter is a lambda function where request parameters can be configured. ```APIDOC ## get ### Description Performs a synchronous network request. The 'path' parameter is the request path, and if it doesn't start with 'http' or 'https', the NetConfig.host will be automatically prepended. The 'tag' parameter can be used to pass an object for specific interface behavior judgment in interceptors or converters. The 'block' parameter is a lambda function where request parameters can be configured. ### Method GET ### Endpoint /{path} ### Parameters #### Path Parameters - **path** (String) - Required - The request path. If it does not contain http/https, NetConfig.host will be automatically appended. #### Query Parameters None explicitly documented. #### Request Body None explicitly documented. ### Request Example ```kotlin // Example usage within a block Net.get("users") { // block configuration here } ``` ### Response #### Success Response (200) - The return type is , indicating the result of the network request. #### Response Example ```json // Response structure depends on the actual API and error class { "data": "...", "message": "..." } ``` ``` -------------------------------- ### options Function Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net/-net/options.html Configures and executes a synchronous network request. The 'path' parameter is the request URL, which will be automatically prefixed with NetConfig.host if it doesn't start with 'http' or 'https'. The 'tag' parameter can be used for custom request identification in interceptors or converters. The 'block' parameter is a lambda function where request parameters can be configured. ```APIDOC ## options ### Description Synchronous network request. ### Signature ```kotlin @JvmOverloads @JvmStatic fun options(path: String, tag: Any? = null, block: UrlRequest.() -> Unit? = null): ``` ### Parameters * **path** (String) - The request path. If it does not contain http/https, it will be automatically appended with [NetConfig.host](../-net-config/host.html). * **tag** (Any?) - An object that can be passed to the Request request, generally used for judging specific interface behavior in interceptors/converters. * **block** (UrlRequest.() -> Unit?) - A lambda function where request parameters can be configured. ``` -------------------------------- ### Custom Converter Implementation Source: https://github.com/liangjingkanji/net/blob/master/docs/converter-customize.md Example of a custom converter that extends `NetConverter`. It includes a try-catch block to handle specific conversion errors and allows returning any object as R. ```kotlin class CustomizeConverter: NetConverter { override fun onConvert(succeed: Type, response: Response): R? { try { return NetConverter.onConvert(succeed, response) } catch (e: ConvertException) { // ... 仅自定义不支持的类型 return 任何对象 as R } } } ``` -------------------------------- ### FragmentActivity Scope for Dialogs Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.utils/index.html Extends FragmentActivity to provide a coroutine scope that displays a loading dialog at the start and dismisses it upon completion or cancellation. Global dialog configuration is available via NetConfig.dialogFactory. ```kotlin fun [FragmentActivity].[scopeDialog](dialog: [Dialog]? = null, cancelable: [Boolean] = true, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> [Unit]): [NetCoroutineScope] ``` -------------------------------- ### CoroutineScope.Trace Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net/-trace.html Initiates an asynchronous network request. The 'path' parameter is the request URL. If it doesn't start with 'http' or 'https', the NetConfig.host will be prepended. The 'tag' parameter can be used to pass an object for identification in interceptors or converters. The 'block' parameter is a lambda where request parameters can be configured. ```APIDOC ## CoroutineScope.Trace ### Description Initiates an asynchronous network request. The 'path' parameter is the request URL. If it doesn't start with 'http' or 'https', the NetConfig.host will be prepended. The 'tag' parameter can be used to pass an object for identification in interceptors or converters. The 'block' parameter is a lambda where request parameters can be configured. ### Signature inline fun CoroutineScope.Trace(path: String, tag: Any? = null, noinline block: UrlRequest.() -> Unit? = null): Deferred ### Parameters #### Path Parameters - **path** (String) - Required - Request path. If it does not contain http/https, NetConfig.host will be automatically appended. - **tag** (Any?) - Optional - Can pass objects to Request, generally used for specific interface behavior judgment in interceptors/converters. #### Block Parameters (within UrlRequest) - **block** (UrlRequest.() -> Unit?) - Optional - Configure request parameters within the lambda. ``` -------------------------------- ### initialize(host: String, context: Context?, config: OkHttpClient.Builder) Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net/-net-config/initialize.html Initializes the Net framework with an optional host, context, and an OkHttpClient.Builder instance for configuration. Essential for multi-process applications. ```APIDOC ## initialize(host: String, context: Context?, config: OkHttpClient.Builder) ### Description Initializes the Net framework. It's recommended to initialize for multi-process applications by setting `NetConfig.host` or providing a `context` to avoid potential issues with Toasts or other unexpected behaviors. ### Parameters #### Parameters - **host** (String) - Optional - The base URL hostname for requests. This parameter is automatically appended to request paths unless the path already includes 'https://' or 'http://'. - **context** (Context?) - Optional - Specify this parameter if your application uses multiple processes to initialize `NetConfig.app`. - **config** (OkHttpClient.Builder) - Optional - An OkHttpClient.Builder instance for network request configuration. ``` -------------------------------- ### DialogCoroutineScope Constructor Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.scope/-dialog-coroutine-scope/index.html Constructs a DialogCoroutineScope that automatically loads a dialog for network requests. The dialog's lifecycle is tied to the provided FragmentActivity. It handles showing the dialog on request start, displaying error messages on error, and closing the dialog on completion. ```APIDOC ## DialogCoroutineScope Constructor ### Description Initializes a DialogCoroutineScope with a FragmentActivity to manage network request dialogs. This scope automatically shows a loading dialog when a request starts, displays an error message if the request fails, and dismisses the dialog when the request completes. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **activity** ([FragmentActivity](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentActivity.html)) - Required - The FragmentActivity to which the dialog will be attached, ensuring its lifecycle is managed correctly. - **dialog** ([Dialog](https://developer.android.com/reference/kotlin/android/app/Dialog.html)?) - Optional - A custom Dialog to be used instead of the default loading dialog. If null, a default dialog will be used. - **cancelable** ([Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)?) - Optional - Specifies whether the user can cancel the dialog by interacting with it (e.g., pressing the back button). If null, the default behavior of the dialog will be used. - **dispatcher** (CoroutineDispatcher) - Optional - The CoroutineDispatcher to use for the coroutine scope. Defaults to `Dispatchers.Main`. ``` -------------------------------- ### initialize(host: String, context: Context?, config: OkHttpClient.Builder.() -> Unit) Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net/-net-config/initialize.html Initializes the Net framework with an optional host, context, and a configuration lambda for OkHttpClient.Builder. This is particularly important for multi-process applications. ```APIDOC ## initialize(host: String, context: Context?, config: OkHttpClient.Builder.() -> Unit) ### Description Initializes the Net framework. It's recommended to initialize for multi-process applications by setting `NetConfig.host` or providing a `context` to avoid potential issues with Toasts or other unexpected behaviors. ### Parameters #### Parameters - **host** (String) - Optional - The base URL hostname for requests. This parameter is automatically appended to request paths unless the path already includes 'https://' or 'http://'. - **context** (Context?) - Optional - Specify this parameter if your application uses multiple processes to initialize `NetConfig.app`. - **config** (OkHttpClient.Builder.() -> Unit) - Optional - A lambda function to configure the OkHttpClient.Builder. ``` -------------------------------- ### GET Method Signature Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.request/-method/-g-e-t/index.html Provides the signature for the GET method, which is used to initiate an HTTP GET request. This method is part of the Method enum in the com.drake.net.request package. ```APIDOC ## GET ### Description Initiates an HTTP GET request. ### Method GET ### Endpoint [Not specified in source] ### Parameters [No parameters explicitly documented for the method signature itself] ### Request Example [No request example provided in source] ### Response [No response details provided in source] ``` -------------------------------- ### Peek Bytes from ResponseBody Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.body/peek-bytes.html Use this extension function on a ResponseBody to get a ByteString of the first 'byteCount' bytes. The default byteCount is 1MB. If byteCount is -1, the entire content is returned. ```kotlin fun ResponseBody.[peekBytes](peek-bytes.html)(byteCount: [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) = 1024 * 1024): ByteString ``` -------------------------------- ### get(type: Class) Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.reflect/-type-token/get.html Gets a type literal for the given Class instance. This overload is convenient for simple class types. ```APIDOC ## get(type: Class) ### Description Gets type literal for the given `{@code Class}` instance. ### Method open fun ### Parameters #### Path Parameters - **type** (*Class*<[T]>*) - Description: The Class instance to create a TypeToken from. ### Response #### Success Response - **TypeToken<[T]>** - A TypeToken representing the provided Class. ``` -------------------------------- ### Initialize Net with OkHttp Builder Source: https://github.com/liangjingkanji/net/blob/master/docs/config.md Initialize Net using an existing OkHttpClient.Builder, allowing for more granular control over the OkHttp client configuration. ```kotlin val okHttpClientBuilder = OkHttpClient.Builder() .setDebug(BuildConfig.DEBUG) .setConverter(SerializationConverter()) .addInterceptor(LogRecordInterceptor(BuildConfig.DEBUG)) NetConfig.initialize(Api.HOST, this, okHttpClientBuilder) ``` -------------------------------- ### StateLayout Scope for Default Page Handling Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.utils/index.html Offers an asynchronous scope for StateLayout that automatically manages default page states. It shows a loading state at the start, a success state on completion, and an error state with toast messages upon exceptions. ```kotlin fun StateLayout.[scope](dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> [Unit]): [NetCoroutineScope] ``` -------------------------------- ### Get Response Headers with Default Converter Source: https://github.com/liangjingkanji/net/blob/master/docs/converter.md Demonstrates how to retrieve response headers using the default converter with a Response object. Ensure the scopeNetLife block is used for managing network request lifecycles. ```kotlin scopeNetLife { Get(Api.PATH).await().headers("响应头名称") // 返回响应头 } ``` -------------------------------- ### Initialize Net with Custom Configuration Source: https://github.com/liangjingkanji/net/blob/master/docs/config.md Use this method to initialize Net with custom configurations like timeouts and debug settings. Ensure to set appropriate timeout values to avoid long user waits. ```kotlin NetConfig.initialize(Api.HOST, this) { // 超时配置, 默认是10秒, 设置太长时间会导致用户等待过久 connectTimeout(30, TimeUnit.SECONDS) readTimeout(30, TimeUnit.SECONDS) writeTimeout(30, TimeUnit.SECONDS) setDebug(BuildConfig.DEBUG) setConverter(SerializationConverter()) } ``` -------------------------------- ### get(type: Type) Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.reflect/-type-token/get.html Gets a type literal for the given Type instance. This is useful for representing complex generic types. ```APIDOC ## get(type: Type) ### Description Gets type literal for the given `{@code Type}` instance. ### Method open fun ### Parameters #### Path Parameters - **type** (*Type*) - Description: The Type instance to create a TypeToken from. ### Response #### Success Response - **TypeToken** - A TypeToken representing the provided Type. ``` -------------------------------- ### Get Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net/index.html Performs an asynchronous GET request. This function is an extension on CoroutineScope and allows for custom request configurations via a lambda block. ```APIDOC ## GET ### Description Performs an asynchronous GET request to the specified path. ### Method GET ### Endpoint /{path} ### Parameters #### Path Parameters - **path** (String) - Required - The path for the GET request. - **tag** (Any?) - Optional - A tag for identifying the request. #### Query Parameters - The query parameters can be configured using the `UrlRequest` lambda. ### Response - Returns a `Deferred` where `M` is the expected response type. ``` -------------------------------- ### Writing Tags and Extras in a Scope Source: https://github.com/liangjingkanji/net/blob/master/docs/tag.md Demonstrates how to set tags and extras when initiating a network request within a scope. Use `tag()` or provide a Class as a key for tags, and `setExtra()` for string-keyed extras. ```kotlin scopeNetLife { tv.text = Get(Api.PATH, "标签A"){ // tag("标签A") 等效上一行的参数 "标签A" setExtra("tagName", "标签B") // 写入额外数据 }.await() } ``` -------------------------------- ### initialize() Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.cache/-force-cache/initialize.html Initializes the cache. This process involves reading journal files from storage and constructing the required in-memory cache data. The time taken for initialization can fluctuate based on the size of the journal files and the current cache size. It is recommended to call this function during the application's initialization phase, ideally on a background thread. If this method is not explicitly called, OkHttp will perform lazy initialization when the cache is first used. ```APIDOC ## initialize() ### Description Initializes the cache. This process involves reading journal files from storage and constructing the required in-memory cache data. The time taken for initialization can fluctuate based on the size of the journal files and the current cache size. It is recommended to call this function during the application's initialization phase, ideally on a background thread. If this method is not explicitly called, OkHttp will perform lazy initialization when the cache is first used. ### Method fun initialize() ### Parameters None ### Response None ``` -------------------------------- ### Initialize Net with SerializationConverter Globally Source: https://github.com/liangjingkanji/net/blob/master/docs/converter-customize.md Sets up the Net configuration globally with a `SerializationConverter`. This converter will be used by default for all requests unless overridden. ```kotlin NetConfig.initialize(Api.HOST, this) { setConverter(SerializationConverter()) } ``` -------------------------------- ### Interval(end: Long, period: Long, unit: TimeUnit, start: Long = 0, initialDelay: Long = 0) Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.time/-interval/-interval.html Creates a timer with a defined end value. This overload supports both forward and countdown timers based on the start and end values. ```APIDOC ## Interval(end: Long, period: Long, unit: TimeUnit, start: Long = 0, initialDelay: Long = 0) ### Description Creates a timer with a defined end value. Supports both forward and countdown timers. ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Parameters * **end** (Long) - The end value, -1 indicates never ending. * **period** (Long) - The timer interval. * **unit** (TimeUnit) - The timer unit. * **start** (Long) - The start value. If start is greater than end and end is not -1, it acts as a countdown; otherwise, it's a count-up. * **initialDelay** (Long) - The interval time for the first event, defaults to 0. ``` -------------------------------- ### onCreate Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.interfaces/-net-dialog-factory/-d-e-f-a-u-l-t/index.html Builds and returns a Dialog. This is an override function from the NetDialogFactory interface. ```APIDOC ## onCreate ### Description Builds and returns a Dialog. This is an override function from the NetDialogFactory interface. ### Method open override fun ### Signature onCreate(activity: FragmentActivity): Dialog ### Parameters #### Path Parameters - **activity** (FragmentActivity) - Required - The FragmentActivity to associate the dialog with. ### Response #### Success Response - **Dialog** - The created Dialog object. ``` -------------------------------- ### Download File Name Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.request/index.html Gets the name of the downloaded file. ```APIDOC ## Download File Name ### Description Gets the name of the downloaded file. ### Method Extension function for `Request` ### Endpoint N/A (SDK function) ### Parameters None ### Request Example ```kotlin val fileName = request.downloadFileName() ``` ### Response #### Success Response - `String?` - The name of the downloaded file, or null if not specified. ``` -------------------------------- ### NetConfig Initialization Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net/-net-config/index.html Initializes the Net framework. While not strictly required for basic usage, it's recommended to initialize NetConfig, especially in multi-process applications, by providing either the global host or a context to avoid potential issues with toasts or other unexpected behaviors. ```APIDOC ## initialize ### Description Initializes the Net framework. It's recommended to call this method, especially in multi-process applications, by providing either the global host or a context to ensure proper functionality. ### Method Signature ```kotlin fun initialize(host: String = "", context: Context? = null, config: OkHttpClient.Builder.() -> Unit = {}) ``` ### Parameters * **host** (String) - Optional. The global domain name for network requests. * **context** (Context?) - Optional. The Android Context, required for multi-process scenarios if host is not set. * **config** (OkHttpClient.Builder.() -> Unit) - Optional. A lambda function to configure the OkHttpClient.Builder. --- ## initialize ### Description Initializes the Net framework using a provided OkHttpClient.Builder. Similar to the other initialize method, it's recommended for multi-process applications. ### Method Signature ```kotlin fun initialize(host: String = "", context: Context? = null, config: OkHttpClient.Builder) ``` ### Parameters * **host** (String) - Optional. The global domain name for network requests. * **context** (Context?) - Optional. The Android Context, required for multi-process scenarios if host is not set. * **config** (OkHttpClient.Builder) - The OkHttpClient.Builder instance to configure the client. ``` -------------------------------- ### Download File Directory Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.request/index.html Gets the directory where downloaded files will be saved. ```APIDOC ## Download File Directory ### Description Gets the directory where downloaded files will be saved. ### Method Extension function for `Request` ### Endpoint N/A (SDK function) ### Parameters None ### Request Example ```kotlin val downloadDir = request.downloadFileDir() ``` ### Response #### Success Response - `String` - The path to the download directory. ``` -------------------------------- ### Show Custom Single-Instance Dialog Source: https://github.com/liangjingkanji/net/blob/master/docs/auto-dialog.md Initiates a network request using a specified custom dialog instance. This allows for more control over the appearance and behavior of the loading indicator for a particular request. ```kotlin val dialog = BubbleDialog(requireActivity(), "加载中") scopeDialog(dialog) { tv.text = Post(Api.PATH) { param("username", "用户名") param("pwd", "123456") }.await() } ``` -------------------------------- ### Request.id Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.request/id.html Extension property to get or set a unique identifier for a Request. ```kotlin var Request.id: Any? get() = tag(R.id.request_id) set(value) = tag(R.id.request_id, value) ``` -------------------------------- ### Request.Builder.id Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.request/id.html Extension property to get or set a unique identifier for a Request.Builder. ```kotlin var Request.Builder.id: Any? get() = tag(R.id.request_id) set(value) = tag(R.id.request_id, value) ``` -------------------------------- ### Get Tag from Request.Builder Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.request/tag-of.html Reads a tag from the Request.Builder, identified by its class type. ```APIDOC ## tagOf ### Description Reads a tag from the Request.Builder, identified by its class type. ### Method Signature `inline fun Request.Builder.tagOf(): T?` ``` -------------------------------- ### Make Requests with Full URLs Source: https://github.com/liangjingkanji/net/blob/master/docs/config.md Construct full URLs for specific requests, especially when dealing with resources hosted on different domains. It's recommended to manage these URLs using singleton objects. ```kotlin object Api { const val HOST_IMG = "http://127.0.0.1" const val BANNER = "$HOST_IMG/banner" const val HOME = "/home" } scopeNetLife { val banner = Get(Api.BANNER).await() val home = Get(Api.HOME).await() } ``` -------------------------------- ### toNetOkhttp (Builder) Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.okhttp/index.html Converts an OkHttpClient.Builder to a Net-compatible OkHttpClient. ```APIDOC ## toNetOkhttp (Builder) ### Description Converts an OkHttpClient.Builder to a Net-compatible OkHttpClient. Net requires clients to be processed through this function for special handling. ### Method Extension function on `OkHttpClient.Builder` ``` -------------------------------- ### Get Tag from Request Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.request/tag-of.html Reads a tag from the OkHttp Request, identified by its class type. ```APIDOC ## tagOf ### Description Reads a tag from the OkHttp Request, identified by its class type. ### Method Signature `inline fun Request.tagOf(): T?` ``` -------------------------------- ### getParameterized Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.reflect/-type-token/get-parameterized.html Gets type literal for the parameterized type represented by applying typeArguments to rawType. ```APIDOC ## getParameterized ### Description Gets type literal for the parameterized type represented by applying `typeArguments` to `rawType`. ### Method fun getParameterized(rawType: Type, typeArguments: Array): TypeToken ### Parameters #### Path Parameters - **rawType** (Type) - Description not available - **typeArguments** (Array) - Description not available ### Response #### Success Response - **TypeToken** - Description not available ``` -------------------------------- ### OkHttp Configuration Source: https://github.com/liangjingkanji/net/blob/master/docs/api/navigation.html Provides methods for configuring the OkHttp client within the Net library. ```APIDOC ## OkHttp Configuration ### Description Methods to configure the underlying OkHttp client for network requests, including setting converters, debug modes, and interceptors. ### Methods - `setConverter(converter)`: Sets the converter factory for serialization/deserialization. - `setDebug(debug)`: Enables or disables debug logging. - `setDialogFactory(factory)`: Sets a factory for creating dialogs during requests. - `setErrorHandler(handler)`: Sets a custom error handler. - `setRequestInterceptor(interceptor)`: Sets an interceptor for modifying requests. - `setSSLCertificate(certificate)`: Configures SSL certificate settings. - `trustSSLCertificate()`: Enables trust for all SSL certificates. ``` -------------------------------- ### DownloadListeners Constructor Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.tag/-net-tag/-download-listeners/-download-listeners.html Initializes a new instance of the DownloadListeners class. ```APIDOC ## DownloadListeners() ### Description Initializes a new instance of the DownloadListeners class. ### Method Constructor ### Parameters None ### Response None ### Example ```kotlin val downloadListeners = DownloadListeners() ``` ``` -------------------------------- ### getArray Method Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.reflect/-type-token/get-array.html Gets type literal for the array type whose elements are all instances of `componentType`. ```APIDOC ## getArray ### Description Gets type literal for the array type whose elements are all instances of `componentType`. ### Method Signature open fun getArray(componentType: Type): TypeToken ### Parameters #### Path Parameters - **componentType** (Type) - Description of the component type for the array. ``` -------------------------------- ### id Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.request/index.html Sets or gets the request ID. The ID is used for uniquely identifying a request, distinguishing it from the group. ```APIDOC ## id ### Description Sets or gets the request ID. The ID is used for uniquely identifying a request, distinguishing it from the group. ### Properties * `var Request.Builder.id: Any?` * `var Request.id: Any?` ``` -------------------------------- ### Setting Multiple Tags and Extras Source: https://github.com/liangjingkanji/net/blob/master/docs/tag.md Demonstrates setting multiple types of data, including string-keyed extras and class-keyed tags, during a request initiation. Use `setExtra()` for extras and `tag()` or `tag(Class, Any)` for tags. ```kotlin scopeNetLife { Get(Api.PATH){ setExtra("person", Person()) // 使用Request.extra("person")读取 tag(User()) // 等同于tag(Any::class.java, User()), 使用Request.tag()读取 tag(User::class.java, User()) // 使用Request.tag(User::class.java)读取 }.await() } ``` -------------------------------- ### Request.tags() Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.request/tags.html An extension function for Request that allows you to get the tags associated with a completed request. Tags are stored in a MutableMap. ```APIDOC ## Request.tags() ### Description Retrieves the mutable map of tags associated with a network request. This map can be used to access any tags that were previously set on the request builder. ### Method Extension Function ### Parameters None ### Returns A MutableMap, Any?> containing the tags for the request. ``` -------------------------------- ### onCreate Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.interfaces/-net-dialog-factory/-d-e-f-a-u-l-t/on-create.html Builds and returns a Dialog. When using the scopeDialog scope, this dialog will be automatically displayed and closed when the scope is completed. ```APIDOC ## onCreate ### Description Builds and returns a Dialog. When using the scopeDialog scope, this dialog will be automatically displayed and closed when the scope is completed. ### Method Signature open override fun onCreate(activity: FragmentActivity): Dialog ### Parameters #### Path Parameters - **activity** (FragmentActivity) - Required - The FragmentActivity where the request is occurring. ``` -------------------------------- ### Request.Builder.tags() Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.request/tags.html An extension function for Request.Builder that allows you to get or set tags associated with the request. Tags are stored in a MutableMap. ```APIDOC ## Request.Builder.tags() ### Description Retrieves the mutable map of tags associated with the request builder. This map can be used to store and retrieve arbitrary key-value pairs (Class to Any?) for the request. ### Method Extension Function ### Parameters None ### Returns A MutableMap, Any?> containing the tags for the request builder. ``` -------------------------------- ### Show Default Loading Dialog Source: https://github.com/liangjingkanji/net/blob/master/docs/auto-dialog.md Initiates a network request within a scope that automatically displays a default loading dialog until the request completes. The dialog is shown when the scope is entered and hidden when the scope finishes, regardless of success or failure. ```kotlin scopeDialog { tv.text = Post(Api.PATH) { param("username", "用户名") // 请求参数 param("pwd", "123456") }.await() } ``` -------------------------------- ### Get BufferedSource from Response Body Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.body/-net-response-body/source.html This snippet demonstrates how to retrieve the raw response body as a BufferedSource from a NetResponseBody object. ```APIDOC ## source() ### Description Provides access to the raw response body as a BufferedSource. ### Signature ```kotlin open override fun source(): BufferedSource ``` ### Returns A `BufferedSource` representing the raw response body. ``` -------------------------------- ### app Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net/-net-config/app.html Represents the application context, which is a global context for the entire application. It is initialized lazily. ```APIDOC ## app ### Description Represents the application context, which is a global context for the entire application. It is initialized lazily. ### Declaration ```kotlin lateinit var app: Context ``` ### Type [Context](https://developer.android.com/reference/kotlin/android/content/Context.html) ``` -------------------------------- ### launch Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.scope/-net-coroutine-scope/index.html Launches a new coroutine within the NetCoroutineScope. ```APIDOC ## launch ### Description Launches a coroutine in this scope. Any unhandled exceptions thrown from the coroutine will be handled by the scope's error handling mechanism. ### Parameters * `block` (suspend CoroutineScope.() -> Unit): The block of code to execute in the coroutine. ### Returns [NetCoroutineScope]: The current NetCoroutineScope instance for chaining. ``` -------------------------------- ### switch() Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.time/-interval/switch.html Toggles the polling task between starting and stopping. If the poller is in a paused state, calling switch will resume its operation. ```APIDOC ## switch() ### Description Toggles the polling task between starting and stopping. If the poller is in a paused state, calling switch will resume its operation. ### Method fun ### Endpoint switch() ### Parameters None ### Response None ``` -------------------------------- ### DownloadTempFile Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.tag/-net-tag/-download-temp-file/-download-temp-file.html This function, DownloadTempFile, is a constructor or a primary function for creating or initiating a temporary file download. It accepts an optional boolean parameter 'value' which defaults to true. ```APIDOC ## DownloadTempFile() ### Description Initializes or creates a temporary file download. This function can be configured with a boolean flag to control its behavior, defaulting to enabled. ### Function Signature `fun DownloadTempFile(value: Boolean = true)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```kotlin // Example of calling the function with default value val download = DownloadTempFile() // Example of calling the function with a specific value val downloadDisabled = DownloadTempFile(false) ``` ### Response This function does not explicitly return a value that is documented here, but it is presumed to initiate a download process. ``` -------------------------------- ### Configure Global Custom Dialog Factory Source: https://github.com/liangjingkanji/net/blob/master/docs/auto-dialog.md Initializes the Net library with a custom dialog factory for all subsequent requests. This factory is responsible for creating the loading dialogs used throughout the application. It allows for a consistent, globally applied custom loading experience. ```kotlin NetConfig.initialize(Api.HOST, this) { setDialogFactory { ProgressDialog(it).apply { setMessage("我是全局自定义的加载对话框...") } } } ``` -------------------------------- ### supertypeOf Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.reflect/$-gson$-types/supertype-of.html Returns a type that represents an unknown supertype of `bound`. For example, if `bound` is `String.class`, this returns `? * super String`. ```APIDOC ## supertypeOf ### Description Returns a type that represents an unknown supertype of `bound`. For example, if `bound` is `String.class`, this returns `? * super String`. ### Method fun ### Parameters #### Path Parameters - **bound** (Type) - Description: The type for which to find the supertype. ### Response #### Success Response - **WildcardType** - Description: An unknown supertype of the bound. ``` -------------------------------- ### group Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.request/index.html Sets or gets the request group. The group is used for organizing requests, and a default group is assigned if not explicitly set. ```APIDOC ## group ### Description Sets or gets the request group. The group is used for organizing requests, and a default group is assigned if not explicitly set. ### Properties * `var Request.Builder.group: Any?` * `var Request.group: Any?` ### Note If you override the group, the request may not be automatically cancelled when the coroutine scope ends. ``` -------------------------------- ### launch Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.scope/-net-coroutine-scope/launch.html Launches a coroutine within the NetCoroutineScope. ```APIDOC ## launch ### Description Launches a new coroutine without blocking the current thread and returns a NetCoroutineScope. ### Signature ```kotlin open override fun launch(block: suspend CoroutineScope.() -> Unit): NetCoroutineScope ``` ### Parameters #### block - `block` (suspend CoroutineScope.() -> Unit) - Required - A suspend lambda that defines the coroutine's work. It has access to the CoroutineScope. ### Returns - `NetCoroutineScope` - The scope for the newly launched coroutine. ``` -------------------------------- ### okHttpClient Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net/-net-config/ok-http-client.html Provides access to the global singleton OkHttpClient instance for making network requests. ```APIDOC ## okHttpClient ### Description Provides access to the global singleton OkHttpClient instance for making network requests. This client is configured and ready for use across your application. ### Property okHttpClient: OkHttpClient ### Usage Access this property directly to obtain the shared OkHttpClient instance. ### Example ```kotlin // Assuming NetConfig is accessible and configured val client: OkHttpClient = NetConfig.okHttpClient // Use the client for network operations ``` ``` -------------------------------- ### Interval Operations Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.time/-interval/index.html Core operations for controlling the Interval, including starting, stopping, pausing, resuming, resetting, and toggling the state. ```APIDOC ## Interval Operations ### Description Provides methods to control the lifecycle and state of the Interval. ### Operations 1. **`start()`** Starts the interval. Can only be called when the interval is idle. 2. **`stop()`** Stops the interval. 3. **`pause()`** Pauses the interval. 4. **`resume()`** Resumes the interval after it has been paused. 5. **`reset()`** Resets the interval. This operation does not stop the poller. 6. **`switch()`** Toggles between starting and pausing the interval. ``` -------------------------------- ### downloadMd5Verify Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.request/download-md5-verify.html Downloads a file and verifies its MD5 checksum against the server's Content-MD5 header. If the checksums match and the file already exists, the download is skipped. ```APIDOC ## downloadMd5Verify() ### Description Downloads a file and verifies its MD5 checksum. If the server's `Content-MD5` header matches the MD5 of the file at the specified path, the download is skipped and the existing file is returned. ### Method Extension function on `Request`. ### Parameters None ### Returns `Boolean` - Returns `true` if the file was downloaded or if the MD5 verification passed and the file was skipped, `false` otherwise. ### Example ```kotlin // Assuming 'request' is an instance of Request val downloadSuccess = request.downloadMd5Verify() ``` ``` -------------------------------- ### Get TypeToken from Type Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.reflect/-type-token/index.html Obtain a TypeToken for a given Type instance. This function handles various Java reflection Type objects. ```kotlin val typeToken = TypeToken.get(object : TypeToken>() {}.type) ``` -------------------------------- ### options Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net/-net/index.html Synchronously sends an OPTIONS request to the specified path. Supports optional tagging and a request block for customization. ```APIDOC ## options ### Description Synchronously sends an OPTIONS request to the specified path. Supports optional tagging and a request block for customization. ### Method OPTIONS ### Endpoint /{path} ### Parameters #### Path Parameters - **path** (String) - Required - The path for the network request. - **tag** (Any?) - Optional - An identifier for the request. #### Request Body - **block** (UrlRequest.() -> Unit)? - Optional - A lambda function to configure the request. ``` -------------------------------- ### Get TypeToken from Class Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.reflect/-type-token/index.html Obtain a TypeToken for a given Class instance. This is useful when you have a Class object and need its corresponding TypeToken representation. ```kotlin val typeToken = TypeToken.get(String::class.java) ``` -------------------------------- ### Peek Bytes from RequestBody Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.body/peek-bytes.html Use this extension function on a RequestBody to get a ByteString of the first 'byteCount' bytes. The default byteCount is 1MB. ```kotlin fun RequestBody.[peekBytes](peek-bytes.html)(byteCount: [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) = 1024 * 1024): ByteString ``` -------------------------------- ### Basic Network Request with GsonConverter Source: https://github.com/liangjingkanji/net/blob/master/docs/converter-customize.md Demonstrates a basic network request using the `GsonConverter`. Ensure the converter is correctly specified for the request. ```kotlin scopeNetLife { val userList = Get>(Api.PATH) { converter = GsonConverter() }.await() } ``` -------------------------------- ### TypeToken.rawType Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.reflect/-type-token/raw-type.html Gets the raw Java Class of the generic type represented by this TypeToken. This is useful for operations that require a Class object, such as reflection or serialization. ```APIDOC ## rawType ### Description Gets the raw Java Class of the generic type represented by this TypeToken. This is useful for operations that require a Class object, such as reflection or serialization. ### Property `val rawType: Class` ### Returns A `Class` object representing the raw type. ``` -------------------------------- ### preview Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.scope/-net-coroutine-scope/preview.html The 'preview' scope is generally used for cache reading and only callbacks on the first launch of the scope. This function executes before the scope's launch. All exceptions within the function are not thrown and do not terminate the scope's execution. ```APIDOC ## preview ### Description This function provides a 'preview' scope, typically used for cache reading. It only executes its block on the first launch of the scope. Exceptions within this scope are handled internally and do not propagate or terminate the scope. ### Function Signature ```kotlin fun preview(breakError: Boolean = false, breakLoading: Boolean = true, block: suspend CoroutineScope.() -> Unit): AndroidScope ``` ### Parameters #### `breakError` (Boolean) - Optional. Default is `false`. - If `true`, error information will not be processed after successful cache reading. #### `breakLoading` (Boolean) - Optional. Default is `true`. - If `true`, the loading animation will end after successful cache reading. #### `block` (suspend CoroutineScope.() -> Unit) - A suspend function that defines the operations within the scope. All exceptions within this block are considered cache read failures and will not result in toasts or error logs. This block can also be used for tasks other than reading cache, such as reading database or other interface data. ``` -------------------------------- ### Get TypeToken for Parameterized Type Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.reflect/-type-token/index.html Construct a TypeToken for a parameterized type by specifying the raw type and its type arguments. This is essential for complex generic types. ```kotlin val parameterizedTypeToken = TypeToken.getParameterized(List::class.java, String::class.java) ``` -------------------------------- ### OkHttpClient.toNetOkhttp Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.okhttp/to-net-okhttp.html Extension function to create a special OkHttpClient. ```APIDOC ## OkHttpClient.toNetOkhttp ### Description Extension function to create a special OkHttpClient. This is required for Net to process. ### Method Extension Function ### Signature fun OkHttpClient.toNetOkhttp(): ### Note Content copied to clipboard ``` -------------------------------- ### Get TypeToken for Array Type Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.reflect/-type-token/index.html Create a TypeToken for an array type given its component type. This is useful for representing arrays of specific generic types. ```kotlin val arrayTypeToken = TypeToken.getArray(String::class.java) ``` -------------------------------- ### onCreate Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.interfaces/-net-dialog-factory/on-create.html Constructs and returns a Dialog. When using the scopeDialog scope, this dialog will be automatically displayed and closed when the scope is completed. ```APIDOC ## onCreate ### Description Constructs and returns a Dialog. When using the scopeDialog scope, this dialog will be automatically displayed and closed when the scope is completed. ### Method abstract fun ### Parameters #### Path Parameters * **activity** ([FragmentActivity](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentActivity.html)) - Required - The FragmentActivity where the request occurred. ### Response #### Success Response * **Dialog** ([Dialog](https://developer.android.com/reference/kotlin/android/app/Dialog.html)) - The constructed dialog. ``` -------------------------------- ### downloadFileNameDecode Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.request/download-file-name-decode.html Decodes the downloaded file name. This is useful when the server transmits file names that are URL-encoded, such as Chinese characters, and you need to URL-decode them to get the readable name. ```APIDOC ## downloadFileNameDecode ### Description Decodes the downloaded file name. This is useful when the server transmits file names that are URL-encoded, such as Chinese characters, and you need to URL-decode them to get the readable name. ### Method Extension Function ### Endpoint N/A (SDK function) ### Parameters None ### Response #### Success Response - **Boolean** (Boolean) - Returns true if the file name decoding is enabled, false otherwise. ``` -------------------------------- ### param(name: String, value: List?) Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.request/-body-request/param.html Adds a list of File parameters to the request. ```APIDOC ## param(name: String, value: List?) ### Description Adds a list of File parameters to the request. ### Method Not applicable (SDK method) ### Parameters - **name** (String) - The name of the parameter. - **value** (List?) - The list of Files to add. ``` -------------------------------- ### BaseRequest.method Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.request/-base-request/method.html Represents the HTTP method for the network request. This property allows you to specify or retrieve the method (e.g., GET, POST, PUT, DELETE) associated with a BaseRequest object. ```APIDOC ## BaseRequest.method ### Description Represents the HTTP method for the network request. This property allows you to specify or retrieve the method (e.g., GET, POST, PUT, DELETE) associated with a BaseRequest object. ### Property `method` ### Type [Method](../-method/index.html) ### Access Open var ``` -------------------------------- ### Add Jitpack Repository to settings.gradle Source: https://github.com/liangjingkanji/net/blob/master/README_EN.md Configure your project's settings.gradle file to include the Jitpack repository for dependency resolution. ```kotlin dependencyResolutionManagement { repositories { // ... maven { url 'https://jitpack.io' } } } ``` -------------------------------- ### Progress Constructor Source: https://github.com/liangjingkanji/net/blob/master/docs/api/-net/com.drake.net.component/-progress/-progress.html Initializes a new instance of the Progress class. ```APIDOC ## Progress() ### Description Initializes a new instance of the Progress class. ### Method Progress ### Parameters None ```