Skip to content

Commit

Permalink
build parameters in request
Browse files Browse the repository at this point in the history
  • Loading branch information
nono3551 committed Jun 17, 2020
1 parent b790cc8 commit 5bf8934
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0.4"
versionName "1.0.5"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,27 @@ import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException

abstract class BaseHttpRequest<T>(
continuation: Continuation<T?>,
protected val requestMethod: Int,
protected val uri: Uri,
protected val body: String,
parseSuccessResponse: (JSONObject?) -> T?,
errorParser: IExceptionDescriptionProvider
): JsonRequest<JSONObject>(requestMethod, uri.toString(), body, onSuccess(continuation, parseSuccessResponse), onError(errorParser, continuation)){
val continuation: Continuation<T?>,
val requestMethod: Int,
val schema: String,
val serverAddress: String,
val apiVersion: String,
val endpoint: String,
val queryParameters: MutableMap<String, String?>?,
val body: String,
val parseSuccessResponse: (JSONObject?) -> T?,
val errorParser: IExceptionDescriptionProvider
): JsonRequest<JSONObject>(
requestMethod,
getUri(schema, serverAddress, apiVersion, endpoint, queryParameters).toString(),
body,
onSuccess(continuation, parseSuccessResponse),
onError(errorParser, continuation)){

val uri by lazy {
return@lazy getUri(schema, serverAddress, apiVersion, endpoint, queryParameters)
}

init {
retryPolicy = DefaultRetryPolicy(
60000,
Expand Down Expand Up @@ -54,14 +68,14 @@ abstract class BaseHttpRequest<T>(
}

companion object {
private fun getUri(schema: String, serverAddress: String, apiVersion: String, endpoint: String, queryParameters: MutableMap<String, String?>?){
val urlBuilder = Uri.Builder().scheme(schema).encodedAuthority(serverAddress).appendEncodedPath(apiVersion).appendEncodedPath(endpoint).apply {
private fun getUri(schema: String, serverAddress: String, apiVersion: String, endpoint: String, queryParameters: MutableMap<String, String?>?): Uri{
return Uri.Builder().scheme(schema).encodedAuthority(serverAddress).appendEncodedPath(apiVersion).appendEncodedPath(endpoint).apply {
queryParameters?.let {
for (key in it.notNullValuesOnly().keys){
this.appendQueryParameter(key, queryParameters[key])
}
}
}
}.build()
}

private fun <T>onSuccess(continuation: Continuation<T?>, parseSuccessResponse: (JSONObject?) -> T?): Response.Listener<JSONObject?>{
Expand Down

0 comments on commit 5bf8934

Please sign in to comment.