Add mobile devices management mappers
This commit is contained in:
parent
fa72395026
commit
da789f1fd7
4 changed files with 48 additions and 5 deletions
|
@ -6,8 +6,6 @@ import io.github.wulkanowy.api.messages.Folder
|
|||
import io.github.wulkanowy.api.messages.Recipient
|
||||
import io.github.wulkanowy.api.messages.ReportingUnit
|
||||
import io.github.wulkanowy.api.messages.SentMessage
|
||||
import io.github.wulkanowy.api.mobile.Device
|
||||
import io.github.wulkanowy.api.mobile.TokenResponse
|
||||
import io.github.wulkanowy.api.resettableLazy
|
||||
import io.github.wulkanowy.api.resettableManager
|
||||
import io.github.wulkanowy.api.school.School
|
||||
|
@ -23,6 +21,8 @@ import io.github.wulkanowy.sdk.grades.mapGrades
|
|||
import io.github.wulkanowy.sdk.grades.mapGradesSummary
|
||||
import io.github.wulkanowy.sdk.homework.mapHomework
|
||||
import io.github.wulkanowy.sdk.messages.mapMessages
|
||||
import io.github.wulkanowy.sdk.mobile.mapDevices
|
||||
import io.github.wulkanowy.sdk.mobile.mapToken
|
||||
import io.github.wulkanowy.sdk.notes.mapNotes
|
||||
import io.github.wulkanowy.sdk.pojo.*
|
||||
import io.github.wulkanowy.sdk.register.mapSemesters
|
||||
|
@ -346,14 +346,14 @@ class Sdk {
|
|||
|
||||
fun getRegisteredDevices(): Single<List<Device>> {
|
||||
return when (mode) {
|
||||
Mode.HYBRID, Mode.SCRAPPER -> scrapper.getRegisteredDevices()
|
||||
Mode.HYBRID, Mode.SCRAPPER -> scrapper.getRegisteredDevices().map { it.mapDevices() }
|
||||
Mode.API -> throw FeatureNotAvailable("Devices management is not available in API mode")
|
||||
}
|
||||
}
|
||||
|
||||
fun getToken(): Single<TokenResponse> {
|
||||
fun getToken(): Single<Token> {
|
||||
return when (mode) {
|
||||
Mode.HYBRID, Mode.SCRAPPER -> scrapper.getToken()
|
||||
Mode.HYBRID, Mode.SCRAPPER -> scrapper.getToken().map { it.mapToken() }
|
||||
Mode.API -> throw FeatureNotAvailable("Devices management is not available in API mode")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package io.github.wulkanowy.sdk.mobile
|
||||
|
||||
import io.github.wulkanowy.api.mobile.Device as ScrapperDevice
|
||||
import io.github.wulkanowy.api.mobile.TokenResponse
|
||||
import io.github.wulkanowy.sdk.pojo.Device
|
||||
import io.github.wulkanowy.sdk.pojo.Token
|
||||
import io.github.wulkanowy.sdk.toLocalDateTime
|
||||
|
||||
fun TokenResponse.mapToken(): Token {
|
||||
return Token(
|
||||
token = token,
|
||||
symbol = symbol,
|
||||
pin = pin,
|
||||
qrCodeImage = qrCodeImage
|
||||
)
|
||||
}
|
||||
|
||||
fun List<ScrapperDevice>.mapDevices(): List<Device> {
|
||||
return map {
|
||||
Device(
|
||||
id = it.id,
|
||||
name = it.name,
|
||||
date = it.date.toLocalDateTime()
|
||||
)
|
||||
}
|
||||
}
|
9
src/main/kotlin/io/github/wulkanowy/sdk/pojo/Device.kt
Normal file
9
src/main/kotlin/io/github/wulkanowy/sdk/pojo/Device.kt
Normal file
|
@ -0,0 +1,9 @@
|
|||
package io.github.wulkanowy.sdk.pojo
|
||||
|
||||
import org.threeten.bp.LocalDateTime
|
||||
|
||||
data class Device(
|
||||
val id: Int,
|
||||
val name: String,
|
||||
val date: LocalDateTime
|
||||
)
|
8
src/main/kotlin/io/github/wulkanowy/sdk/pojo/Token.kt
Normal file
8
src/main/kotlin/io/github/wulkanowy/sdk/pojo/Token.kt
Normal file
|
@ -0,0 +1,8 @@
|
|||
package io.github.wulkanowy.sdk.pojo
|
||||
|
||||
data class Token(
|
||||
val token: String,
|
||||
val symbol: String,
|
||||
val pin: String,
|
||||
val qrCodeImage: String
|
||||
)
|
Loading…
Reference in a new issue