From ff7f0151464e78d3c5875ebf57a12f0efb8d9db2 Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Wed, 23 Oct 2019 22:53:25 +0200 Subject: [PATCH] [APIv2/Librus] Add getting student info (student number) using Synergia --- .../api/v2/librus/data/LibrusData.kt | 5 +++ .../data/synergia/LibrusSynergiaInfo.kt | 34 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/synergia/LibrusSynergiaInfo.kt diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/LibrusData.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/LibrusData.kt index 33ce86c2..0302dc2a 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/LibrusData.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/LibrusData.kt @@ -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() } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/synergia/LibrusSynergiaInfo.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/synergia/LibrusSynergiaInfo.kt new file mode 100644 index 00000000..7777cf6a --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/synergia/LibrusSynergiaInfo.kt @@ -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() + } + } +}