forked from github/szkolny
[APIv2/Librus] Parse document in LibrusSynergia instead of endpoints
This commit is contained in:
parent
35ed31f6b9
commit
5166228915
@ -38,11 +38,11 @@ const val LIBRUS_API_CLIENT_ID_JST = "49"
|
||||
const val LIBRUS_JST_DEMO_CODE = "68656A21"
|
||||
const val LIBRUS_JST_DEMO_PIN = "1290"
|
||||
|
||||
const val LIBRUS_SYNERGIA_URL = "https://synergia.librus.pl/"
|
||||
const val LIBRUS_SYNERGIA_URL = "https://synergia.librus.pl"
|
||||
/** https://synergia.librus.pl/loguj/token/TOKEN/przenies */
|
||||
const val LIBRUS_SYNERGIA_TOKEN_LOGIN_URL = "https://synergia.librus.pl/loguj/token/TOKEN/przenies"
|
||||
|
||||
const val LIBRUS_MESSAGES_URL = "https://wiadomosci.librus.pl/module/"
|
||||
const val LIBRUS_MESSAGES_URL = "https://wiadomosci.librus.pl/module"
|
||||
const val LIBRUS_SANDBOX_URL = "https://sandbox.librus.pl/index.php?action="
|
||||
|
||||
|
||||
|
@ -8,6 +8,8 @@ import im.wangchao.mhttp.Request
|
||||
import im.wangchao.mhttp.Response
|
||||
import im.wangchao.mhttp.callback.TextCallbackHandler
|
||||
import okhttp3.Cookie
|
||||
import org.jsoup.Jsoup
|
||||
import org.jsoup.nodes.Document
|
||||
import pl.szczodrzynski.edziennik.api.v2.*
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
|
||||
@ -25,8 +27,8 @@ open class LibrusSynergia(open val data: DataLibrus) {
|
||||
get() = data.profile
|
||||
|
||||
fun synergiaGet(tag: String, endpoint: String, method: Int = GET,
|
||||
parameters: Map<String, Any> = emptyMap(), onSuccess: (text: String) -> Unit) {
|
||||
d(tag, "Request: Librus/Synergia - $LIBRUS_SYNERGIA_URL$endpoint")
|
||||
parameters: Map<String, Any> = emptyMap(), onSuccess: (doc: Document) -> Unit) {
|
||||
d(tag, "Request: Librus/Synergia - $LIBRUS_SYNERGIA_URL/$endpoint")
|
||||
|
||||
val callback = object : TextCallbackHandler() {
|
||||
override fun onSuccess(text: String?, response: Response?) {
|
||||
@ -39,7 +41,8 @@ open class LibrusSynergia(open val data: DataLibrus) {
|
||||
// TODO: Error handling
|
||||
|
||||
try {
|
||||
onSuccess(text)
|
||||
val doc = Jsoup.parse(text)
|
||||
onSuccess(doc)
|
||||
} catch (e: Exception) {
|
||||
data.error(ApiError(tag, EXCEPTION_LIBRUS_SYNERGIA_REQUEST)
|
||||
.withResponse(response)
|
||||
@ -47,6 +50,12 @@ open class LibrusSynergia(open val data: DataLibrus) {
|
||||
.withApiResponse(text))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(response: Response?, throwable: Throwable?) {
|
||||
data.error(ApiError(tag, ERROR_REQUEST_FAILURE)
|
||||
.withResponse(response)
|
||||
.withThrowable(throwable))
|
||||
}
|
||||
}
|
||||
|
||||
data.app.cookieJar.saveFromResponse(null, listOf(
|
||||
@ -58,7 +67,7 @@ open class LibrusSynergia(open val data: DataLibrus) {
|
||||
))
|
||||
|
||||
Request.builder()
|
||||
.url("$LIBRUS_SYNERGIA_URL$endpoint")
|
||||
.url("$LIBRUS_SYNERGIA_URL/$endpoint")
|
||||
.userAgent(LIBRUS_USER_AGENT)
|
||||
.apply {
|
||||
when (method) {
|
||||
|
@ -1,19 +0,0 @@
|
||||
package pl.szczodrzynski.edziennik.api.v2.librus.data.synergia
|
||||
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.api.v2.models.Data
|
||||
import pl.szczodrzynski.edziennik.data.api.interfaces.ProgressCallback
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile
|
||||
|
||||
class LibrusSynergiaGrades(val app: App,
|
||||
val profile: Profile,
|
||||
val loginStore: LoginStore,
|
||||
val data: Data,
|
||||
val callback: ProgressCallback,
|
||||
val onSuccess: () -> Unit) {
|
||||
|
||||
init {
|
||||
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.librus.data.synergia
|
||||
|
||||
import org.jsoup.Jsoup
|
||||
import pl.szczodrzynski.edziennik.HOUR
|
||||
import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_HOMEWORK
|
||||
import pl.szczodrzynski.edziennik.api.v2.POST
|
||||
@ -32,8 +31,7 @@ class LibrusSynergiaHomework(override val data: DataLibrus, val onSuccess: () ->
|
||||
"dataDo" to profile!!.getSemesterEnd(profile?.currentSemester ?: 2).stringY_m_d,
|
||||
"przedmiot" to -1
|
||||
|
||||
)) { text ->
|
||||
val doc = Jsoup.parse(text)
|
||||
)) { doc ->
|
||||
|
||||
doc.select("table.myHomeworkTable > tbody").firstOrNull()?.also { homeworkTable ->
|
||||
val homeworkElements = homeworkTable.children()
|
||||
@ -93,7 +91,7 @@ class LibrusSynergiaHomework(override val data: DataLibrus, val onSuccess: () ->
|
||||
}
|
||||
|
||||
// because this requires a synergia login (2 more requests) sync this every two hours or if explicit :D
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_SYNERGIA_HOMEWORK, 2*HOUR, DRAWER_ITEM_HOMEWORK)
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_SYNERGIA_HOMEWORK, 2 * HOUR, DRAWER_ITEM_HOMEWORK)
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
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
|
||||
@ -16,8 +15,7 @@ class LibrusSynergiaInfo(override val data: DataLibrus, val onSuccess: () -> Uni
|
||||
}
|
||||
|
||||
init {
|
||||
synergiaGet(TAG, "informacja") { text ->
|
||||
val doc = Jsoup.parse(text)
|
||||
synergiaGet(TAG, "informacja") { doc ->
|
||||
|
||||
doc.select("table.form tbody").firstOrNull()?.children()?.also { info ->
|
||||
val studentNumber = info[2].select("td").text().trim().toIntOrNull()
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.librus.data.synergia
|
||||
|
||||
import org.jsoup.Jsoup
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusSynergia
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
@ -15,8 +14,7 @@ class LibrusSynergiaTemplate(override val data: DataLibrus, val onSuccess: () ->
|
||||
}
|
||||
|
||||
init {
|
||||
/* synergiaGet(TAG, "") { text ->
|
||||
val doc = Jsoup.parse(text)
|
||||
/* synergiaGet(TAG, "") { doc ->
|
||||
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_SYNERGIA_, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
|
@ -158,26 +158,26 @@ class DataVulcan(app: App, profile: Profile?, loginStore: LoginStore) : Data(app
|
||||
val apiUrl: String?
|
||||
get() {
|
||||
val url = when (apiToken?.substring(0, 3)) {
|
||||
"3S1" -> "https://lekcjaplus.vulcan.net.pl/"
|
||||
"TA1" -> "https://uonetplus-komunikacja.umt.tarnow.pl/"
|
||||
"OP1" -> "https://uonetplus-komunikacja.eszkola.opolskie.pl/"
|
||||
"RZ1" -> "https://uonetplus-komunikacja.resman.pl/"
|
||||
"GD1" -> "https://uonetplus-komunikacja.edu.gdansk.pl/"
|
||||
"KA1" -> "https://uonetplus-komunikacja.mcuw.katowice.eu/"
|
||||
"KA2" -> "https://uonetplus-komunikacja-test.mcuw.katowice.eu/"
|
||||
"P03" -> "https://efeb-komunikacja-pro-efebmobile.pro.vulcan.pl/"
|
||||
"P01" -> "http://efeb-komunikacja.pro-hudson.win.vulcan.pl/"
|
||||
"P02" -> "http://efeb-komunikacja.pro-hudsonrc.win.vulcan.pl/"
|
||||
"P90" -> "http://efeb-komunikacja-pro-mwujakowska.neo.win.vulcan.pl/"
|
||||
"FK1", "FS1" -> "http://api.fakelog.cf/"
|
||||
"SZ9" -> "http://vulcan.szkolny.eu/"
|
||||
"3S1" -> "https://lekcjaplus.vulcan.net.pl"
|
||||
"TA1" -> "https://uonetplus-komunikacja.umt.tarnow.pl"
|
||||
"OP1" -> "https://uonetplus-komunikacja.eszkola.opolskie.pl"
|
||||
"RZ1" -> "https://uonetplus-komunikacja.resman.pl"
|
||||
"GD1" -> "https://uonetplus-komunikacja.edu.gdansk.pl"
|
||||
"KA1" -> "https://uonetplus-komunikacja.mcuw.katowice.eu"
|
||||
"KA2" -> "https://uonetplus-komunikacja-test.mcuw.katowice.eu"
|
||||
"P03" -> "https://efeb-komunikacja-pro-efebmobile.pro.vulcan.pl"
|
||||
"P01" -> "http://efeb-komunikacja.pro-hudson.win.vulcan.pl"
|
||||
"P02" -> "http://efeb-komunikacja.pro-hudsonrc.win.vulcan.pl"
|
||||
"P90" -> "http://efeb-komunikacja-pro-mwujakowska.neo.win.vulcan.pl"
|
||||
"FK1", "FS1" -> "http://api.fakelog.cf"
|
||||
"SZ9" -> "http://vulcan.szkolny.eu"
|
||||
else -> null
|
||||
}
|
||||
return if (url != null) "$url$symbol/" else null
|
||||
return if (url != null) "$url/$symbol" else null
|
||||
}
|
||||
|
||||
val fullApiUrl: String?
|
||||
get() {
|
||||
return "${apiUrl}${schoolSymbol}/"
|
||||
return "${apiUrl}/${schoolSymbol}/"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user