Skip to content

Instantly share code, notes, and snippets.

@hafs-r
Created October 7, 2019 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hafs-r/a868c3bc12a8be4118d51042aa814379 to your computer and use it in GitHub Desktop.
Save hafs-r/a868c3bc12a8be4118d51042aa814379 to your computer and use it in GitHub Desktop.
import okhttp3.Request
import okio.Buffer
object ResponseManager {
var next_match = true
var errorCode = 200
private fun bodyToString(request: Request): String {
try {
val copy = request.newBuilder().build()
val buffer = Buffer()
copy.body()!!.writeTo(buffer)
return buffer.readUtf8()
} catch (e: Exception) {
return "did not work".plus(e.message)
}
}
fun mapProperResponse(input: String, request: Request): String {
var output = input
if (input.endsWith("xxxxxx.json")) {
output = "api/xxxxx.json"
} else if (input.endsWith("xxxxx")) {
output = "api/xxxxx.json"
} else if (input.endsWith("login")) {
var bodyAsString = bodyToString(request)
bodyAsString = bodyAsString.substring(bodyAsString.indexOf("xxxxxx\":") + xx)
val xxxxx = bodyAsString.substring(0, bodyAsString.indexOf("\""))
bodyAsString = bodyAsString.substring(bodyAsString.indexOf("xxxxx\":") + xx)
val xxxxx = bodyAsString.substring(0, bodyAsString.indexOf("\""))
if (xxxxx.equals("xxx@xxxx.xxx")) {
errorCode = xxx
output = "api/xxxx/xxxxx_xxx.json"
} else {
errorCode = 200
output = "api/accounts/login.json"
}
}
return output
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment