mirror of
https://github.com/InsanusMokrassar/SauceNaoAPI.git
synced 2024-12-23 05:07:12 +00:00
SauceNaoAnswer#row
This commit is contained in:
parent
1ee9e6a42c
commit
e04ee7300c
@ -12,12 +12,14 @@
|
|||||||
* Now `SauceNaoAPI` working with synchronous queue
|
* Now `SauceNaoAPI` working with synchronous queue
|
||||||
* `SauceNaoAPI` now will wait for some time when one of limits will be achieved
|
* `SauceNaoAPI` now will wait for some time when one of limits will be achieved
|
||||||
|
|
||||||
### 0.4.1 Managers experiments
|
### 0.4.1 Managers experiments and row format in answer
|
||||||
|
|
||||||
* Add `TimeManager` - it will manage work with requests times
|
* Add `TimeManager` - it will manage work with requests times
|
||||||
* Add `RequestQuotaMagager` - it will manage quota for requests and call suspend
|
* Add `RequestQuotaMagager` - it will manage quota for requests and call suspend
|
||||||
if they will be over
|
if they will be over
|
||||||
* `SauceNaoAPI` now working (almost) asynchronously
|
* `SauceNaoAPI` now working (almost) asynchronously
|
||||||
|
* Now `SauceNaoAnswer` have field `row` which contains `JsonObject` with
|
||||||
|
all original answer fields
|
||||||
|
|
||||||
## 0.3.0
|
## 0.3.0
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
It is wrapper for [SauceNAO](https://saucenao.com/) API. For now, library is
|
It is wrapper for [SauceNAO](https://saucenao.com/) API. For now, library is
|
||||||
in preview state. It can be fully used, but some of info can be unavailable from
|
in preview state. It can be fully used, but some of info can be unavailable from
|
||||||
wrapper classes.
|
wrapper classes, but now you can access them via `SauceNaoAnswer#row` field.
|
||||||
|
|
||||||
## Requester
|
## Requester
|
||||||
|
|
||||||
|
@ -1,9 +1,40 @@
|
|||||||
package com.github.insanusmokrassar.SauceNaoAPI.models
|
package com.github.insanusmokrassar.SauceNaoAPI.models
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.*
|
||||||
|
import kotlinx.serialization.internal.ArrayListSerializer
|
||||||
|
import kotlinx.serialization.json.*
|
||||||
|
|
||||||
@Serializable
|
@Serializable(SauceNaoAnswerSerializer::class)
|
||||||
data class SauceNaoAnswer(
|
data class SauceNaoAnswer(
|
||||||
val header: Header,
|
val header: Header,
|
||||||
val results: List<Result> = emptyList()
|
val results: List<Result> = emptyList(),
|
||||||
|
val raw: JsonObject
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializer(SauceNaoAnswer::class)
|
||||||
|
object SauceNaoAnswerSerializer : KSerializer<SauceNaoAnswer> {
|
||||||
|
private val resultsSerializer = ArrayListSerializer(Result.serializer())
|
||||||
|
private const val headerField = "header"
|
||||||
|
private const val resultsField = "results"
|
||||||
|
private val serializer = Json.nonstrict
|
||||||
|
|
||||||
|
override fun deserialize(decoder: Decoder): SauceNaoAnswer {
|
||||||
|
val raw = JsonObjectSerializer.deserialize(decoder)
|
||||||
|
val header = serializer.fromJson(Header.serializer(), raw.getObject(headerField))
|
||||||
|
val results = serializer.fromJson(resultsSerializer, raw.getArray(resultsField))
|
||||||
|
|
||||||
|
return SauceNaoAnswer(header, results, raw)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun serialize(encoder: Encoder, obj: SauceNaoAnswer) {
|
||||||
|
val resultObject = JsonObject(
|
||||||
|
obj.raw.content.let {
|
||||||
|
it + mapOf(
|
||||||
|
headerField to serializer.toJson(Header.serializer(), obj.header),
|
||||||
|
resultsField to serializer.toJson(resultsSerializer, obj.results)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
JsonObject.serializer().serialize(encoder, resultObject)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user