From da789f1fd70af2a66a12c16d366b22836d4b23a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Wed, 26 Jun 2019 13:31:25 +0200 Subject: [PATCH] Add mobile devices management mappers --- .../kotlin/io/github/wulkanowy/sdk/Sdk.kt | 10 +++---- .../sdk/mobile/MobileDevicesMapper.kt | 26 +++++++++++++++++++ .../io/github/wulkanowy/sdk/pojo/Device.kt | 9 +++++++ .../io/github/wulkanowy/sdk/pojo/Token.kt | 8 ++++++ 4 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 src/main/kotlin/io/github/wulkanowy/sdk/mobile/MobileDevicesMapper.kt create mode 100644 src/main/kotlin/io/github/wulkanowy/sdk/pojo/Device.kt create mode 100644 src/main/kotlin/io/github/wulkanowy/sdk/pojo/Token.kt diff --git a/src/main/kotlin/io/github/wulkanowy/sdk/Sdk.kt b/src/main/kotlin/io/github/wulkanowy/sdk/Sdk.kt index 36b9bd6b..8e51e7a6 100644 --- a/src/main/kotlin/io/github/wulkanowy/sdk/Sdk.kt +++ b/src/main/kotlin/io/github/wulkanowy/sdk/Sdk.kt @@ -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> { 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 { + fun getToken(): Single { 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") } } diff --git a/src/main/kotlin/io/github/wulkanowy/sdk/mobile/MobileDevicesMapper.kt b/src/main/kotlin/io/github/wulkanowy/sdk/mobile/MobileDevicesMapper.kt new file mode 100644 index 00000000..8250649e --- /dev/null +++ b/src/main/kotlin/io/github/wulkanowy/sdk/mobile/MobileDevicesMapper.kt @@ -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.mapDevices(): List { + return map { + Device( + id = it.id, + name = it.name, + date = it.date.toLocalDateTime() + ) + } +} diff --git a/src/main/kotlin/io/github/wulkanowy/sdk/pojo/Device.kt b/src/main/kotlin/io/github/wulkanowy/sdk/pojo/Device.kt new file mode 100644 index 00000000..a8c92b59 --- /dev/null +++ b/src/main/kotlin/io/github/wulkanowy/sdk/pojo/Device.kt @@ -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 +) diff --git a/src/main/kotlin/io/github/wulkanowy/sdk/pojo/Token.kt b/src/main/kotlin/io/github/wulkanowy/sdk/pojo/Token.kt new file mode 100644 index 00000000..b2c1137c --- /dev/null +++ b/src/main/kotlin/io/github/wulkanowy/sdk/pojo/Token.kt @@ -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 +)