Expose alternative cookie manager used for registration

This commit is contained in:
Mikołaj Pich 2024-01-12 11:54:00 +01:00
parent 6c7c919978
commit 212f0e33d5
6 changed files with 14 additions and 1 deletions

View file

@ -6,6 +6,7 @@ public final class io/github/wulkanowy/sdk/scrapper/Scrapper {
public final fun deleteMessages (Ljava/util/List;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun excuseForAbsence (Ljava/util/List;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun excuseForAbsence$default (Lio/github/wulkanowy/sdk/scrapper/Scrapper;Ljava/util/List;Ljava/lang/String;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public final fun getAlternativeCookieManager ()Ljava/net/CookieManager;
public final fun getAndroidVersion ()Ljava/lang/String;
public final fun getAttendance (Ljava/time/LocalDate;Ljava/time/LocalDate;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun getAttendance$default (Lio/github/wulkanowy/sdk/scrapper/Scrapper;Ljava/time/LocalDate;Ljava/time/LocalDate;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;

View file

@ -68,6 +68,10 @@ class Scrapper {
setCookiePolicy(CookiePolicy.ACCEPT_ALL)
}
val alternativeCookieManager = CookieManager().apply {
setCookiePolicy(CookiePolicy.ACCEPT_ALL)
}
var logLevel: HttpLoggingInterceptor.Level = HttpLoggingInterceptor.Level.BASIC
set(value) {
if (field != value) changeManager.reset()
@ -214,6 +218,7 @@ class Scrapper {
ServiceManager(
okHttpClientBuilderFactory = okHttpFactory,
cookies = cookieManager,
alternativeCookies = alternativeCookieManager,
logLevel = logLevel,
loginType = loginType,
schema = schema,

View file

@ -36,6 +36,7 @@ import javax.net.ssl.X509TrustManager
internal class ServiceManager(
private val okHttpClientBuilderFactory: OkHttpClientBuilderFactory,
private val cookies: CookieManager,
private val alternativeCookies: CookieManager,
logLevel: HttpLoggingInterceptor.Level,
private val loginType: Scrapper.LoginType,
private val schema: String,
@ -233,7 +234,7 @@ internal class ServiceManager(
-> sslSocketFactory(TLSSocketFactory(), trustManager)
}
}
.cookieJar(if (!separateJar) JavaNetCookieJar(cookies) else JavaNetCookieJar(CookieManager()))
.cookieJar(if (!separateJar) JavaNetCookieJar(cookies) else JavaNetCookieJar(alternativeCookies))
.apply {
interceptors.forEach {
if (it.first is ErrorInterceptor || it.first is AutoLoginInterceptor) {

View file

@ -24,6 +24,7 @@ class ServiceManagerTest : BaseLocalTest() {
val manager = ServiceManager(
okHttpClientBuilderFactory = OkHttpClientBuilderFactory(),
cookies = CookieManager(),
alternativeCookies = CookieManager(),
logLevel = HttpLoggingInterceptor.Level.NONE,
loginType = Scrapper.LoginType.STANDARD,
schema = "http",
@ -58,6 +59,7 @@ class ServiceManagerTest : BaseLocalTest() {
val manager = ServiceManager(
okHttpClientBuilderFactory = OkHttpClientBuilderFactory(),
cookies = CookieManager(),
alternativeCookies = CookieManager(),
logLevel = HttpLoggingInterceptor.Level.NONE,
loginType = Scrapper.LoginType.STANDARD,
schema = "http",
@ -130,6 +132,7 @@ class ServiceManagerTest : BaseLocalTest() {
val manager = ServiceManager(
okHttpClientBuilderFactory = OkHttpClientBuilderFactory(),
cookies = CookieManager(),
alternativeCookies = CookieManager(),
logLevel = HttpLoggingInterceptor.Level.NONE,
loginType = Scrapper.LoginType.STANDARD,
schema = "http",

View file

@ -7,6 +7,7 @@ public final class io/github/wulkanowy/sdk/Sdk {
public static synthetic fun deleteMessages$default (Lio/github/wulkanowy/sdk/Sdk;Ljava/util/List;ZLkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public final fun excuseForAbsence (Ljava/util/List;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun excuseForAbsence$default (Lio/github/wulkanowy/sdk/Sdk;Ljava/util/List;Ljava/lang/String;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public final fun getAlternativeCookieManager ()Ljava/net/CookieManager;
public final fun getAndroidVersion ()Ljava/lang/String;
public final fun getAttendance (Ljava/time/LocalDate;Ljava/time/LocalDate;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun getAttendanceSummary (Ljava/lang/Integer;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;

View file

@ -100,6 +100,8 @@ class Sdk {
val cookieManager: CookieManager = scrapper.cookieManager
val alternativeCookieManager: CookieManager = scrapper.alternativeCookieManager
var mode = Mode.SCRAPPER
var mobileBaseUrl = ""