mirror of
https://github.com/InsanusMokrassar/SauceNaoAPI.git
synced 2025-01-09 13:09:53 +00:00
AdaptedAnswer and the other facade
This commit is contained in:
parent
6925e309eb
commit
9b9bbefaf0
@ -1,4 +1,5 @@
|
|||||||
# 0.3.0
|
# 0.3.0
|
||||||
|
|
||||||
* Now `results` field of `SauceNaoAnswer` is optional and is empty list by default
|
* Now `results` field of `SauceNaoAnswer` is optional and is empty list by default
|
||||||
|
* Adapted structure almost completed and now can be used with raw results
|
||||||
|
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.github.insanusmokrassar.SauceNaoAPI.additional
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.SauceNaoAPI.additional.header.ResultMetaInfo
|
||||||
|
import com.github.insanusmokrassar.SauceNaoAPI.additional.header.adapted
|
||||||
|
import com.github.insanusmokrassar.SauceNaoAPI.additional.results.AdaptedResult
|
||||||
|
import com.github.insanusmokrassar.SauceNaoAPI.additional.results.adapted
|
||||||
|
import com.github.insanusmokrassar.SauceNaoAPI.models.SauceNaoAnswer
|
||||||
|
|
||||||
|
val SauceNaoAnswer.adapted: AdaptedAnswer
|
||||||
|
get() = header.adapted.let { resultMetainfo ->
|
||||||
|
val adaptedResults = results.map {
|
||||||
|
it.adapted(resultMetainfo)
|
||||||
|
}
|
||||||
|
AdaptedAnswer(
|
||||||
|
resultMetainfo,
|
||||||
|
adaptedResults
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class AdaptedAnswer(
|
||||||
|
val resultMetaInfo: ResultMetaInfo,
|
||||||
|
val results: List<AdaptedResult>
|
||||||
|
)
|
@ -2,13 +2,13 @@ package com.github.insanusmokrassar.SauceNaoAPI.additional.header
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.SauceNaoAPI.models.Header
|
import com.github.insanusmokrassar.SauceNaoAPI.models.Header
|
||||||
|
|
||||||
data class ResultMetainfo(
|
data class ResultMetaInfo(
|
||||||
val accountInfo: AccountInfo = AccountInfo(),
|
val accountInfo: AccountInfo = AccountInfo(),
|
||||||
val resultsInfo: QueryResultsMetainfo = QueryResultsMetainfo()
|
val resultsInfo: QueryResultsMetainfo = QueryResultsMetainfo()
|
||||||
)
|
)
|
||||||
|
|
||||||
val Header.adapted
|
val Header.adapted
|
||||||
get() = ResultMetainfo(
|
get() = ResultMetaInfo(
|
||||||
accountInfo,
|
accountInfo,
|
||||||
queryResults
|
queryResults
|
||||||
)
|
)
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.github.insanusmokrassar.SauceNaoAPI.additional.results
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.SauceNaoAPI.additional.header.IndexInfo
|
||||||
|
import com.github.insanusmokrassar.SauceNaoAPI.additional.header.ResultMetaInfo
|
||||||
|
import com.github.insanusmokrassar.SauceNaoAPI.models.Result
|
||||||
|
import com.github.insanusmokrassar.SauceNaoAPI.models.ResultData
|
||||||
|
|
||||||
|
fun Result.adapted(
|
||||||
|
resultMetaInfo: ResultMetaInfo
|
||||||
|
): AdaptedResult = AdaptedResult(
|
||||||
|
ResultHeader(
|
||||||
|
header.similarity,
|
||||||
|
header.thumbnail,
|
||||||
|
resultMetaInfo.resultsInfo.indexesInfo.firstOrNull { it.id == header.indexId } ?: IndexInfo(header.indexId)
|
||||||
|
),
|
||||||
|
data
|
||||||
|
)
|
||||||
|
|
||||||
|
data class AdaptedResult(
|
||||||
|
val resultHeader: ResultHeader,
|
||||||
|
val resultData: ResultData
|
||||||
|
)
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.github.insanusmokrassar.SauceNaoAPI.additional.results
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.SauceNaoAPI.additional.header.IndexInfo
|
||||||
|
|
||||||
|
data class ResultHeader(
|
||||||
|
val similarity: Float,
|
||||||
|
val thumbnail: String,
|
||||||
|
val index: IndexInfo
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user