Created
June 29, 2020 18:38
-
-
Save jetaggart/d096a1d500fdf378549f9f7eaf756fb0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // android/app/src/main/java/io/getstream/thestream/services/BackendService.kt:18 | |
| fun signIn(user: String) { | |
| authToken = post( | |
| "/v1/users", | |
| mapOf("user" to user) | |
| ) | |
| .getString("authToken") | |
| this.user = user | |
| } | |
| // ... | |
| private fun post(path: String, body: Map<String, Any>, authToken: String? = null): JSONObject { | |
| val request = Request.Builder() | |
| .url("$apiRoot${path}") | |
| .post(JSONObject(body).toString().toRequestBody(JSON)) | |
| if (authToken != null) { | |
| request.addHeader("Authorization", "Bearer $authToken") | |
| } | |
| http.newCall(request.build()).execute().use { | |
| return JSONObject(it.body!!.string()) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment