Skip to content

Commit

Permalink
Changed constructor of BaseHttpRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
nono3551 committed Jun 17, 2020
1 parent 91e8dd4 commit b790cc8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.3"
versionName "1.0.4"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.json.JSONException
import org.json.JSONObject
import sk.backbone.android.shared.repositories.server.client.exceptions.BaseHttpException
import sk.backbone.android.shared.repositories.server.client.exceptions.IExceptionDescriptionProvider
import sk.backbone.android.shared.utils.notNullValuesOnly
import java.io.UnsupportedEncodingException
import java.nio.charset.Charset
import kotlin.coroutines.Continuation
Expand All @@ -20,9 +21,9 @@ import kotlin.coroutines.resumeWithException

abstract class BaseHttpRequest<T>(
continuation: Continuation<T?>,
requestMethod: Int,
uri: Uri,
body: String,
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)){
Expand Down Expand Up @@ -53,6 +54,16 @@ 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 {
queryParameters?.let {
for (key in it.notNullValuesOnly().keys){
this.appendQueryParameter(key, queryParameters[key])
}
}
}
}

private fun <T>onSuccess(continuation: Continuation<T?>, parseSuccessResponse: (JSONObject?) -> T?): Response.Listener<JSONObject?>{
return Response.Listener {
Log.i("HttpResponseBody", it.toString())
Expand Down

0 comments on commit b790cc8

Please sign in to comment.