Skip to content

Commit

Permalink
fixed ktlint and detekt issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelperc committed Nov 3, 2024
1 parent 39c6613 commit e9d42a9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class NetworkData {
)

data class Response(
val request: Request,
val statusCode: Int,
val body: Body?,
val headers: Map<String, String?>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class NetworkData {
private fun parseGraphqlData(): GraphqlData? {
if (method != "POST" ||
body == null ||
body.isBinary ||
!body.body.startsWith("{")
!body.isLikelyJson
) return null
val json = runCatching { JSONObject(body!!.body.toString()) }.getOrNull() ?: return null
val query = json.optString("query") ?: return null
Expand Down Expand Up @@ -60,13 +59,12 @@ class NetworkData {
get() = headers["Content-Encoding"].equals("gzip", ignoreCase = true)

private fun getStatusMessage() = mapCode2Message(statusCode) +
if (hasGraphqlErrors) ", Response with errors" else ""
if (hasGraphqlErrors) ", Response with errors" else ""

private fun parseHasGraphqlErrors(): Boolean {
if (request.graphqlData == null ||
body == null ||
body.isBinary ||
!body.body.startsWith("{")
!body.isLikelyJson
) return false
val json = runCatching { JSONObject(body!!.body.toString()) }.getOrNull() ?: return false
return json.has("errors")
Expand All @@ -83,6 +81,7 @@ class NetworkData {
internal val isBinary: Boolean = BINARY_MEDIA_TYPES.contains(mediaType)
val sizeInBytes: Long = body.length.toLong()
internal val mediaTypeFull: String = "$mediaType/$mediaSubtype"
val isLikelyJson get() = !isBinary && body.startsWith('{')
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal class ApiItemHolder(parent: ViewGroup, actionListener: DiffAwareAdapter

url.setSpan {
append(fontColor(method, context.color(R.color.pluto___text_dark_60)))
append(" ${urlOrQuery}")
append(" $urlOrQuery")
}
progress.visibility = VISIBLE
status.visibility = INVISIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface ApiService {
@POST("xml")
suspend fun xml(@Body hashMapOf: RequestBody): Any

// https://studio.apollographql.com/public/SpaceX-pxxbxen/variant/current/home
@POST("https://spacex-production.up.railway.app/")
suspend fun graphql(@Body body: Any): Any
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class OkhttpViewModel : ViewModel() {
enqueue {
apiService.graphql(
mapOf(
"query" to "query Launches(\$limit: Int){launches(limit: \$limit){mission_name}}",
"variables" to mapOf("limit" to 3),
GQL_QUERY to "query Launches(\$limit: Int){launches(limit: \$limit){mission_name}}",
GQL_VARIABLES to mapOf("limit" to GQL_LIMIT_VALID),
)
)
}
Expand All @@ -43,8 +43,8 @@ class OkhttpViewModel : ViewModel() {
enqueue {
apiService.graphql(
mapOf(
"query" to "query Launches(\$limit: Int){launches(limit: \$limit){mission_name}}",
"variables" to mapOf("limit" to -1111),
GQL_QUERY to "query Launches(\$limit: Int){launches(limit: \$limit){mission_name}}",
GQL_VARIABLES to mapOf("limit" to GQL_LIMIT_INVALID),
)
)
}
Expand All @@ -56,8 +56,8 @@ class OkhttpViewModel : ViewModel() {
enqueue {
apiService.graphql(
mapOf(
"query" to "mutation Insert_users(\$objects: [users_insert_input!]!) {insert_users(objects: \$objects) {affected_rows}}",
"variables" to mapOf("objects" to emptyList<Any>()),
GQL_QUERY to "mutation Insert_users(\$objects: [users_insert_input!]!) {insert_users(objects: \$objects) {affected_rows}}",
GQL_VARIABLES to mapOf("objects" to emptyList<Any>()),
)
)
}
Expand All @@ -69,8 +69,8 @@ class OkhttpViewModel : ViewModel() {
enqueue {
apiService.graphql(
mapOf(
"query" to "mutation Insert_users(\$objects: [users_insert_input!]!) {insert_users112231321(objects: \$objects) {affected_rows}}",
"variables" to mapOf("objects" to emptyList<Any>()),
GQL_QUERY to "mutation Insert_users(\$objects: [users_insert_input!]!) {insert_users112231321(objects: \$objects) {affected_rows}}",
GQL_VARIABLES to mapOf("objects" to emptyList<Any>()),
)
)
}
Expand Down Expand Up @@ -131,4 +131,11 @@ class OkhttpViewModel : ViewModel() {
)
}
}

companion object {
private const val GQL_QUERY = "query"
private const val GQL_LIMIT_VALID = 3
private const val GQL_LIMIT_INVALID = -1111
private const val GQL_VARIABLES = "variables"
}
}

0 comments on commit e9d42a9

Please sign in to comment.