Reformat code
This commit is contained in:
parent
88062caa69
commit
14204770c3
12 changed files with 161 additions and 157 deletions
|
@ -1,3 +1,13 @@
|
|||
[*.{kt,kts}]
|
||||
[*]
|
||||
charset=utf-8
|
||||
end_of_line=lf
|
||||
insert_final_newline=false
|
||||
indent_style=space
|
||||
indent_size=4
|
||||
|
||||
disabled_rules=import-ordering
|
||||
[*.json]
|
||||
indent_size=2
|
||||
|
||||
[*.{kt,kts}]
|
||||
disabled_rules=import-orderin
|
||||
max_line_length=155
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<option name="RIGHT_MARGIN" value="130" />
|
||||
<JetCodeStyleSettings>
|
||||
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
||||
<value>
|
||||
|
@ -17,12 +18,16 @@
|
|||
</codeStyleSettings>
|
||||
<codeStyleSettings language="kotlin">
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
<option name="RIGHT_MARGIN" value="155" />
|
||||
<option name="LINE_COMMENT_AT_FIRST_COLUMN" value="false" />
|
||||
<option name="LINE_COMMENT_ADD_SPACE" value="true" />
|
||||
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
|
||||
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
|
||||
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="0" />
|
||||
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
|
||||
<option name="CALL_PARAMETERS_LPAREN_ON_NEXT_LINE" value="false" />
|
||||
<option name="CALL_PARAMETERS_RPAREN_ON_NEXT_LINE" value="false" />
|
||||
<option name="WRAP_ON_TYPING" value="0" />
|
||||
<indentOptions>
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
</indentOptions>
|
||||
|
|
|
@ -127,37 +127,18 @@ class Api {
|
|||
private val normalizedSymbol by resettableLazy(changeManager) { if (symbol.isBlank()) "Default" else symbol.getNormalizedSymbol() }
|
||||
|
||||
private val serviceManager by resettableLazy(changeManager) {
|
||||
ServiceManager(
|
||||
logLevel,
|
||||
loginType,
|
||||
schema,
|
||||
host,
|
||||
normalizedSymbol,
|
||||
email,
|
||||
password,
|
||||
schoolSymbol,
|
||||
studentId,
|
||||
diaryId,
|
||||
androidVersion,
|
||||
buildTag
|
||||
).apply {
|
||||
appInterceptors.forEach {
|
||||
setInterceptor(it.value.first, it.value.second, it.key)
|
||||
ServiceManager(logLevel, loginType, schema, host, normalizedSymbol, email, password, schoolSymbol, studentId, diaryId, androidVersion, buildTag)
|
||||
.apply {
|
||||
appInterceptors.forEach {
|
||||
setInterceptor(it.value.first, it.value.second, it.key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val register by resettableLazy(changeManager) {
|
||||
RegisterRepository(
|
||||
normalizedSymbol, email, password, useNewStudent,
|
||||
LoginHelper(
|
||||
loginType,
|
||||
schema,
|
||||
host,
|
||||
normalizedSymbol,
|
||||
serviceManager.getCookieManager(),
|
||||
serviceManager.getLoginService()
|
||||
),
|
||||
LoginHelper(loginType, schema, host, normalizedSymbol, serviceManager.getCookieManager(), serviceManager.getLoginService()),
|
||||
serviceManager.getRegisterService(),
|
||||
serviceManager.getSnpService(withLogin = false, interceptor = false),
|
||||
serviceManager.getStudentService(withLogin = false, interceptor = false),
|
||||
|
@ -167,12 +148,7 @@ class Api {
|
|||
|
||||
private val snpStart by resettableLazy(changeManager) {
|
||||
if (0 == studentId) throw ApiException("Student id is not set")
|
||||
StudentAndParentStartRepository(
|
||||
normalizedSymbol,
|
||||
schoolSymbol,
|
||||
studentId,
|
||||
serviceManager.getSnpService(withLogin = true, interceptor = false)
|
||||
)
|
||||
StudentAndParentStartRepository(normalizedSymbol, schoolSymbol, studentId, serviceManager.getSnpService(withLogin = true, interceptor = false))
|
||||
}
|
||||
|
||||
private val studentStart by resettableLazy(changeManager) {
|
||||
|
|
|
@ -19,8 +19,8 @@ import io.reactivex.Single
|
|||
import org.threeten.bp.LocalDate
|
||||
import org.threeten.bp.Month
|
||||
|
||||
fun Single<AttendanceResponse?>.mapAttendanceList(startDate: LocalDate, endDate: LocalDate?, getTimes: () -> Single<List<Time>>): Single<List<Attendance>> {
|
||||
val end = endDate ?: startDate.plusDays(4)
|
||||
fun Single<AttendanceResponse?>.mapAttendanceList(start: LocalDate, end: LocalDate?, getTimes: () -> Single<List<Time>>): Single<List<Attendance>> {
|
||||
val endDate = end ?: start.plusDays(4)
|
||||
var excuseActive = false
|
||||
return map {
|
||||
it.run {
|
||||
|
@ -43,7 +43,7 @@ fun Single<AttendanceResponse?>.mapAttendanceList(startDate: LocalDate, endDate:
|
|||
}
|
||||
}
|
||||
}.filter {
|
||||
it.date.toLocalDate() >= startDate && it.date.toLocalDate() <= end
|
||||
it.date.toLocalDate() >= start && it.date.toLocalDate() <= endDate
|
||||
}.toList().map { list -> list.sortedWith(compareBy({ it.date }, { it.number })) }
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package io.github.wulkanowy.api.grades
|
||||
|
||||
import io.github.wulkanowy.api.getGradeShortValue
|
||||
import kotlin.String
|
||||
import java.util.Locale
|
||||
|
||||
fun GradesResponse.mapGradesList(): List<Grade> {
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
package io.github.wulkanowy.api.interceptor
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.api.Api.LoginType
|
||||
import io.github.wulkanowy.api.Api.LoginType.ADFS
|
||||
import io.github.wulkanowy.api.Api.LoginType.ADFSCards
|
||||
import io.github.wulkanowy.api.Api.LoginType.ADFSLight
|
||||
import io.github.wulkanowy.api.Api.LoginType.ADFSLightScoped
|
||||
import io.github.wulkanowy.api.Api.LoginType.STANDARD
|
||||
import io.github.wulkanowy.api.login.NotLoggedInException
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
import org.jsoup.Jsoup
|
||||
import org.jsoup.select.Elements
|
||||
|
||||
class NotLoggedInErrorInterceptor(private val loginType: Api.LoginType) : Interceptor {
|
||||
class NotLoggedInErrorInterceptor(private val loginType: LoginType) : Interceptor {
|
||||
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val response = chain.proceed(chain.request())
|
||||
|
@ -20,12 +25,13 @@ class NotLoggedInErrorInterceptor(private val loginType: Api.LoginType) : Interc
|
|||
}
|
||||
|
||||
if (when (loginType) {
|
||||
Api.LoginType.STANDARD -> doc.select(".loginButton, .LogOnBoard input[type=submit]")
|
||||
Api.LoginType.ADFS -> doc.select("form[name=form1] #SubmitButton")
|
||||
Api.LoginType.ADFSLight, Api.LoginType.ADFSLightScoped -> doc.select("form #SubmitButton")
|
||||
Api.LoginType.ADFSCards -> doc.select("#PassiveSignInButton")
|
||||
else -> Elements()
|
||||
}.isNotEmpty()) {
|
||||
STANDARD -> doc.select(".loginButton, .LogOnBoard input[type=submit]")
|
||||
ADFS -> doc.select("form[name=form1] #SubmitButton")
|
||||
ADFSLight, ADFSLightScoped -> doc.select("form #SubmitButton")
|
||||
ADFSCards -> doc.select("#PassiveSignInButton")
|
||||
else -> Elements()
|
||||
}.isNotEmpty()
|
||||
) {
|
||||
throw NotLoggedInException("User not logged in")
|
||||
}
|
||||
|
||||
|
|
|
@ -16,12 +16,12 @@ class UserAgentInterceptor(
|
|||
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
return chain.proceed(chain.request().newBuilder()
|
||||
.addHeader("User-Agent",
|
||||
"Mozilla/5.0 (Linux; $androidVersion; $buildTag) " +
|
||||
"AppleWebKit/$webKitRev (KHTML, like Gecko) " +
|
||||
"Chrome/$chromeRev Mobile " +
|
||||
"Safari/$webKitRev")
|
||||
.build()
|
||||
.addHeader("User-Agent",
|
||||
"Mozilla/5.0 (Linux; $androidVersion; $buildTag) " +
|
||||
"AppleWebKit/$webKitRev (KHTML, like Gecko) " +
|
||||
"Chrome/$chromeRev Mobile " +
|
||||
"Safari/$webKitRev")
|
||||
.build()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
package io.github.wulkanowy.api.login
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.api.Api.LoginType.ADFS
|
||||
import io.github.wulkanowy.api.Api.LoginType.ADFSCards
|
||||
import io.github.wulkanowy.api.Api.LoginType.ADFSLight
|
||||
import io.github.wulkanowy.api.Api.LoginType.ADFSLightScoped
|
||||
import io.github.wulkanowy.api.Api.LoginType.AUTO
|
||||
import io.github.wulkanowy.api.Api.LoginType.STANDARD
|
||||
import io.github.wulkanowy.api.ApiException
|
||||
import io.github.wulkanowy.api.interceptor.VulcanException
|
||||
import io.github.wulkanowy.api.register.SendCertificateResponse
|
||||
|
@ -47,22 +53,22 @@ class LoginHelper(
|
|||
fun sendCredentials(email: String, password: String): Single<CertificateResponse> {
|
||||
email.substringBefore("||").let {
|
||||
return when (loginType) {
|
||||
Api.LoginType.AUTO -> throw ApiException("You must first specify LoginType before logging in")
|
||||
Api.LoginType.STANDARD -> sendStandard(it, password)
|
||||
Api.LoginType.ADFS -> sendAdfs(it, password)
|
||||
Api.LoginType.ADFSLight -> sendADFSLightGeneric(it, password, Api.LoginType.ADFSLight)
|
||||
Api.LoginType.ADFSLightScoped -> sendADFSLightGeneric(it, password, Api.LoginType.ADFSLightScoped)
|
||||
Api.LoginType.ADFSCards -> sendADFSCards(it, password)
|
||||
AUTO -> throw ApiException("You must first specify Api.loginType before logging in")
|
||||
STANDARD -> sendStandard(it, password)
|
||||
ADFS -> sendADFS(it, password)
|
||||
ADFSLight -> sendADFSLightGeneric(it, password, ADFSLight)
|
||||
ADFSLightScoped -> sendADFSLightGeneric(it, password, ADFSLightScoped)
|
||||
ADFSCards -> sendADFSCards(it, password)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun sendCertificate(certificate: CertificateResponse, email: String, url: String = certificate.action): Single<SendCertificateResponse> {
|
||||
fun sendCertificate(cert: CertificateResponse, email: String, url: String = cert.action): Single<SendCertificateResponse> {
|
||||
cookies.cookieStore.removeAll()
|
||||
return api.sendCertificate(url, mapOf(
|
||||
"wa" to certificate.wa,
|
||||
"wresult" to certificate.wresult,
|
||||
"wctx" to certificate.wctx
|
||||
"wa" to cert.wa,
|
||||
"wresult" to cert.wresult,
|
||||
"wctx" to cert.wctx
|
||||
)).flatMap {
|
||||
if (email.contains("||")) api.switchLogin("$url?rebuild=${email.substringAfter("||", "")}")
|
||||
else Single.just(it)
|
||||
|
@ -71,8 +77,8 @@ class LoginHelper(
|
|||
|
||||
private fun sendStandard(email: String, password: String): Single<CertificateResponse> {
|
||||
return api.sendCredentials(firstStepReturnUrl, mapOf(
|
||||
"LoginName" to email,
|
||||
"Password" to password
|
||||
"LoginName" to email,
|
||||
"Password" to password
|
||||
)).map { certificateAdapter.fromHtml(it) }
|
||||
}
|
||||
|
||||
|
@ -95,74 +101,74 @@ class LoginHelper(
|
|||
}.map { certificateAdapter.fromHtml(it) }
|
||||
}
|
||||
|
||||
private fun sendAdfs(email: String, password: String): Single<CertificateResponse> {
|
||||
return api.getForm(getADFSUrl(Api.LoginType.ADFS)).flatMap {
|
||||
private fun sendADFS(email: String, password: String): Single<CertificateResponse> {
|
||||
return api.getForm(getADFSUrl(ADFS)).flatMap {
|
||||
if (it.formAction.isBlank()) throw VulcanException("Invalid ADFS login page: '${it.title}'. Try again")
|
||||
api.sendADFSForm("$schema://adfs.$host/${it.formAction.removePrefix("/")}", mapOf(
|
||||
"__db" to it.db,
|
||||
"__VIEWSTATE" to it.viewstate,
|
||||
"__VIEWSTATEGENERATOR" to it.viewStateGenerator,
|
||||
"__EVENTVALIDATION" to it.eventValidation,
|
||||
"UsernameTextBox" to email,
|
||||
"PasswordTextBox" to password,
|
||||
"SubmitButton.x" to "0",
|
||||
"SubmitButton.y" to "0"
|
||||
"__db" to it.db,
|
||||
"__VIEWSTATE" to it.viewstate,
|
||||
"__VIEWSTATEGENERATOR" to it.viewStateGenerator,
|
||||
"__EVENTVALIDATION" to it.eventValidation,
|
||||
"UsernameTextBox" to email,
|
||||
"PasswordTextBox" to password,
|
||||
"SubmitButton.x" to "0",
|
||||
"SubmitButton.y" to "0"
|
||||
))
|
||||
}.map { certificateAdapter.fromHtml(it) }.flatMap {
|
||||
api.sendADFSForm(it.action, mapOf(
|
||||
"wa" to it.wa,
|
||||
"wresult" to it.wresult,
|
||||
"wctx" to it.wctx
|
||||
"wa" to it.wa,
|
||||
"wresult" to it.wresult,
|
||||
"wctx" to it.wctx
|
||||
))
|
||||
}.map { certificateAdapter.fromHtml(it) }
|
||||
}
|
||||
|
||||
private fun sendADFSCards(email: String, password: String): Single<CertificateResponse> {
|
||||
return api.getForm(getADFSUrl(Api.LoginType.ADFSCards)).flatMap {
|
||||
return api.getForm(getADFSUrl(ADFSCards)).flatMap {
|
||||
api.sendADFSFormStandardChoice("$schema://adfs.$host/${it.formAction.removePrefix("/")}", mapOf(
|
||||
"__db" to it.db,
|
||||
"__VIEWSTATE" to it.viewstate,
|
||||
"__VIEWSTATEGENERATOR" to it.viewStateGenerator,
|
||||
"__EVENTVALIDATION" to it.eventValidation,
|
||||
"PassiveSignInButton.x" to "0",
|
||||
"PassiveSignInButton.y" to "0"
|
||||
"__db" to it.db,
|
||||
"__VIEWSTATE" to it.viewstate,
|
||||
"__VIEWSTATEGENERATOR" to it.viewStateGenerator,
|
||||
"__EVENTVALIDATION" to it.eventValidation,
|
||||
"PassiveSignInButton.x" to "0",
|
||||
"PassiveSignInButton.y" to "0"
|
||||
))
|
||||
}.flatMap {
|
||||
api.sendADFSForm("$schema://adfs.$host/${it.formAction.removePrefix("/")}", mapOf(
|
||||
"__db" to it.db,
|
||||
"__VIEWSTATE" to it.viewstate,
|
||||
"__VIEWSTATEGENERATOR" to it.viewStateGenerator,
|
||||
"__EVENTVALIDATION" to it.eventValidation,
|
||||
"SubmitButton.x" to "0",
|
||||
"SubmitButton.y" to "0",
|
||||
"UsernameTextBox" to email,
|
||||
"PasswordTextBox" to password
|
||||
"__db" to it.db,
|
||||
"__VIEWSTATE" to it.viewstate,
|
||||
"__VIEWSTATEGENERATOR" to it.viewStateGenerator,
|
||||
"__EVENTVALIDATION" to it.eventValidation,
|
||||
"SubmitButton.x" to "0",
|
||||
"SubmitButton.y" to "0",
|
||||
"UsernameTextBox" to email,
|
||||
"PasswordTextBox" to password
|
||||
))
|
||||
}.map { certificateAdapter.fromHtml(it) }.flatMap {
|
||||
api.sendADFSForm(it.action, mapOf(
|
||||
"wa" to it.wa,
|
||||
"wresult" to it.wresult,
|
||||
"wctx" to it.wctx
|
||||
"wa" to it.wa,
|
||||
"wresult" to it.wresult,
|
||||
"wctx" to it.wctx
|
||||
))
|
||||
}.map { certificateAdapter.fromHtml(it) }
|
||||
}
|
||||
|
||||
private fun getADFSUrl(type: Api.LoginType): String {
|
||||
val id = when (type) {
|
||||
Api.LoginType.ADFS -> "adfs"
|
||||
Api.LoginType.ADFSCards -> "eSzkola"
|
||||
Api.LoginType.ADFSLightScoped -> "ADFSLight"
|
||||
ADFS -> "adfs"
|
||||
ADFSCards -> "eSzkola"
|
||||
ADFSLightScoped -> "ADFSLight"
|
||||
else -> "ADFS"
|
||||
}
|
||||
|
||||
val query = "?wa=wsignin1.0" +
|
||||
"&wtrealm=" + encode("http${if (Api.LoginType.ADFSCards != type) "s" else ""}://cufs.$host/$symbol/Account/LogOn") +
|
||||
"&wctx=" + encode("rm=0&id=$id&ru=" + encode(firstStepReturnUrl)) +
|
||||
"&wct=" + encode(now(ZoneId.of("UTC")).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + "Z")
|
||||
"&wtrealm=" + encode("http${if (ADFSCards != type) "s" else ""}://cufs.$host/$symbol/Account/LogOn") +
|
||||
"&wctx=" + encode("rm=0&id=$id&ru=" + encode(firstStepReturnUrl)) +
|
||||
"&wct=" + encode(now(ZoneId.of("UTC")).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + "Z")
|
||||
|
||||
return when (type) {
|
||||
Api.LoginType.ADFSLight -> "$schema://adfslight.$host/LoginPage.aspx?ReturnUrl=" + encode("/$query")
|
||||
Api.LoginType.ADFSLightScoped -> "$schema://adfslight.$host/$symbol/LoginPage.aspx?ReturnUrl=" + encode("/$symbol/default.aspx$query")
|
||||
ADFSLight -> "$schema://adfslight.$host/LoginPage.aspx?ReturnUrl=" + encode("/$query")
|
||||
ADFSLightScoped -> "$schema://adfslight.$host/$symbol/LoginPage.aspx?ReturnUrl=" + encode("/$symbol/default.aspx$query")
|
||||
else -> "$schema://adfs.$host/adfs/ls/$query"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,11 +14,11 @@ import io.github.wulkanowy.api.homework.Homework
|
|||
import io.github.wulkanowy.api.mobile.Device
|
||||
import io.github.wulkanowy.api.mobile.TokenResponse
|
||||
import io.github.wulkanowy.api.notes.Note
|
||||
import io.github.wulkanowy.api.timetable.CompletedLesson
|
||||
import io.github.wulkanowy.api.school.School
|
||||
import io.github.wulkanowy.api.school.Teacher
|
||||
import io.github.wulkanowy.api.service.StudentAndParentService
|
||||
import io.github.wulkanowy.api.student.StudentInfo
|
||||
import io.github.wulkanowy.api.timetable.CompletedLesson
|
||||
import io.github.wulkanowy.api.timetable.Timetable
|
||||
import io.github.wulkanowy.api.timetable.TimetableParser
|
||||
import io.github.wulkanowy.api.toDate
|
||||
|
@ -61,13 +61,13 @@ class StudentAndParentRepository(private val api: StudentAndParentService) {
|
|||
res.months.mapIndexedNotNull { i, month ->
|
||||
if (res.summaryRows.all { it.value[i].isBlank() }) return@mapIndexedNotNull null
|
||||
AttendanceSummary(romanToMonthEnum(month),
|
||||
res.summaryRows[0].value[i].toIntOrNull() ?: 0,
|
||||
res.summaryRows[1].value[i].toIntOrNull() ?: 0,
|
||||
res.summaryRows[2].value[i].toIntOrNull() ?: 0,
|
||||
res.summaryRows[3].value[i].toIntOrNull() ?: 0,
|
||||
res.summaryRows[4].value[i].toIntOrNull() ?: 0,
|
||||
res.summaryRows[5].value[i].toIntOrNull() ?: 0,
|
||||
res.summaryRows[6].value[i].toIntOrNull() ?: 0
|
||||
res.summaryRows[0].value[i].toIntOrNull() ?: 0,
|
||||
res.summaryRows[1].value[i].toIntOrNull() ?: 0,
|
||||
res.summaryRows[2].value[i].toIntOrNull() ?: 0,
|
||||
res.summaryRows[3].value[i].toIntOrNull() ?: 0,
|
||||
res.summaryRows[4].value[i].toIntOrNull() ?: 0,
|
||||
res.summaryRows[5].value[i].toIntOrNull() ?: 0,
|
||||
res.summaryRows[6].value[i].toIntOrNull() ?: 0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,12 @@ class StudentAndParentStartRepository(
|
|||
api.getDiaryInfo(diary.id, "/$symbol/$schoolSymbol/Oceny.mvc/Wszystkie").map { res ->
|
||||
if (!res.title.endsWith("Oceny")) throw VulcanException("Unknow page with title: ${res.title}")
|
||||
res.semesters.map {
|
||||
Semester(diary.id, diary.name, diary.name.substringAfter(" ").toInt(), it.semesterId, it.semesterNumber, "selected" == it.current && "selected" == diary.current)
|
||||
Semester(diary.id,
|
||||
diary.name,
|
||||
diary.name.substringAfter(" ").toInt(),
|
||||
it.semesterId,
|
||||
it.semesterNumber,
|
||||
"selected" == it.current && "selected" == diary.current)
|
||||
}
|
||||
}
|
||||
}.toList().map { it.flatten() }
|
||||
|
|
|
@ -26,7 +26,7 @@ import retrofit2.converter.scalars.ScalarsConverterFactory
|
|||
import retrofit2.create
|
||||
import java.net.CookieManager
|
||||
import java.net.CookiePolicy
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.TimeUnit.SECONDS
|
||||
|
||||
class ServiceManager(
|
||||
logLevel: HttpLoggingInterceptor.Level,
|
||||
|
@ -58,10 +58,10 @@ class ServiceManager(
|
|||
}
|
||||
|
||||
private val interceptors: MutableList<Pair<Interceptor, Boolean>> = mutableListOf(
|
||||
Pair(HttpLoggingInterceptor().setLevel(logLevel), true),
|
||||
Pair(ErrorInterceptor(), false),
|
||||
Pair(NotLoggedInErrorInterceptor(loginType), false),
|
||||
Pair(UserAgentInterceptor(androidVersion, buildTag), false)
|
||||
Pair(HttpLoggingInterceptor().setLevel(logLevel), true),
|
||||
Pair(ErrorInterceptor(), false),
|
||||
Pair(NotLoggedInErrorInterceptor(loginType), false),
|
||||
Pair(UserAgentInterceptor(androidVersion, buildTag), false)
|
||||
)
|
||||
|
||||
fun setInterceptor(interceptor: Interceptor, network: Boolean = false, index: Int = -1) {
|
||||
|
@ -77,11 +77,14 @@ class ServiceManager(
|
|||
if (email.isBlank() && password.isBlank()) throw ApiException("Email and password are not set")
|
||||
if (email.isBlank()) throw ApiException("Email is not set")
|
||||
if (password.isBlank()) throw ApiException("Password is not set")
|
||||
return getRetrofit(getClientBuilder(loginInterceptor = false), urlGenerator.generate(UrlGenerator.Site.LOGIN), false).create()
|
||||
return getRetrofit(getClientBuilder(loginIntercept = false), urlGenerator.generate(UrlGenerator.Site.LOGIN), false).create()
|
||||
}
|
||||
|
||||
fun getRegisterService(): RegisterService {
|
||||
return getRetrofit(getClientBuilder(errorInterceptor = false, loginInterceptor = false, separateJar = true), urlGenerator.generate(UrlGenerator.Site.LOGIN), false).create()
|
||||
return getRetrofit(getClientBuilder(errIntercept = false, loginIntercept = false, separateJar = true),
|
||||
urlGenerator.generate(UrlGenerator.Site.LOGIN),
|
||||
false
|
||||
).create()
|
||||
}
|
||||
|
||||
fun getStudentService(withLogin: Boolean = true, interceptor: Boolean = true): StudentService {
|
||||
|
@ -99,7 +102,7 @@ class ServiceManager(
|
|||
fun getSnpService(withLogin: Boolean = true, interceptor: Boolean = true): StudentAndParentService {
|
||||
if (withLogin && schoolSymbol.isBlank()) throw ApiException("School id is not set")
|
||||
|
||||
val client = getClientBuilder(loginInterceptor = withLogin)
|
||||
val client = getClientBuilder(loginIntercept = withLogin)
|
||||
if (interceptor) {
|
||||
if (0 == diaryId || 0 == studentId) throw ApiException("Student or/and diaryId id are not set")
|
||||
client.addInterceptor(StudentAndParentInterceptor(cookies, schema, host, diaryId, studentId))
|
||||
|
@ -109,59 +112,53 @@ class ServiceManager(
|
|||
}
|
||||
|
||||
fun getMessagesService(): MessagesService {
|
||||
return getRetrofit(getClientBuilder(), urlGenerator.generate(UrlGenerator.Site.MESSAGES),
|
||||
login = true,
|
||||
gson = true
|
||||
).create()
|
||||
return getRetrofit(getClientBuilder(), urlGenerator.generate(UrlGenerator.Site.MESSAGES), login = true, gson = true).create()
|
||||
}
|
||||
|
||||
fun getHomepageService(): HomepageService {
|
||||
return getRetrofit(getClientBuilder(), urlGenerator.generate(UrlGenerator.Site.HOME),
|
||||
login = true,
|
||||
gson = true
|
||||
).create()
|
||||
return getRetrofit(getClientBuilder(), urlGenerator.generate(UrlGenerator.Site.HOME), login = true, gson = true).create()
|
||||
}
|
||||
|
||||
private fun getRetrofit(client: OkHttpClient.Builder, baseUrl: String, login: Boolean = true, gson: Boolean = false): Retrofit {
|
||||
return Retrofit.Builder()
|
||||
.baseUrl(baseUrl)
|
||||
.client(client.build())
|
||||
.addConverterFactory(ScalarsConverterFactory.create())
|
||||
.addConverterFactory(if (gson) GsonConverterFactory.create(GsonBuilder()
|
||||
.setDateFormat("yyyy-MM-dd HH:mm:ss")
|
||||
.serializeNulls()
|
||||
.registerTypeAdapter(GradeDate::class.java, DateDeserializer(GradeDate::class.java))
|
||||
.create()) else JspoonConverterFactory.create())
|
||||
.addCallAdapterFactory(if (!login) RxJava2CallAdapterFactory.create() else
|
||||
RxJava2ReauthCallAdapterFactory.create(
|
||||
getLoginHelper(),
|
||||
{ it is NotLoggedInException }
|
||||
)
|
||||
).build()
|
||||
.baseUrl(baseUrl)
|
||||
.client(client.build())
|
||||
.addConverterFactory(ScalarsConverterFactory.create())
|
||||
.addConverterFactory(if (gson) GsonConverterFactory.create(GsonBuilder()
|
||||
.setDateFormat("yyyy-MM-dd HH:mm:ss")
|
||||
.serializeNulls()
|
||||
.registerTypeAdapter(GradeDate::class.java, DateDeserializer(GradeDate::class.java))
|
||||
.create()) else JspoonConverterFactory.create())
|
||||
.addCallAdapterFactory(if (!login) RxJava2CallAdapterFactory.create() else
|
||||
RxJava2ReauthCallAdapterFactory.create(
|
||||
getLoginHelper(),
|
||||
{ it is NotLoggedInException }
|
||||
)
|
||||
).build()
|
||||
}
|
||||
|
||||
private fun getClientBuilder(errorInterceptor: Boolean = true, loginInterceptor: Boolean = true, separateJar: Boolean = false): OkHttpClient.Builder {
|
||||
private fun getClientBuilder(errIntercept: Boolean = true, loginIntercept: Boolean = true, separateJar: Boolean = false): OkHttpClient.Builder {
|
||||
return OkHttpClient().newBuilder()
|
||||
.callTimeout(25, TimeUnit.SECONDS)
|
||||
.cookieJar(if (!separateJar) JavaNetCookieJar(cookies) else JavaNetCookieJar(CookieManager()))
|
||||
.apply {
|
||||
interceptors.forEach {
|
||||
if (it.first is ErrorInterceptor || it.first is NotLoggedInErrorInterceptor) {
|
||||
if (it.first is NotLoggedInErrorInterceptor && loginInterceptor) addInterceptor(it.first)
|
||||
if (it.first is ErrorInterceptor && errorInterceptor) addInterceptor(it.first)
|
||||
} else {
|
||||
if (it.second) addNetworkInterceptor(it.first)
|
||||
else addInterceptor(it.first)
|
||||
}
|
||||
.callTimeout(25, SECONDS)
|
||||
.cookieJar(if (!separateJar) JavaNetCookieJar(cookies) else JavaNetCookieJar(CookieManager()))
|
||||
.apply {
|
||||
interceptors.forEach {
|
||||
if (it.first is ErrorInterceptor || it.first is NotLoggedInErrorInterceptor) {
|
||||
if (it.first is NotLoggedInErrorInterceptor && loginIntercept) addInterceptor(it.first)
|
||||
if (it.first is ErrorInterceptor && errIntercept) addInterceptor(it.first)
|
||||
} else {
|
||||
if (it.second) addNetworkInterceptor(it.first)
|
||||
else addInterceptor(it.first)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getLoginHelper(): Flowable<SendCertificateResponse> {
|
||||
return loginHelper
|
||||
.login(email, password)
|
||||
.toFlowable()
|
||||
.share()
|
||||
.login(email, password)
|
||||
.toFlowable()
|
||||
.share()
|
||||
}
|
||||
|
||||
class UrlGenerator(private val schema: String, private val host: String, var symbol: String, var schoolId: String) {
|
||||
|
|
|
@ -9,10 +9,10 @@ import io.github.wulkanowy.api.homework.HomeworkResponse
|
|||
import io.github.wulkanowy.api.mobile.RegisteredDevicesResponse
|
||||
import io.github.wulkanowy.api.mobile.TokenResponse
|
||||
import io.github.wulkanowy.api.notes.NotesResponse
|
||||
import io.github.wulkanowy.api.timetable.RealizedResponse
|
||||
import io.github.wulkanowy.api.register.StudentAndParentResponse
|
||||
import io.github.wulkanowy.api.school.SchoolAndTeachersResponse
|
||||
import io.github.wulkanowy.api.student.StudentInfo
|
||||
import io.github.wulkanowy.api.timetable.RealizedResponse
|
||||
import io.github.wulkanowy.api.timetable.TimetableResponse
|
||||
import io.reactivex.Single
|
||||
import retrofit2.http.Field
|
||||
|
|
Loading…
Reference in a new issue