Created
October 7, 2019 13:35
-
-
Save hafs-r/a868c3bc12a8be4118d51042aa814379 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("[email protected]")) { | |
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