[APIv2/Librus] Add getting student info (student number) using Synergia

This commit is contained in:
Kacper Ziubryniewicz 2019-10-23 22:53:25 +02:00
parent e2150e3018
commit ff7f015146
2 changed files with 39 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import pl.szczodrzynski.edziennik.R
import pl.szczodrzynski.edziennik.api.v2.librus.*
import pl.szczodrzynski.edziennik.api.v2.librus.data.api.*
import pl.szczodrzynski.edziennik.api.v2.librus.data.synergia.LibrusSynergiaHomework
import pl.szczodrzynski.edziennik.api.v2.librus.data.synergia.LibrusSynergiaInfo
import pl.szczodrzynski.edziennik.utils.Utils
class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) {
@ -88,6 +89,10 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) {
data.startProgress(R.string.edziennik_progress_endpoint_homework)
LibrusSynergiaHomework(data) { onSuccess() }
}
ENDPOINT_LIBRUS_SYNERGIA_INFO -> {
data.startProgress(R.string.edziennik_progress_endpoint_student_info)
LibrusSynergiaInfo(data) { onSuccess() }
}
else -> onSuccess()
}
}

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) Kacper Ziubryniewicz 2019-10-23
*/
package pl.szczodrzynski.edziennik.api.v2.librus.data.synergia
import org.jsoup.Jsoup
import pl.szczodrzynski.edziennik.MONTH
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_SYNERGIA_INFO
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusSynergia
class LibrusSynergiaInfo(override val data: DataLibrus, val onSuccess: () -> Unit) : LibrusSynergia(data) {
companion object {
const val TAG = "LibrusSynergiaInfo"
}
init {
synergiaGet(TAG, "informacja") { text ->
val doc = Jsoup.parse(text)
doc.select("table.form tbody").firstOrNull()?.children()?.also { info ->
val studentNumber = info[2].select("td").text().trim().toIntOrNull()
studentNumber?.also {
data.profile?.studentNumber = it
}
}
data.setSyncNext(ENDPOINT_LIBRUS_SYNERGIA_INFO, MONTH)
onSuccess()
}
}
}