From f50690a95acaf90d2ad2cc325e2e71e12dad1260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Sat, 11 May 2024 20:54:17 +0200 Subject: [PATCH] Make setters for endpoints mapping public --- sdk-scrapper/api/sdk-scrapper.api | 4 ++++ .../{ApiEndpoints2.kt => ApiEndpoints.kt} | 0 .../github/wulkanowy/sdk/scrapper/Scrapper.kt | 17 +++++++++++++++++ .../io/github/wulkanowy/sdk/scrapper/Utils.kt | 8 +++++--- sdk/api/sdk.api | 4 ++++ .../main/kotlin/io/github/wulkanowy/sdk/Sdk.kt | 12 ++++++++++++ 6 files changed, 42 insertions(+), 3 deletions(-) rename sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/{ApiEndpoints2.kt => ApiEndpoints.kt} (100%) diff --git a/sdk-scrapper/api/sdk-scrapper.api b/sdk-scrapper/api/sdk-scrapper.api index a7549f5b..d7d479fe 100644 --- a/sdk-scrapper/api/sdk-scrapper.api +++ b/sdk-scrapper/api/sdk-scrapper.api @@ -25,6 +25,7 @@ public final class io/github/wulkanowy/sdk/scrapper/Scrapper { public final fun getDomainSuffix ()Ljava/lang/String; public final fun getEmail ()Ljava/lang/String; public final fun getEmptyCookieJarInterceptor ()Z + public final fun getEndpointsMapping ()Ljava/util/Map; public final fun getExams (Ljava/time/LocalDate;Ljava/time/LocalDate;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun getExams$default (Lio/github/wulkanowy/sdk/scrapper/Scrapper;Ljava/time/LocalDate;Ljava/time/LocalDate;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public final fun getFreeDays (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -81,6 +82,7 @@ public final class io/github/wulkanowy/sdk/scrapper/Scrapper { public final fun getUserAgent ()Ljava/lang/String; public final fun getUserAgentTemplate ()Ljava/lang/String; public final fun getUserSubjects (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun getVTokenMapping ()Ljava/util/Map; public final fun isEduOne ()Z public final fun isSymbolNotExist (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun restoreMessages (Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -96,6 +98,7 @@ public final class io/github/wulkanowy/sdk/scrapper/Scrapper { public final fun setEduOne (Z)V public final fun setEmail (Ljava/lang/String;)V public final fun setEmptyCookieJarInterceptor (Z)V + public final fun setEndpointsMapping (Ljava/util/Map;)V public final fun setHost (Ljava/lang/String;)V public final fun setKindergartenDiaryId (I)V public final fun setLogLevel (Lokhttp3/logging/HttpLoggingInterceptor$Level;)V @@ -108,6 +111,7 @@ public final class io/github/wulkanowy/sdk/scrapper/Scrapper { public final fun setSymbol (Ljava/lang/String;)V public final fun setUnitId (I)V public final fun setUserAgentTemplate (Ljava/lang/String;)V + public final fun setVTokenMapping (Ljava/util/Map;)V public final fun unregisterDevice (ILkotlin/coroutines/Continuation;)Ljava/lang/Object; } diff --git a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/ApiEndpoints2.kt b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/ApiEndpoints.kt similarity index 100% rename from sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/ApiEndpoints2.kt rename to sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/ApiEndpoints.kt 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 3bf2f35c..650f9099 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 @@ -212,6 +212,23 @@ class Scrapper { } } + var endpointsMapping: Map>> + get() = endpointsMap + set(value) { + endpointsMap = value + } + + var vTokenMapping: Map>> + get() = vTokenMap + set(value) { + vTokenMap = value + } + + internal companion object { + var endpointsMap: Map>> = ApiEndpointsMap + var vTokenMap: Map>> = ApiEndpointsVTokenMap + } + private val appInterceptors: MutableList> = mutableListOf() fun addInterceptor(interceptor: Interceptor, network: Boolean = false) { diff --git a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Utils.kt b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Utils.kt index eca19716..c34fc540 100644 --- a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Utils.kt +++ b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Utils.kt @@ -204,7 +204,7 @@ internal fun String.md5(): String { internal fun HttpUrl.mapModuleUrls(moduleHost: String, appVersion: String?): HttpUrl { val pathSegmentIndex = getPathIndexByModuleHost(moduleHost) val pathKey = pathSegments.getOrNull(pathSegmentIndex) - val mappedPath = ApiEndpointsMap[appVersion] + val mappedPath = Scrapper.endpointsMap[appVersion] ?.get(moduleHost) ?.get(pathKey?.substringBefore(".mvc")) @@ -216,7 +216,9 @@ internal fun HttpUrl.mapModuleUrls(moduleHost: String, appVersion: String?): Htt else -> mappedPath }, ).build() - } else this + } else { + this + } } internal fun getPathIndexByModuleHost(moduleHost: String): Int = when (moduleHost) { @@ -228,7 +230,7 @@ internal fun getPathIndexByModuleHost(moduleHost: String): Int = when (moduleHos internal fun Request.Builder.attachVToken(moduleHost: String, url: HttpUrl, headers: ModuleHeaders?): Request.Builder { val pathSegmentIndex = getPathIndexByModuleHost(moduleHost) val pathKey = url.pathSegments.getOrNull(pathSegmentIndex) - val mappedUuid = ApiEndpointsVTokenMap[headers?.appVersion] + val mappedUuid = Scrapper.vTokenMap[headers?.appVersion] ?.get(moduleHost) ?.get(pathKey) ?: return this diff --git a/sdk/api/sdk.api b/sdk/api/sdk.api index 6abbaaae..92a78443 100644 --- a/sdk/api/sdk.api +++ b/sdk/api/sdk.api @@ -24,6 +24,7 @@ public final class io/github/wulkanowy/sdk/Sdk { public final fun getDomainSuffix ()Ljava/lang/String; public final fun getEmail ()Ljava/lang/String; public final fun getEmptyCookieJarInterceptor ()Z + public final fun getEndpointsMapping ()Ljava/util/Map; public final fun getExams (Ljava/time/LocalDate;Ljava/time/LocalDate;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getFreeDays (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getGrades (ILkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -89,6 +90,7 @@ public final class io/github/wulkanowy/sdk/Sdk { public final fun getUserSubjectsFromScrapper (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getUserSubjectsFromScrapper (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun getUserSubjectsFromScrapper$default (Lio/github/wulkanowy/sdk/Sdk;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public final fun getVTokenMapping ()Ljava/util/Map; public final fun isEduOne ()Z public final fun isSymbolNotExist (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun restoreMessages (Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -103,6 +105,7 @@ public final class io/github/wulkanowy/sdk/Sdk { public final fun setEduOne (Z)V public final fun setEmail (Ljava/lang/String;)V public final fun setEmptyCookieJarInterceptor (Z)V + public final fun setEndpointsMapping (Ljava/util/Map;)V public final fun setKeyId (Ljava/lang/String;)V public final fun setKindergartenDiaryId (I)V public final fun setLogLevel (Lokhttp3/logging/HttpLoggingInterceptor$Level;)V @@ -119,6 +122,7 @@ public final class io/github/wulkanowy/sdk/Sdk { public final fun setSymbol (Ljava/lang/String;)V public final fun setUnitId (I)V public final fun setUserAgentTemplate (Ljava/lang/String;)V + public final fun setVTokenMapping (Ljava/util/Map;)V public final fun switchDiary (III)Lio/github/wulkanowy/sdk/Sdk; public final fun switchDiary (IIII)Lio/github/wulkanowy/sdk/Sdk; public static synthetic fun switchDiary$default (Lio/github/wulkanowy/sdk/Sdk;IIIIILjava/lang/Object;)Lio/github/wulkanowy/sdk/Sdk; 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 520a3502..75c309d0 100644 --- a/sdk/src/main/kotlin/io/github/wulkanowy/sdk/Sdk.kt +++ b/sdk/src/main/kotlin/io/github/wulkanowy/sdk/Sdk.kt @@ -235,6 +235,18 @@ class Sdk { scrapper.buildTag = value } + var endpointsMapping + get() = scrapper.endpointsMapping + set(value) { + scrapper.endpointsMapping = value + } + + var vTokenMapping + get() = scrapper.vTokenMapping + set(value) { + scrapper.vTokenMapping = value + } + var emptyCookieJarInterceptor: Boolean = false set(value) { field = value