|
|
|
@ -61,18 +61,22 @@ class OkHttpWebClient(
|
|
|
|
return httpClient.newCall(request.build()).await().ensureSuccess()
|
|
|
|
return httpClient.newCall(request.build()).await().ensureSuccess()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override suspend fun graphQLQuery(endpoint: String, query: String): JSONObject {
|
|
|
|
override suspend fun httpPost(url: HttpUrl, body: JSONObject): Response {
|
|
|
|
val body = JSONObject()
|
|
|
|
|
|
|
|
body.put("operationName", null as Any?)
|
|
|
|
|
|
|
|
body.put("variables", JSONObject())
|
|
|
|
|
|
|
|
body.put("query", "{$query}")
|
|
|
|
|
|
|
|
val mediaType = "application/json; charset=utf-8".toMediaType()
|
|
|
|
val mediaType = "application/json; charset=utf-8".toMediaType()
|
|
|
|
val requestBody = body.toString().toRequestBody(mediaType)
|
|
|
|
val requestBody = body.toString().toRequestBody(mediaType)
|
|
|
|
val request = Request.Builder()
|
|
|
|
val request = Request.Builder()
|
|
|
|
.post(requestBody)
|
|
|
|
.post(requestBody)
|
|
|
|
.url(endpoint)
|
|
|
|
.url(url)
|
|
|
|
.addTags()
|
|
|
|
.addTags()
|
|
|
|
val json = httpClient.newCall(request.build()).await().ensureSuccess().parseJson()
|
|
|
|
return httpClient.newCall(request.build()).await().ensureSuccess()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override suspend fun graphQLQuery(endpoint: String, query: String): JSONObject {
|
|
|
|
|
|
|
|
val body = JSONObject()
|
|
|
|
|
|
|
|
body.put("operationName", null as Any?)
|
|
|
|
|
|
|
|
body.put("variables", JSONObject())
|
|
|
|
|
|
|
|
body.put("query", "{$query}")
|
|
|
|
|
|
|
|
val json = httpPost(endpoint, body).parseJson()
|
|
|
|
json.optJSONArray("errors")?.let {
|
|
|
|
json.optJSONArray("errors")?.let {
|
|
|
|
if (it.length() != 0) {
|
|
|
|
if (it.length() != 0) {
|
|
|
|
throw GraphQLException(it)
|
|
|
|
throw GraphQLException(it)
|
|
|
|
@ -82,9 +86,7 @@ class OkHttpWebClient(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun Request.Builder.addTags(): Request.Builder {
|
|
|
|
private fun Request.Builder.addTags(): Request.Builder {
|
|
|
|
if (mangaSource != null) {
|
|
|
|
|
|
|
|
tag(MangaSource::class.java, mangaSource)
|
|
|
|
tag(MangaSource::class.java, mangaSource)
|
|
|
|
}
|
|
|
|
|
|
|
|
return this
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|