From 32d6505e4b238dcc264935a87e1f5a8d5ea046e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Sun, 16 Apr 2023 09:40:48 +0200 Subject: [PATCH] Add some missing API --- .github/workflows/test.yml | 1 + sdk-hebe/api/sdk-hebe.api | 273 ++++++++++++++++++ sdk-hebe/build.gradle | 1 + .../github/wulkanowy/sdk/hebe/ApiRequest.kt | 2 +- .../github/wulkanowy/sdk/hebe/ApiResponse.kt | 2 +- .../io/github/wulkanowy/sdk/hebe/Hebe.kt | 11 +- .../sdk/hebe/ResettableLazyManager.kt | 10 +- .../sdk/hebe/interceptor/ErrorInterceptor.kt | 2 +- .../sdk/hebe/interceptor/SignInterceptor.kt | 2 +- .../sdk/hebe/register/RegisterRequest.kt | 4 +- .../sdk/hebe/repository/RegisterRepository.kt | 35 ++- .../sdk/hebe/repository/RepositoryManager.kt | 22 +- .../hebe/repository/RoutingRulesRepository.kt | 2 +- .../sdk/hebe/service/RegisterService.kt | 2 +- .../sdk/hebe/service/RoutingRulesService.kt | 2 +- sdk-scrapper/api/sdk-scrapper.api | 8 +- .../github/wulkanowy/sdk/scrapper/Scrapper.kt | 4 +- .../sdk/scrapper/service/ServiceManager.kt | 6 +- .../sdk/scrapper/ScrapperRemoteTest.kt | 2 +- .../wulkanowy/sdk/scrapper/ScrapperTest.kt | 2 +- .../repository/StudentStartRepositoryTest.kt | 2 +- .../scrapper/service/ServiceManagerTest.kt | 6 +- sdk/api/sdk.api | 34 ++- .../kotlin/io/github/wulkanowy/sdk/Sdk.kt | 74 ++--- .../wulkanowy/sdk/mapper/StudentsMapper.kt | 109 +++++-- .../io/github/wulkanowy/sdk/pojo/Student.kt | 7 +- 26 files changed, 503 insertions(+), 122 deletions(-) create mode 100644 sdk-hebe/api/sdk-hebe.api diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 88efcef6..64e60427 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,6 +33,7 @@ jobs: - name: API changes check run: | ./gradlew :sdk:apiCheck --stacktrace + ./gradlew :sdk-hebe:apiCheck --stacktrace ./gradlew :sdk-scrapper:apiCheck --stacktrace - uses: codecov/codecov-action@v1 diff --git a/sdk-hebe/api/sdk-hebe.api b/sdk-hebe/api/sdk-hebe.api new file mode 100644 index 00000000..21579e20 --- /dev/null +++ b/sdk-hebe/api/sdk-hebe.api @@ -0,0 +1,273 @@ +public final class io/github/wulkanowy/sdk/hebe/Hebe { + public fun ()V + public final fun getBaseUrl ()Ljava/lang/String; + public final fun getDeviceModel ()Ljava/lang/String; + public final fun getLogLevel ()Lokhttp3/logging/HttpLoggingInterceptor$Level; + public final fun getPrivateKey ()Ljava/lang/String; + public final fun getSchoolSymbol ()Ljava/lang/String; + public final fun getStudents (Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun register (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun setBaseUrl (Ljava/lang/String;)V + public final fun setDeviceModel (Ljava/lang/String;)V + public final fun setLogLevel (Lokhttp3/logging/HttpLoggingInterceptor$Level;)V + public final fun setPrivateKey (Ljava/lang/String;)V + public final fun setSchoolSymbol (Ljava/lang/String;)V +} + +public final class io/github/wulkanowy/sdk/hebe/exception/InvalidTokenException : java/io/IOException { + public fun (Ljava/lang/String;)V +} + +public final class io/github/wulkanowy/sdk/hebe/exception/UnknownTokenException : java/io/IOException { + public fun (Ljava/lang/String;)V +} + +public final class io/github/wulkanowy/sdk/hebe/register/RegisterResponse { + public fun (ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + public final fun component1 ()I + public final fun component2 ()Ljava/lang/String; + public final fun component3 ()Ljava/lang/String; + public final fun component4 ()Ljava/lang/String; + public final fun copy (ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lio/github/wulkanowy/sdk/hebe/register/RegisterResponse; + public static synthetic fun copy$default (Lio/github/wulkanowy/sdk/hebe/register/RegisterResponse;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lio/github/wulkanowy/sdk/hebe/register/RegisterResponse; + public fun equals (Ljava/lang/Object;)Z + public final fun getLoginId ()I + public final fun getRestUrl ()Ljava/lang/String; + public final fun getUserLogin ()Ljava/lang/String; + public final fun getUserName ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class io/github/wulkanowy/sdk/hebe/register/StudentInfo { + public fun (Ljava/util/List;Ljava/lang/String;Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$ConstituentUnit;Ljava/util/List;ZLjava/lang/String;Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Journal;Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Login;Ljava/lang/String;Ljava/util/List;Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Pupil;Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$SenderEntry;Ljava/lang/String;Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Unit;)V + public final fun getCapabilities ()Ljava/util/List; + public final fun getClassDisplay ()Ljava/lang/String; + public final fun getConstituentUnit ()Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$ConstituentUnit; + public final fun getEducators ()Ljava/util/List; + public final fun getFullSync ()Z + public final fun getInfoDisplay ()Ljava/lang/String; + public final fun getJournal ()Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Journal; + public final fun getLogin ()Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Login; + public final fun getPartition ()Ljava/lang/String; + public final fun getPeriods ()Ljava/util/List; + public final fun getPupil ()Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Pupil; + public final fun getSenderEntry ()Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$SenderEntry; + public final fun getTopLevelPartition ()Ljava/lang/String; + public final fun getUnit ()Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Unit; +} + +public final class io/github/wulkanowy/sdk/hebe/register/StudentInfo$ConstituentUnit { + public fun (Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + public final fun component1 ()Ljava/lang/String; + public final fun component2 ()I + public final fun component3 ()Ljava/lang/String; + public final fun component4 ()Ljava/lang/String; + public final fun component5 ()Ljava/lang/String; + public final fun component6 ()Ljava/lang/String; + public final fun copy (Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$ConstituentUnit; + public static synthetic fun copy$default (Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$ConstituentUnit;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$ConstituentUnit; + public fun equals (Ljava/lang/Object;)Z + public final fun getAddress ()Ljava/lang/String; + public final fun getId ()I + public final fun getName ()Ljava/lang/String; + public final fun getPatron ()Ljava/lang/String; + public final fun getSchoolTopic ()Ljava/lang/String; + public final fun getShort ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class io/github/wulkanowy/sdk/hebe/register/StudentInfo$Educator { + public fun (ILjava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/util/List;)V + public final fun component1 ()I + public final fun component2 ()Ljava/lang/String; + public final fun component3 ()I + public final fun component4 ()Ljava/lang/String; + public final fun component5 ()Ljava/lang/String; + public final fun component6 ()Ljava/util/List; + public final fun copy (ILjava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/util/List;)Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Educator; + public static synthetic fun copy$default (Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Educator;ILjava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/util/List;ILjava/lang/Object;)Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Educator; + public fun equals (Ljava/lang/Object;)Z + public final fun getId ()I + public final fun getInitials ()Ljava/lang/String; + public final fun getLoginId ()I + public final fun getName ()Ljava/lang/String; + public final fun getRoles ()Ljava/util/List; + public final fun getSurname ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class io/github/wulkanowy/sdk/hebe/register/StudentInfo$Educator$Role { + public fun (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)V + public final fun component1 ()Ljava/lang/String; + public final fun component10 ()Ljava/lang/String; + public final fun component2 ()Ljava/lang/String; + public final fun component3 ()Ljava/lang/String; + public final fun component4 ()Ljava/lang/String; + public final fun component5 ()Ljava/lang/String; + public final fun component6 ()Ljava/lang/String; + public final fun component7 ()Ljava/lang/String; + public final fun component8 ()I + public final fun component9 ()Ljava/lang/String; + public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Educator$Role; + public static synthetic fun copy$default (Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Educator$Role;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Educator$Role; + public fun equals (Ljava/lang/Object;)Z + public final fun getAddress ()Ljava/lang/String; + public final fun getAddressHash ()Ljava/lang/String; + public final fun getClassSymbol ()Ljava/lang/String; + public final fun getConstituentUnitSymbol ()Ljava/lang/String; + public final fun getInitials ()Ljava/lang/String; + public final fun getName ()Ljava/lang/String; + public final fun getRoleName ()Ljava/lang/String; + public final fun getRoleOrder ()I + public final fun getSurname ()Ljava/lang/String; + public final fun getUnitSymbol ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class io/github/wulkanowy/sdk/hebe/register/StudentInfo$Journal { + public fun (ILio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate;Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate;)V + public final fun component1 ()I + public final fun component2 ()Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate; + public final fun component3 ()Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate; + public final fun copy (ILio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate;Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate;)Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Journal; + public static synthetic fun copy$default (Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Journal;ILio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate;Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate;ILjava/lang/Object;)Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Journal; + public fun equals (Ljava/lang/Object;)Z + public final fun getId ()I + public final fun getYearEnd ()Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate; + public final fun getYearStart ()Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class io/github/wulkanowy/sdk/hebe/register/StudentInfo$Login { + public fun (Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + public final fun component1 ()Ljava/lang/String; + public final fun component2 ()Ljava/lang/String; + public final fun component3 ()I + public final fun component4 ()Ljava/lang/String; + public final fun component5 ()Ljava/lang/String; + public final fun component6 ()Ljava/lang/String; + public final fun component7 ()Ljava/lang/String; + public final fun copy (Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Login; + public static synthetic fun copy$default (Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Login;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Login; + public fun equals (Ljava/lang/Object;)Z + public final fun getDisplayName ()Ljava/lang/String; + public final fun getFirstName ()Ljava/lang/String; + public final fun getId ()I + public final fun getLoginRole ()Ljava/lang/String; + public final fun getSecondName ()Ljava/lang/String; + public final fun getSurname ()Ljava/lang/String; + public final fun getValue ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class io/github/wulkanowy/sdk/hebe/register/StudentInfo$Period { + public fun (ZLio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate;IZIILio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate;)V + public final fun component1 ()Z + public final fun component2 ()Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate; + public final fun component3 ()I + public final fun component4 ()Z + public final fun component5 ()I + public final fun component6 ()I + public final fun component7 ()Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate; + public final fun copy (ZLio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate;IZIILio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate;)Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Period; + public static synthetic fun copy$default (Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Period;ZLio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate;IZIILio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate;ILjava/lang/Object;)Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Period; + public fun equals (Ljava/lang/Object;)Z + public final fun getCurrent ()Z + public final fun getEnd ()Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate; + public final fun getId ()I + public final fun getLast ()Z + public final fun getLevel ()I + public final fun getNumber ()I + public final fun getStart ()Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class io/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate { + public fun (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;J)V + public final fun component1 ()Ljava/lang/String; + public final fun component2 ()Ljava/lang/String; + public final fun component3 ()Ljava/lang/String; + public final fun component4 ()J + public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;J)Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate; + public static synthetic fun copy$default (Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JILjava/lang/Object;)Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$PeriodDate; + public fun equals (Ljava/lang/Object;)Z + public final fun getDate ()Ljava/lang/String; + public final fun getDateDisplay ()Ljava/lang/String; + public final fun getTime ()Ljava/lang/String; + public final fun getTimestamp ()J + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class io/github/wulkanowy/sdk/hebe/register/StudentInfo$Pupil { + public fun (Ljava/lang/String;IILjava/lang/String;Ljava/lang/String;ZLjava/lang/String;)V + public final fun component1 ()Ljava/lang/String; + public final fun component2 ()I + public final fun component3 ()I + public final fun component4 ()Ljava/lang/String; + public final fun component5 ()Ljava/lang/String; + public final fun component6 ()Z + public final fun component7 ()Ljava/lang/String; + public final fun copy (Ljava/lang/String;IILjava/lang/String;Ljava/lang/String;ZLjava/lang/String;)Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Pupil; + public static synthetic fun copy$default (Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Pupil;Ljava/lang/String;IILjava/lang/String;Ljava/lang/String;ZLjava/lang/String;ILjava/lang/Object;)Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Pupil; + public fun equals (Ljava/lang/Object;)Z + public final fun getFirstName ()Ljava/lang/String; + public final fun getId ()I + public final fun getLoginId ()I + public final fun getLoginValue ()Ljava/lang/String; + public final fun getSecondName ()Ljava/lang/String; + public final fun getSex ()Z + public final fun getSurname ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class io/github/wulkanowy/sdk/hebe/register/StudentInfo$SenderEntry { + public fun (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V + public final fun component1 ()Ljava/lang/String; + public final fun component2 ()Ljava/lang/String; + public final fun component3 ()Ljava/lang/String; + public final fun component4 ()I + public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$SenderEntry; + public static synthetic fun copy$default (Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$SenderEntry;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IILjava/lang/Object;)Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$SenderEntry; + public fun equals (Ljava/lang/Object;)Z + public final fun getAddress ()Ljava/lang/String; + public final fun getAddressHash ()Ljava/lang/String; + public final fun getInitials ()Ljava/lang/String; + public final fun getLoginId ()I + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class io/github/wulkanowy/sdk/hebe/register/StudentInfo$Unit { + public fun (Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + public final fun component1 ()Ljava/lang/String; + public final fun component2 ()Ljava/lang/String; + public final fun component3 ()I + public final fun component4 ()Ljava/lang/String; + public final fun component5 ()Ljava/lang/String; + public final fun component6 ()Ljava/lang/String; + public final fun component7 ()Ljava/lang/String; + public final fun component8 ()Ljava/lang/String; + public final fun copy (Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Unit; + public static synthetic fun copy$default (Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Unit;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lio/github/wulkanowy/sdk/hebe/register/StudentInfo$Unit; + public fun equals (Ljava/lang/Object;)Z + public final fun getAddress ()Ljava/lang/String; + public final fun getDisplayName ()Ljava/lang/String; + public final fun getId ()I + public final fun getName ()Ljava/lang/String; + public final fun getPatron ()Ljava/lang/String; + public final fun getRestUrl ()Ljava/lang/String; + public final fun getShort ()Ljava/lang/String; + public final fun getSymbol ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + diff --git a/sdk-hebe/build.gradle b/sdk-hebe/build.gradle index 60967d7c..89c7e2af 100644 --- a/sdk-hebe/build.gradle +++ b/sdk-hebe/build.gradle @@ -1,6 +1,7 @@ plugins { id 'java' id 'org.jetbrains.kotlin.jvm' + alias(libs.plugins.validator) id 'jacoco' } diff --git a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/ApiRequest.kt b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/ApiRequest.kt index 5858ff5c..bc78a76a 100644 --- a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/ApiRequest.kt +++ b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/ApiRequest.kt @@ -6,7 +6,7 @@ import java.time.ZoneOffset.UTC import java.time.format.DateTimeFormatter.ofPattern import java.util.UUID -data class ApiRequest( +internal data class ApiRequest( @SerialName("API") val apiVersion: Int = 1, diff --git a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/ApiResponse.kt b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/ApiResponse.kt index d2854b3c..65c184ef 100644 --- a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/ApiResponse.kt +++ b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/ApiResponse.kt @@ -4,7 +4,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -class ApiResponse { +internal class ApiResponse { @SerialName("Envelope") var envelope: T? = null diff --git a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/Hebe.kt b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/Hebe.kt index fcf37e9e..57c787e1 100644 --- a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/Hebe.kt +++ b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/Hebe.kt @@ -46,10 +46,17 @@ class Hebe { private val routes by resettableLazy(resettableManager) { serviceManager.getRoutesRepository() } - suspend fun register(privateKey: String, certificateId: String, token: String, pin: String, symbol: String): ApiResponse { + suspend fun register(privateKey: String, certificateId: String, firebaseToken: String, token: String, pin: String, symbol: String): RegisterResponse { return serviceManager .getRegisterRepository(routes.getRouteByToken(token), symbol) - .registerDevice(privateKey, certificateId, deviceModel, pin, token) + .registerDevice( + privateKey = privateKey, + certificateId = certificateId, + deviceModel = deviceModel, + firebaseToken = firebaseToken, + pin = pin, + token = token, + ) } suspend fun getStudents(url: String, symbol: String): List { diff --git a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/ResettableLazyManager.kt b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/ResettableLazyManager.kt index 0f5b56c2..e37c5940 100644 --- a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/ResettableLazyManager.kt +++ b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/ResettableLazyManager.kt @@ -6,7 +6,7 @@ import kotlin.reflect.KProperty /** * see https://stackoverflow.com/a/35757638/6695449 */ -class ResettableLazyManager { +internal class ResettableLazyManager { // we synchronize to make sure the timing of a reset() call and new inits do not collide val managedDelegates = LinkedList() @@ -24,11 +24,11 @@ class ResettableLazyManager { } } -interface Resettable { +internal interface Resettable { fun reset() } -class ResettableLazy(val manager: ResettableLazyManager, val init: () -> PROPTYPE) : Resettable { +internal class ResettableLazy(val manager: ResettableLazyManager, val init: () -> PROPTYPE) : Resettable { @Volatile var lazyHolder = makeInitBlock() @@ -48,8 +48,8 @@ class ResettableLazy(val manager: ResettableLazyManager, val init: () } } -fun resettableLazy(manager: ResettableLazyManager, init: () -> PROPTYPE): ResettableLazy { +internal fun resettableLazy(manager: ResettableLazyManager, init: () -> PROPTYPE): ResettableLazy { return ResettableLazy(manager, init) } -fun resettableManager(): ResettableLazyManager = ResettableLazyManager() +internal fun resettableManager(): ResettableLazyManager = ResettableLazyManager() diff --git a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/interceptor/ErrorInterceptor.kt b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/interceptor/ErrorInterceptor.kt index b5943717..8822dfd5 100644 --- a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/interceptor/ErrorInterceptor.kt +++ b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/interceptor/ErrorInterceptor.kt @@ -3,7 +3,7 @@ package io.github.wulkanowy.sdk.hebe.interceptor import okhttp3.Interceptor import okhttp3.Response -class ErrorInterceptor : Interceptor { +internal class ErrorInterceptor : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { return chain.proceed(chain.request()) diff --git a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/interceptor/SignInterceptor.kt b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/interceptor/SignInterceptor.kt index 5318ff92..8d8ddd37 100644 --- a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/interceptor/SignInterceptor.kt +++ b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/interceptor/SignInterceptor.kt @@ -3,7 +3,7 @@ package io.github.wulkanowy.sdk.hebe.interceptor import okhttp3.Interceptor import okhttp3.Response -class SignInterceptor(private val privateKey: String) : Interceptor { +internal class SignInterceptor(private val privateKey: String) : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { return chain.proceed(chain.request()) diff --git a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/register/RegisterRequest.kt b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/register/RegisterRequest.kt index dc01fdb6..eca2773a 100644 --- a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/register/RegisterRequest.kt +++ b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/register/RegisterRequest.kt @@ -3,7 +3,7 @@ package io.github.wulkanowy.sdk.hebe.register import kotlinx.serialization.SerialName import java.util.UUID -data class RegisterRequest( +internal data class RegisterRequest( @SerialName("Certificate") val certificate: String, @@ -27,5 +27,5 @@ data class RegisterRequest( val securityToken: String, @SerialName("SelfIdentifier") - val selfIdentifier: String = UUID.randomUUID().toString() + val selfIdentifier: String = UUID.randomUUID().toString(), ) diff --git a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/repository/RegisterRepository.kt b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/repository/RegisterRepository.kt index 701839d9..b3889bbc 100644 --- a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/repository/RegisterRepository.kt +++ b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/repository/RegisterRepository.kt @@ -7,23 +7,28 @@ import io.github.wulkanowy.sdk.hebe.register.RegisterResponse import io.github.wulkanowy.sdk.hebe.register.StudentInfo import io.github.wulkanowy.sdk.hebe.service.RegisterService -class RegisterRepository(private val service: RegisterService) { +internal class RegisterRepository(private val service: RegisterService) { - suspend fun registerDevice(privateKey: String, certificateId: String, deviceModel: String, pin: String, token: String): ApiResponse { - return service.registerDevice( - ApiRequest( - certificateId = certificateId, - firebaseToken = "", - envelope = RegisterRequest( - certificate = privateKey, - certificateThumbprint = certificateId, - deviceModel = deviceModel, - pin = pin, - securityToken = token, - ), + suspend fun registerDevice( + privateKey: String, + certificateId: String, + deviceModel: String, + firebaseToken: String, + pin: String, + token: String, + ): RegisterResponse = service.registerDevice( + ApiRequest( + certificateId = certificateId, + firebaseToken = firebaseToken, + envelope = RegisterRequest( + certificate = privateKey, + certificateThumbprint = certificateId, + deviceModel = deviceModel, + pin = pin, + securityToken = token, ), - ) - } + ), + ).envelope!! suspend fun getStudentInfo(): List { return service.getStudentsInfo().envelope!! diff --git a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/repository/RepositoryManager.kt b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/repository/RepositoryManager.kt index 57b9e9db..9049f96a 100644 --- a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/repository/RepositoryManager.kt +++ b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/repository/RepositoryManager.kt @@ -13,7 +13,7 @@ import retrofit2.Retrofit import retrofit2.converter.scalars.ScalarsConverterFactory import retrofit2.create -class RepositoryManager( +internal class RepositoryManager( private val logLevel: HttpLoggingInterceptor.Level, private val privateKey: String, private val interceptors: MutableList>, @@ -32,14 +32,24 @@ class RepositoryManager( } fun getRoutesRepository(): RoutingRulesRepository { - return RoutingRulesRepository(getRetrofitBuilder(interceptors).baseUrl("http://komponenty.vulcan.net.pl").build().create()) + return RoutingRulesRepository( + getRetrofitBuilder(interceptors) + .baseUrl("http://komponenty.vulcan.net.pl") + .build() + .create(), + ) } - fun getRegisterRepository(baseUrl: String, symbol: String) = getRegisterRepository("${baseUrl.removeSuffix("/")}/$symbol") + internal fun getRegisterRepository(baseUrl: String, symbol: String): RegisterRepository = getRegisterRepository( + "${baseUrl.removeSuffix("/")}/$symbol", + ) - fun getRegisterRepository(baseUrl: String): RegisterRepository { - return RegisterRepository(getRetrofitBuilder(interceptors).baseUrl("${baseUrl.removeSuffix("/")}/api/mobile/register/").build().create()) - } + private fun getRegisterRepository(baseUrl: String): RegisterRepository = RegisterRepository( + getRetrofitBuilder(interceptors) + .baseUrl("${baseUrl.removeSuffix("/")}/api/mobile/register/") + .build() + .create(), + ) @OptIn(ExperimentalSerializationApi::class) private fun getRetrofitBuilder(interceptors: MutableList>): Retrofit.Builder { diff --git a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/repository/RoutingRulesRepository.kt b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/repository/RoutingRulesRepository.kt index 83361069..046deb43 100644 --- a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/repository/RoutingRulesRepository.kt +++ b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/repository/RoutingRulesRepository.kt @@ -4,7 +4,7 @@ import io.github.wulkanowy.sdk.hebe.exception.InvalidTokenException import io.github.wulkanowy.sdk.hebe.exception.UnknownTokenException import io.github.wulkanowy.sdk.hebe.service.RoutingRulesService -class RoutingRulesRepository(private val api: RoutingRulesService) { +internal class RoutingRulesRepository(private val api: RoutingRulesService) { suspend fun getRouteByToken(token: String): String { if (token.length < 4) throw InvalidTokenException("Token '$token' is too short") diff --git a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/service/RegisterService.kt b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/service/RegisterService.kt index 5637f2b2..67f7b382 100644 --- a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/service/RegisterService.kt +++ b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/service/RegisterService.kt @@ -8,7 +8,7 @@ import io.github.wulkanowy.sdk.hebe.register.StudentInfo import retrofit2.http.GET import retrofit2.http.POST -interface RegisterService { +internal interface RegisterService { @POST("new") suspend fun registerDevice(request: ApiRequest): ApiResponse diff --git a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/service/RoutingRulesService.kt b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/service/RoutingRulesService.kt index cf9e0c7f..04268c01 100644 --- a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/service/RoutingRulesService.kt +++ b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/service/RoutingRulesService.kt @@ -2,7 +2,7 @@ package io.github.wulkanowy.sdk.hebe.service import retrofit2.http.GET -interface RoutingRulesService { +internal interface RoutingRulesService { @GET("/UonetPlusMobile/RoutingRules.txt") suspend fun getRoutingRules(): String diff --git a/sdk-scrapper/api/sdk-scrapper.api b/sdk-scrapper/api/sdk-scrapper.api index ab86ef52..f9402de0 100644 --- a/sdk-scrapper/api/sdk-scrapper.api +++ b/sdk-scrapper/api/sdk-scrapper.api @@ -54,7 +54,7 @@ public final class io/github/wulkanowy/sdk/scrapper/Scrapper { public final fun getRecipients (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getRegisteredDevices (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getSchool (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun getSchoolSymbol ()Ljava/lang/String; + public final fun getSchoolId ()Ljava/lang/String; public final fun getSchoolYear ()I public final fun getSelfGovernments (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getSemesters (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -89,7 +89,7 @@ public final class io/github/wulkanowy/sdk/scrapper/Scrapper { public final fun setLogLevel (Lokhttp3/logging/HttpLoggingInterceptor$Level;)V public final fun setLoginType (Lio/github/wulkanowy/sdk/scrapper/Scrapper$LoginType;)V public final fun setPassword (Ljava/lang/String;)V - public final fun setSchoolSymbol (Ljava/lang/String;)V + public final fun setSchoolId (Ljava/lang/String;)V public final fun setSchoolYear (I)V public final fun setSsl (Z)V public final fun setStudentId (I)V @@ -111,6 +111,10 @@ public final class io/github/wulkanowy/sdk/scrapper/Scrapper$LoginType : java/la public static fun values ()[Lio/github/wulkanowy/sdk/scrapper/Scrapper$LoginType; } +public final class io/github/wulkanowy/sdk/scrapper/UtilsKt { + public static final fun getNormalizedSymbol (Ljava/lang/String;)Ljava/lang/String; +} + public final class io/github/wulkanowy/sdk/scrapper/attendance/Absent { public fun (Ljava/time/LocalDateTime;Ljava/lang/Integer;)V public final fun component1 ()Ljava/time/LocalDateTime; diff --git a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Scrapper.kt b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Scrapper.kt index bcc67d24..bb48697a 100644 --- a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Scrapper.kt +++ b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Scrapper.kt @@ -109,7 +109,7 @@ class Scrapper { field = value } - var schoolSymbol: String = "" + var schoolId: String = "" set(value) { if (field != value) changeManager.reset() field = value @@ -197,7 +197,7 @@ class Scrapper { symbol = normalizedSymbol, email = email, password = password, - schoolSymbol = schoolSymbol, + schoolId = schoolId, studentId = studentId, diaryId = diaryId, kindergartenDiaryId = kindergartenDiaryId, diff --git a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/service/ServiceManager.kt b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/service/ServiceManager.kt index e1d4c75b..1f46c7c3 100644 --- a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/service/ServiceManager.kt +++ b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/service/ServiceManager.kt @@ -43,7 +43,7 @@ internal class ServiceManager( private val symbol: String, private val email: String, private val password: String, - private val schoolSymbol: String, + private val schoolId: String, private val studentId: Int, private val diaryId: Int, private val kindergartenDiaryId: Int, @@ -65,7 +65,7 @@ internal class ServiceManager( } val urlGenerator by lazy { - UrlGenerator(schema, host, symbol, schoolSymbol) + UrlGenerator(schema, host, symbol, schoolId) } @OptIn(ExperimentalSerializationApi::class) @@ -141,7 +141,7 @@ internal class ServiceManager( } private fun prepareStudentService(withLogin: Boolean, studentInterceptor: Boolean): OkHttpClient.Builder { - if (withLogin && schoolSymbol.isBlank()) throw ScrapperException("School id is not set") + if (withLogin && schoolId.isBlank()) throw ScrapperException("School id is not set") val client = getClientBuilder(loginIntercept = withLogin) if (studentInterceptor) { diff --git a/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/ScrapperRemoteTest.kt b/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/ScrapperRemoteTest.kt index c871c342..0b956960 100644 --- a/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/ScrapperRemoteTest.kt +++ b/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/ScrapperRemoteTest.kt @@ -31,7 +31,7 @@ class ScrapperRemoteTest : BaseTest() { symbol = "powiatwulkanowy" email = "jan@fakelog.cf" password = "jan123" - schoolSymbol = "123456" + schoolId = "123456" studentId = 1 diaryId = 101 kindergartenDiaryId = 1 diff --git a/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/ScrapperTest.kt b/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/ScrapperTest.kt index f7aea065..c34a1466 100644 --- a/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/ScrapperTest.kt +++ b/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/ScrapperTest.kt @@ -20,7 +20,7 @@ class ScrapperTest : BaseLocalTest() { symbol = "Default" email = "jan@fakelog.cf" password = "jan123" - schoolSymbol = "123456" + schoolId = "123456" studentId = 1 diaryId = 101 } diff --git a/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/repository/StudentStartRepositoryTest.kt b/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/repository/StudentStartRepositoryTest.kt index deb0faab..0dbba860 100644 --- a/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/repository/StudentStartRepositoryTest.kt +++ b/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/repository/StudentStartRepositoryTest.kt @@ -18,7 +18,7 @@ class StudentStartRepositoryTest : BaseLocalTest() { symbol = "Default" email = "jan@fakelog.cf" password = "jan123" - schoolSymbol = "123456" + schoolId = "123456" diaryId = 101 } } diff --git a/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/service/ServiceManagerTest.kt b/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/service/ServiceManagerTest.kt index 2378a6de..1888a7a5 100644 --- a/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/service/ServiceManagerTest.kt +++ b/sdk-scrapper/src/test/kotlin/io/github/wulkanowy/sdk/scrapper/service/ServiceManagerTest.kt @@ -29,7 +29,7 @@ class ServiceManagerTest : BaseLocalTest() { symbol = "default", email = "email", password = "password", - schoolSymbol = "schoolSymbol", + schoolId = "schoolSymbol", studentId = 123, diaryId = 101, kindergartenDiaryId = 0, @@ -61,7 +61,7 @@ class ServiceManagerTest : BaseLocalTest() { symbol = "default", email = "email", password = "password", - schoolSymbol = "schoolSymbol", + schoolId = "schoolSymbol", studentId = 123, diaryId = 101, kindergartenDiaryId = 0, @@ -131,7 +131,7 @@ class ServiceManagerTest : BaseLocalTest() { symbol = "default", email = "email", password = "password", - schoolSymbol = "schoolSymbol", + schoolId = "schoolSymbol", studentId = 123, diaryId = 101, kindergartenDiaryId = 0, diff --git a/sdk/api/sdk.api b/sdk/api/sdk.api index 71412d7c..a4b0a7f6 100644 --- a/sdk/api/sdk.api +++ b/sdk/api/sdk.api @@ -12,6 +12,7 @@ public final class io/github/wulkanowy/sdk/Sdk { public final fun getAttendanceSummary (Ljava/lang/Integer;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun getAttendanceSummary$default (Lio/github/wulkanowy/sdk/Sdk;Ljava/lang/Integer;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public final fun getBuildTag ()Ljava/lang/String; + public final fun getCertKey ()Ljava/lang/String; public final fun getClassId ()I public final fun getCompletedLessons (Ljava/time/LocalDate;Ljava/time/LocalDate;ILkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun getCompletedLessons$default (Lio/github/wulkanowy/sdk/Sdk;Ljava/time/LocalDate;Ljava/time/LocalDate;ILkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; @@ -46,10 +47,12 @@ public final class io/github/wulkanowy/sdk/Sdk { public final fun getMessageReplayDetails (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getMessages (Lio/github/wulkanowy/sdk/pojo/Folder;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun getMessages$default (Lio/github/wulkanowy/sdk/Sdk;Lio/github/wulkanowy/sdk/pojo/Folder;Ljava/lang/String;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public final fun getMobileBaseUrl ()Ljava/lang/String; public final fun getMode ()Lio/github/wulkanowy/sdk/Sdk$Mode; public final fun getNotes (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getPassword ()Ljava/lang/String; public final fun getPasswordResetCaptchaCode (Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun getPrivateKey ()Ljava/lang/String; public final fun getReceivedMessages (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun getReceivedMessages$default (Lio/github/wulkanowy/sdk/Sdk;Ljava/lang/String;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public final fun getRecipients (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -66,6 +69,9 @@ public final class io/github/wulkanowy/sdk/Sdk { public final fun getStudentInfo (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getStudentPhoto (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getStudentThreats (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun getStudentsFromHebe (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun getStudentsHybrid (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static synthetic fun getStudentsHybrid$default (Lio/github/wulkanowy/sdk/Sdk;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public final fun getStudentsTrips (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getSubjects (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getSymbol ()Ljava/lang/String; @@ -79,6 +85,7 @@ public final class io/github/wulkanowy/sdk/Sdk { public final fun sendPasswordResetRequest (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun setAndroidVersion (Ljava/lang/String;)V public final fun setBuildTag (Ljava/lang/String;)V + public final fun setCertKey (Ljava/lang/String;)V public final fun setClassId (I)V public final fun setDiaryId (I)V public final fun setEmail (Ljava/lang/String;)V @@ -86,8 +93,10 @@ public final class io/github/wulkanowy/sdk/Sdk { public final fun setKindergartenDiaryId (I)V public final fun setLogLevel (Lokhttp3/logging/HttpLoggingInterceptor$Level;)V public final fun setLoginType (Lio/github/wulkanowy/sdk/Sdk$ScrapperLoginType;)V + public final fun setMobileBaseUrl (Ljava/lang/String;)V public final fun setMode (Lio/github/wulkanowy/sdk/Sdk$Mode;)V public final fun setPassword (Ljava/lang/String;)V + public final fun setPrivateKey (Ljava/lang/String;)V public final fun setSchoolSymbol (Ljava/lang/String;)V public final fun setSchoolYear (I)V public final fun setScrapperBaseUrl (Ljava/lang/String;)V @@ -103,6 +112,7 @@ public final class io/github/wulkanowy/sdk/Sdk$Companion { } public final class io/github/wulkanowy/sdk/Sdk$Mode : java/lang/Enum { + public static final field HEBE Lio/github/wulkanowy/sdk/Sdk$Mode; public static final field HYBRID Lio/github/wulkanowy/sdk/Sdk$Mode; public static final field SCRAPPER Lio/github/wulkanowy/sdk/Sdk$Mode; public static fun valueOf (Ljava/lang/String;)Lio/github/wulkanowy/sdk/Sdk$Mode; @@ -134,6 +144,10 @@ public final class io/github/wulkanowy/sdk/exception/FeatureNotAvailableExceptio public final class io/github/wulkanowy/sdk/exception/VulcanException : java/io/IOException { } +public final class io/github/wulkanowy/sdk/mapper/StudentsMapperKt { + public static final fun mapHebeUser (Ljava/util/List;Lio/github/wulkanowy/sdk/hebe/register/RegisterResponse;Ljava/lang/String;Ljava/lang/String;)Lio/github/wulkanowy/sdk/pojo/RegisterUser; +} + public final class io/github/wulkanowy/sdk/pojo/Absent { public fun (Ljava/time/LocalDateTime;Ljava/lang/Integer;)V public final fun component1 ()Ljava/time/LocalDateTime; @@ -898,19 +912,27 @@ public final class io/github/wulkanowy/sdk/pojo/RegisterUnit { } public final class io/github/wulkanowy/sdk/pojo/RegisterUser { - public fun (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/github/wulkanowy/sdk/scrapper/Scrapper$LoginType;Ljava/util/List;)V + public fun (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/github/wulkanowy/sdk/scrapper/Scrapper$LoginType;Lio/github/wulkanowy/sdk/Sdk$Mode;Ljava/util/List;)V public final fun component1 ()Ljava/lang/String; public final fun component2 ()Ljava/lang/String; public final fun component3 ()Ljava/lang/String; - public final fun component4 ()Lio/github/wulkanowy/sdk/scrapper/Scrapper$LoginType; - public final fun component5 ()Ljava/util/List; - public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/github/wulkanowy/sdk/scrapper/Scrapper$LoginType;Ljava/util/List;)Lio/github/wulkanowy/sdk/pojo/RegisterUser; - public static synthetic fun copy$default (Lio/github/wulkanowy/sdk/pojo/RegisterUser;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/github/wulkanowy/sdk/scrapper/Scrapper$LoginType;Ljava/util/List;ILjava/lang/Object;)Lio/github/wulkanowy/sdk/pojo/RegisterUser; + public final fun component4 ()Ljava/lang/String; + public final fun component5 ()Ljava/lang/String; + public final fun component6 ()Ljava/lang/String; + public final fun component7 ()Lio/github/wulkanowy/sdk/scrapper/Scrapper$LoginType; + public final fun component8 ()Lio/github/wulkanowy/sdk/Sdk$Mode; + public final fun component9 ()Ljava/util/List; + public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/github/wulkanowy/sdk/scrapper/Scrapper$LoginType;Lio/github/wulkanowy/sdk/Sdk$Mode;Ljava/util/List;)Lio/github/wulkanowy/sdk/pojo/RegisterUser; + public static synthetic fun copy$default (Lio/github/wulkanowy/sdk/pojo/RegisterUser;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/github/wulkanowy/sdk/scrapper/Scrapper$LoginType;Lio/github/wulkanowy/sdk/Sdk$Mode;Ljava/util/List;ILjava/lang/Object;)Lio/github/wulkanowy/sdk/pojo/RegisterUser; public fun equals (Ljava/lang/Object;)Z - public final fun getBaseUrl ()Ljava/lang/String; + public final fun getCertificateKey ()Ljava/lang/String; public final fun getEmail ()Ljava/lang/String; + public final fun getHebeBaseUrl ()Ljava/lang/String; public final fun getLogin ()Ljava/lang/String; + public final fun getLoginMode ()Lio/github/wulkanowy/sdk/Sdk$Mode; public final fun getLoginType ()Lio/github/wulkanowy/sdk/scrapper/Scrapper$LoginType; + public final fun getPrivateKey ()Ljava/lang/String; + public final fun getScrapperBaseUrl ()Ljava/lang/String; public final fun getSymbols ()Ljava/util/List; public fun hashCode ()I public fun toString ()Ljava/lang/String; diff --git a/sdk/src/main/kotlin/io/github/wulkanowy/sdk/Sdk.kt b/sdk/src/main/kotlin/io/github/wulkanowy/sdk/Sdk.kt index 4005275f..4f318618 100644 --- a/sdk/src/main/kotlin/io/github/wulkanowy/sdk/Sdk.kt +++ b/sdk/src/main/kotlin/io/github/wulkanowy/sdk/Sdk.kt @@ -12,7 +12,7 @@ import io.github.wulkanowy.sdk.mapper.mapGradePointsStatistics import io.github.wulkanowy.sdk.mapper.mapGradeStatistics import io.github.wulkanowy.sdk.mapper.mapGrades import io.github.wulkanowy.sdk.mapper.mapGradesSemesterStatistics -import io.github.wulkanowy.sdk.mapper.mapHebeStudents +import io.github.wulkanowy.sdk.mapper.mapHebeUser import io.github.wulkanowy.sdk.mapper.mapHomework import io.github.wulkanowy.sdk.mapper.mapLuckyNumbers import io.github.wulkanowy.sdk.mapper.mapMailboxes @@ -53,6 +53,7 @@ import io.github.wulkanowy.sdk.pojo.MessageDetails import io.github.wulkanowy.sdk.pojo.MessageReplayDetails import io.github.wulkanowy.sdk.pojo.Note import io.github.wulkanowy.sdk.pojo.Recipient +import io.github.wulkanowy.sdk.pojo.RegisterStudent import io.github.wulkanowy.sdk.pojo.RegisterUser import io.github.wulkanowy.sdk.pojo.School import io.github.wulkanowy.sdk.pojo.Semester @@ -136,7 +137,7 @@ class Sdk { var schoolSymbol = "" set(value) { field = value - scrapper.schoolSymbol = value + scrapper.schoolId = value hebe.schoolSymbol = value } @@ -266,13 +267,21 @@ class Sdk { } } - suspend fun getStudentsFromHebe(token: String, pin: String, symbol: String): List { + suspend fun getStudentsFromHebe(token: String, pin: String, symbol: String, firebaseToken: String): RegisterUser { val privateKey = "" // TODO val certificateId = "" // TODO - val students = hebe.register(privateKey, certificateId, token, pin, symbol) - return hebe.getStudents(students.envelope!!.restUrl, symbol) - .mapHebeStudents(certificateId, privateKey) + val registerResponse = hebe.register( + privateKey = privateKey, + certificateId = certificateId, + firebaseToken = firebaseToken, + token = token, + pin = pin, + symbol = symbol, + ) + return hebe + .getStudents(registerResponse.restUrl, symbol) + .mapHebeUser(registerResponse, certificateId, privateKey) } suspend fun getStudentsHybrid( @@ -282,36 +291,35 @@ class Sdk { firebaseToken: String, startSymbol: String = "Default", ) = withContext(Dispatchers.IO) { - getStudentsFromScrapper(email, password, scrapperBaseUrl, startSymbol) - .distinctBy { it.symbol } - .map { scrapperStudent -> - scrapper.let { - it.symbol = scrapperStudent.symbol - it.schoolSymbol = scrapperStudent.schoolSymbol - it.studentId = scrapperStudent.studentId + val scrapperUser = getUserSubjectsFromScrapper(email, password, scrapperBaseUrl, startSymbol) + scrapperUser.symbols + .mapNotNull { symbol -> + val school = symbol.schools + .firstOrNull() ?: return@mapNotNull null + val student = school.subjects + .firstOrNull() as? RegisterStudent ?: return@mapNotNull null + scrapper.also { + it.symbol = symbol.symbol + it.schoolId = school.schoolId + it.studentId = student.studentId it.diaryId = -1 - it.classId = scrapperStudent.classId - it.loginType = Scrapper.LoginType.valueOf(scrapperStudent.loginType.name) + it.classId = student.classId + it.loginType = Scrapper.LoginType.valueOf(scrapperUser.loginType!!.name) } val token = scrapper.getToken() - getStudentsFromHebe(token.token, token.pin, token.symbol).map { student -> - student.copy( - loginMode = Mode.HYBRID, - loginType = scrapperStudent.loginType, - scrapperBaseUrl = scrapperStudent.scrapperBaseUrl, - ) - } - }.toList().flatten() - } - - suspend fun getUserSubjectsFromScrapper(email: String, password: String, scrapperBaseUrl: String, symbol: String = "Default"): RegisterUser = withContext(Dispatchers.IO) { - scrapper.let { - it.baseUrl = scrapperBaseUrl - it.email = email - it.password = password - it.symbol = symbol - it.getUserSubjects() - } + val hebeUser = getStudentsFromHebe( + token = token.token, + pin = token.pin, + symbol = token.symbol, + firebaseToken = firebaseToken, + ) + hebeUser.copy( + loginMode = Mode.HYBRID, + loginType = scrapperUser.loginType, + scrapperBaseUrl = scrapperUser.scrapperBaseUrl, + hebeBaseUrl = hebeUser.hebeBaseUrl, + ) + }.toList() } suspend fun getSemesters(): List = withContext(Dispatchers.IO) { diff --git a/sdk/src/main/kotlin/io/github/wulkanowy/sdk/mapper/StudentsMapper.kt b/sdk/src/main/kotlin/io/github/wulkanowy/sdk/mapper/StudentsMapper.kt index edcb1f27..86596226 100644 --- a/sdk/src/main/kotlin/io/github/wulkanowy/sdk/mapper/StudentsMapper.kt +++ b/sdk/src/main/kotlin/io/github/wulkanowy/sdk/mapper/StudentsMapper.kt @@ -1,29 +1,35 @@ package io.github.wulkanowy.sdk.mapper +import io.github.wulkanowy.sdk.Sdk +import io.github.wulkanowy.sdk.hebe.register.RegisterResponse +import io.github.wulkanowy.sdk.hebe.register.StudentInfo import io.github.wulkanowy.sdk.pojo.RegisterEmployee import io.github.wulkanowy.sdk.pojo.RegisterStudent import io.github.wulkanowy.sdk.pojo.RegisterSubject import io.github.wulkanowy.sdk.pojo.RegisterSymbol import io.github.wulkanowy.sdk.pojo.RegisterUnit import io.github.wulkanowy.sdk.pojo.RegisterUser +import io.github.wulkanowy.sdk.pojo.Semester +import io.github.wulkanowy.sdk.toLocalDate import io.github.wulkanowy.sdk.scrapper.register.RegisterEmployee as ScrapperRegisterEmploye import io.github.wulkanowy.sdk.scrapper.register.RegisterStudent as ScrapperRegisterStudent import io.github.wulkanowy.sdk.scrapper.register.RegisterSubject as ScrapperRegisterSubject import io.github.wulkanowy.sdk.scrapper.register.RegisterSymbol as SdkRegisterSymbol import io.github.wulkanowy.sdk.scrapper.register.RegisterUnit as ScrapperRegisterUnit import io.github.wulkanowy.sdk.scrapper.register.RegisterUser as ScrapperRegisterUser -import io.github.wulkanowy.sdk.Sdk -import io.github.wulkanowy.sdk.hebe.register.StudentInfo -import io.github.wulkanowy.sdk.pojo.Student -import io.github.wulkanowy.sdk.scrapper.register.Student as ScrapperStudent internal fun ScrapperRegisterUser.mapUser(): RegisterUser = RegisterUser( email = email, login = login, - baseUrl = baseUrl, + scrapperBaseUrl = baseUrl, + hebeBaseUrl = null, + certificateKey = null, + privateKey = null, loginType = loginType, + loginMode = Sdk.Mode.SCRAPPER, symbols = symbols.map { it.mapSymbol() }, ) + internal fun SdkRegisterSymbol.mapSymbol(): RegisterSymbol = RegisterSymbol( symbol = symbol, userName = userName, @@ -66,31 +72,70 @@ internal fun ScrapperRegisterStudent.mapStudent(): RegisterStudent = RegisterStu semesters = semesters.mapSemesters(), ) -fun List.mapHebeStudents(certificateKey: String, privateKey: String): List { - return map { - Student( - email = it.pupil.loginValue, - isParent = it.login.loginRole != "Uczen", - className = it.classDisplay, - classId = -1, - studentId = it.pupil.id, - userLoginId = it.pupil.loginId, - symbol = it.topLevelPartition, - loginType = Sdk.ScrapperLoginType.STANDARD, - schoolName = it.constituentUnit.name, - schoolShortName = it.constituentUnit.short, - schoolSymbol = it.unit.symbol, - studentName = it.pupil.let { pupil -> "${pupil.firstName} ${pupil.surname}" }, - loginMode = Sdk.Mode.HEBE, - scrapperBaseUrl = "", - mobileBaseUrl = it.unit.restUrl, - certificateKey = certificateKey, - privateKey = privateKey, - // todo - userName = "", - userLogin = "", - studentSurname = "", - semesters = listOf(), - ) - } +fun List.mapHebeUser( + registerResponse: RegisterResponse, + certificateKey: String, + privateKey: String, +): RegisterUser = RegisterUser( + email = registerResponse.userName, + login = registerResponse.userLogin, + scrapperBaseUrl = null, + loginType = null, + loginMode = Sdk.Mode.HEBE, + hebeBaseUrl = registerResponse.restUrl, + certificateKey = certificateKey, + privateKey = privateKey, + symbols = this + .groupBy { it.topLevelPartition } + .mapNotNull { (symbol, students) -> + RegisterSymbol( + symbol = symbol, + error = null, + userName = students.firstOrNull()?.login?.displayName ?: return@mapNotNull null, + schools = students.mapUnit(), + ) + }, +) + +private fun List.mapUnit(): List { + return this + .groupBy { it.unit.symbol } + .mapNotNull { (schoolId, students) -> + val firstStudent = students.firstOrNull() ?: return@mapNotNull null + RegisterUnit( + userLoginId = firstStudent.login.id, + schoolId = schoolId, + schoolName = firstStudent.constituentUnit.name, + schoolShortName = firstStudent.constituentUnit.short, + parentIds = listOf(), + studentIds = listOf(), + employeeIds = listOf(), + error = null, + subjects = students.map { student -> + RegisterStudent( + studentId = student.pupil.id, + studentName = student.pupil.let { pupil -> "${pupil.firstName} ${pupil.surname}" }, + studentSecondName = student.pupil.secondName, + studentSurname = student.pupil.surname, + className = student.classDisplay, + classId = -1, // todo + isParent = student.login.loginRole != "Uczen", + semesters = student.periods.map { period -> + Semester( + diaryId = student.journal.id, + kindergartenDiaryId = 0, + diaryName = student.classDisplay, + schoolYear = period.start.timestamp.toLocalDate().year, + semesterId = period.id, + semesterNumber = period.number, + start = period.start.timestamp.toLocalDate(), + end = period.end.timestamp.toLocalDate(), + classId = -1, // todo + unitId = student.unit.id, // todo: is needed? + ) + }, + ) + }, + ) + } } diff --git a/sdk/src/main/kotlin/io/github/wulkanowy/sdk/pojo/Student.kt b/sdk/src/main/kotlin/io/github/wulkanowy/sdk/pojo/Student.kt index b455daa5..2fdc6e11 100644 --- a/sdk/src/main/kotlin/io/github/wulkanowy/sdk/pojo/Student.kt +++ b/sdk/src/main/kotlin/io/github/wulkanowy/sdk/pojo/Student.kt @@ -1,12 +1,17 @@ package io.github.wulkanowy.sdk.pojo +import io.github.wulkanowy.sdk.Sdk import io.github.wulkanowy.sdk.scrapper.Scrapper data class RegisterUser( val email: String, val login: String, // may be the same as email - val baseUrl: String, + val scrapperBaseUrl: String?, + val hebeBaseUrl: String?, + val certificateKey: String?, + val privateKey: String?, val loginType: Scrapper.LoginType?, + val loginMode: Sdk.Mode, val symbols: List, )