|
@ -178,12 +178,15 @@ open class GraphQLRepository(private val service: GraphQLService) { |
|
|
// TODO convert string response to a response class |
|
|
// TODO convert string response to a response class |
|
|
open suspend fun fetchUser( |
|
|
open suspend fun fetchUser( |
|
|
username: String, |
|
|
username: String, |
|
|
): User { |
|
|
|
|
|
|
|
|
): User? { |
|
|
val response = service.getUser(username) |
|
|
val response = service.getUser(username) |
|
|
val body = JSONObject(response |
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
val body = JSONObject( |
|
|
|
|
|
response |
|
|
.split("<script type=\"text/javascript\">window._sharedData = ").get(1) |
|
|
.split("<script type=\"text/javascript\">window._sharedData = ").get(1) |
|
|
.split("</script>").get(0) |
|
|
.split("</script>").get(0) |
|
|
.trim().replace(Regex("\\};$"), "}")) |
|
|
|
|
|
|
|
|
.trim().replace(Regex("\\};$"), "}") |
|
|
|
|
|
) |
|
|
val userJson = body |
|
|
val userJson = body |
|
|
.getJSONObject("entry_data") |
|
|
.getJSONObject("entry_data") |
|
|
.getJSONArray("ProfilePage") |
|
|
.getJSONArray("ProfilePage") |
|
@ -224,6 +227,11 @@ open class GraphQLRepository(private val service: GraphQLService) { |
|
|
externalUrl = url, |
|
|
externalUrl = url, |
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
catch (e: Exception) { |
|
|
|
|
|
Log.e(TAG, "fetchUser failed", e) |
|
|
|
|
|
return null |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// TODO convert string response to a response class |
|
|
// TODO convert string response to a response class |
|
|
suspend fun fetchPost( |
|
|
suspend fun fetchPost( |
|
|