support for request methods
This commit is contained in:
parent
72e0e2a912
commit
6da971ef21
1 changed files with 19 additions and 4 deletions
|
@ -2,6 +2,7 @@ package eu.m724.vastapp.vastai
|
|||
|
||||
import eu.m724.vastapp.BuildConfig
|
||||
import org.chromium.net.CronetEngine
|
||||
import org.chromium.net.UploadDataProvider
|
||||
import org.chromium.net.UrlRequest
|
||||
import java.util.concurrent.Executor
|
||||
|
||||
|
@ -16,15 +17,28 @@ class VastApi(
|
|||
*
|
||||
* @param endpoint the endpoint path starting with a slash like /users/current
|
||||
* @param callback any callback for example [UserUrlRequestCallback]
|
||||
* @param method request method, default GET
|
||||
* @param uploadDataProvider [UploadDataProvider] if request sends data
|
||||
* @return an [UrlRequest] you must .start() yourself
|
||||
*/
|
||||
fun buildRequest(endpoint: String, callback: UrlRequest.Callback): UrlRequest {
|
||||
val requestBuilder = cronetEngine.newUrlRequestBuilder(
|
||||
fun buildRequest(
|
||||
endpoint: String,
|
||||
callback: UrlRequest.Callback,
|
||||
method: String = "GET",
|
||||
uploadDataProvider: UploadDataProvider?
|
||||
): UrlRequest {
|
||||
var requestBuilder = cronetEngine.newUrlRequestBuilder(
|
||||
BuildConfig.VASIAI_API_ENDPOINT + endpoint,
|
||||
callback,
|
||||
executor
|
||||
).addHeader("Authorization", "Bearer $apiKey")
|
||||
|
||||
requestBuilder = requestBuilder.setHttpMethod(method)
|
||||
|
||||
if (uploadDataProvider != null) {
|
||||
requestBuilder = requestBuilder.setUploadDataProvider(uploadDataProvider, executor)
|
||||
}
|
||||
|
||||
return requestBuilder.build()
|
||||
}
|
||||
|
||||
|
@ -34,9 +48,10 @@ class VastApi(
|
|||
*
|
||||
* @param apiRoute the api route
|
||||
* @param callback any callback for example [UserUrlRequestCallback]
|
||||
* @param uploadDataProvider [UploadDataProvider] if request sends data
|
||||
* @return an [UrlRequest] you must .start() yourself
|
||||
*/
|
||||
fun buildRequest(apiRoute: ApiRoute, callback: UrlRequest.Callback): UrlRequest {
|
||||
return buildRequest(apiRoute.path, callback)
|
||||
fun buildRequest(apiRoute: ApiRoute, callback: UrlRequest.Callback, uploadDataProvider: UploadDataProvider? = null): UrlRequest {
|
||||
return buildRequest(apiRoute.path, callback, apiRoute.method, uploadDataProvider)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue