All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.wulkanowy.sdk.scrapper.interceptor.StudentCookieInterceptor.kt Maven / Gradle / Ivy

Go to download

Unified way of retrieving data from the UONET+ register through mobile api and scraping api

There is a newer version: 2.7.0
Show newest version
package io.github.wulkanowy.sdk.scrapper.interceptor

import io.github.wulkanowy.sdk.scrapper.CookieJarCabinet
import okhttp3.Interceptor
import okhttp3.Response
import java.net.HttpCookie
import java.net.URI

internal class StudentCookieInterceptor(
    private val cookieJarCabinet: CookieJarCabinet,
    private val schema: String,
    private val host: String,
    private val domainSuffix: String,
    private val diaryId: Int,
    private val kindergartenDiaryId: Int,
    private val studentId: Int,
    private val schoolYear: Int,
) : Interceptor {

    override fun intercept(chain: Interceptor.Chain): Response {
        arrayOf(
            "idBiezacyDziennik" to diaryId,
            "idBiezacyUczen" to studentId,
            "idBiezacyDziennikPrzedszkole" to kindergartenDiaryId,
            "biezacyRokSzkolny" to schoolYear,
        ).forEach { (name, value) ->
            HttpCookie(name, value.toString()).let {
                it.path = "/"
                it.domain = "uonetplus-uczen$domainSuffix.$host"
                cookieJarCabinet.addStudentCookie(URI("$schema://${it.domain}"), it)
            }
        }

        return chain.proceed(chain.request().newBuilder().build())
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy