forked from github/szkolny
[API/Edudziennik] Add limited access basic handling and add setting next sync for lucky number.
This commit is contained in:
parent
70de47408a
commit
a24620de31
@ -162,6 +162,7 @@ const val ERROR_LOGIN_EDUDZIENNIK_WEB_INVALID_LOGIN = 501
|
|||||||
const val ERROR_LOGIN_EDUDZIENNIK_WEB_OTHER = 510
|
const val ERROR_LOGIN_EDUDZIENNIK_WEB_OTHER = 510
|
||||||
const val ERROR_LOGIN_EDUDZIENNIK_WEB_NO_SESSION_ID = 511
|
const val ERROR_LOGIN_EDUDZIENNIK_WEB_NO_SESSION_ID = 511
|
||||||
const val ERROR_EDUDZIENNIK_WEB_TIMETABLE_NOT_PUBLIC = 520
|
const val ERROR_EDUDZIENNIK_WEB_TIMETABLE_NOT_PUBLIC = 520
|
||||||
|
const val ERROR_EDUDZIENNIK_WEB_LIMITED_ACCESS = 521
|
||||||
const val ERROR_EDUDZIENNIK_WEB_TEAM_MISSING = 530
|
const val ERROR_EDUDZIENNIK_WEB_TEAM_MISSING = 530
|
||||||
|
|
||||||
const val ERROR_TEMPLATE_WEB_OTHER = 801
|
const val ERROR_TEMPLATE_WEB_OTHER = 801
|
||||||
|
@ -8,10 +8,7 @@ import im.wangchao.mhttp.Request
|
|||||||
import im.wangchao.mhttp.Response
|
import im.wangchao.mhttp.Response
|
||||||
import im.wangchao.mhttp.callback.TextCallbackHandler
|
import im.wangchao.mhttp.callback.TextCallbackHandler
|
||||||
import okhttp3.Cookie
|
import okhttp3.Cookie
|
||||||
import pl.szczodrzynski.edziennik.data.api.EDUDZIENNIK_USER_AGENT
|
import pl.szczodrzynski.edziennik.data.api.*
|
||||||
import pl.szczodrzynski.edziennik.data.api.ERROR_REQUEST_FAILURE
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.ERROR_RESPONSE_EMPTY
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.EXCEPTION_EDUDZIENNIK_WEB_REQUEST
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.DataEdudziennik
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.DataEdudziennik
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||||
@ -54,7 +51,11 @@ open class EdudziennikWeb(open val data: DataEdudziennik) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onFailure(response: Response?, throwable: Throwable?) {
|
override fun onFailure(response: Response?, throwable: Throwable?) {
|
||||||
data.error(ApiError(tag, ERROR_REQUEST_FAILURE)
|
val error = when (response?.code()) {
|
||||||
|
402 -> ERROR_EDUDZIENNIK_WEB_LIMITED_ACCESS
|
||||||
|
else -> ERROR_REQUEST_FAILURE
|
||||||
|
}
|
||||||
|
data.error(ApiError(tag, error)
|
||||||
.withResponse(response)
|
.withResponse(response)
|
||||||
.withThrowable(throwable))
|
.withThrowable(throwable))
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ package pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.web
|
|||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.DataEdudziennik
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.DataEdudziennik
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikWeb
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikWeb
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.luckynumber.LuckyNumber
|
import pl.szczodrzynski.edziennik.data.db.modules.luckynumber.LuckyNumber
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
@ -20,7 +19,7 @@ class EdudziennikWebLuckyNumber(override val data: DataEdudziennik,
|
|||||||
|
|
||||||
init { data.profile?.also { profile ->
|
init { data.profile?.also { profile ->
|
||||||
webGet(TAG, data.schoolEndpoint + "Lucky", xhr = true) { text ->
|
webGet(TAG, data.schoolEndpoint + "Lucky", xhr = true) { text ->
|
||||||
text.toIntOrNull()?.let { luckyNumber ->
|
text.toIntOrNull()?.also { luckyNumber ->
|
||||||
val luckyNumberObject = LuckyNumber(
|
val luckyNumberObject = LuckyNumber(
|
||||||
profileId,
|
profileId,
|
||||||
Date.getToday(),
|
Date.getToday(),
|
||||||
@ -38,7 +37,9 @@ class EdudziennikWebLuckyNumber(override val data: DataEdudziennik,
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER, SYNC_ALWAYS)
|
val nextSync = Date.getToday().stepForward(0, 0, 1).inMillis
|
||||||
|
|
||||||
|
data.setSyncNext(ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER, syncAt = nextSync)
|
||||||
onSuccess()
|
onSuccess()
|
||||||
}
|
}
|
||||||
} ?: onSuccess() }
|
} ?: onSuccess() }
|
||||||
|
@ -17,7 +17,7 @@ class EdudziennikWebTeachers(override val data: DataEdudziennik,
|
|||||||
private const val TAG = "EdudziennikWebTeachers"
|
private const val TAG = "EdudziennikWebTeachers"
|
||||||
}
|
}
|
||||||
|
|
||||||
init { data.profile?.also { profile ->
|
init {
|
||||||
webGet(TAG, data.studentAndTeacherClassEndpoint + "grid") { text ->
|
webGet(TAG, data.studentAndTeacherClassEndpoint + "grid") { text ->
|
||||||
EDUDZIENNIK_TEACHERS.findAll(text).forEach {
|
EDUDZIENNIK_TEACHERS.findAll(text).forEach {
|
||||||
val lastName = it[1].trim()
|
val lastName = it[1].trim()
|
||||||
@ -28,5 +28,5 @@ class EdudziennikWebTeachers(override val data: DataEdudziennik,
|
|||||||
data.setSyncNext(ENDPOINT_EDUDZIENNIK_WEB_TEACHERS, MONTH)
|
data.setSyncNext(ENDPOINT_EDUDZIENNIK_WEB_TEACHERS, MONTH)
|
||||||
onSuccess()
|
onSuccess()
|
||||||
}
|
}
|
||||||
} ?: onSuccess() }
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user