Migrate mobile module to coroutines

This commit is contained in:
Mikołaj Pich 2020-06-14 19:05:55 +02:00
parent 0165e05aae
commit 08ec425b6a
19 changed files with 176 additions and 260 deletions

View file

@ -22,7 +22,6 @@ import io.github.wulkanowy.sdk.mobile.repository.RepositoryManager
import io.github.wulkanowy.sdk.mobile.school.Teacher
import io.github.wulkanowy.sdk.mobile.timetable.Lesson
import io.github.wulkanowy.signer.getPrivateKeyFromCert
import io.reactivex.Single
import okhttp3.Interceptor
import okhttp3.logging.HttpLoggingInterceptor
import org.threeten.bp.LocalDate
@ -83,21 +82,19 @@ class Mobile {
private lateinit var dictionaries: Dictionaries
fun getDictionaries(): Single<Dictionaries> {
if (::dictionaries.isInitialized) return Single.just(dictionaries)
suspend fun getDictionaries(): Dictionaries {
if (::dictionaries.isInitialized) return dictionaries
return mobile.getDictionaries(0, 0, classId).map {
it.apply { dictionaries = this }
}
return mobile.getDictionaries(0, 0, classId)
.apply { dictionaries = this }
}
fun getCertificate(token: String, pin: String, symbol: String, deviceName: String, androidVer: String, firebaseToken: String): Single<CertificateResponse> {
return routes.getRouteByToken(token).flatMap { baseUrl ->
serviceManager.getRegisterRepository(baseUrl, symbol).getCertificate(token, pin, deviceName, androidVer, firebaseToken)
}
suspend fun getCertificate(token: String, pin: String, symbol: String, deviceName: String, androidVer: String, firebaseToken: String): CertificateResponse {
val baseUrl = routes.getRouteByToken(token)
return serviceManager.getRegisterRepository(baseUrl, symbol).getCertificate(token, pin, deviceName, androidVer, firebaseToken)
}
fun getStudents(certRes: CertificateResponse, apiKey: String = ""): Single<List<Student>> {
suspend fun getStudents(certRes: CertificateResponse, apiKey: String = ""): List<Student> {
if (certRes.isError) when {
certRes.message == "TokenDead" -> throw TokenDeadException(certRes.message)
certRes.message == "TokenNotFound" -> throw TokenNotFoundException(certRes.message)
@ -117,8 +114,7 @@ class Mobile {
.removeSurrounding("(", ")")
}, cert.certificatePfx)
return serviceManager.getRegisterRepository(cert.baseUrl).getStudents().map { students ->
students.map {
return serviceManager.getRegisterRepository(cert.baseUrl).getStudents().map {
it.copy().apply {
certificateKey = this@Mobile.certKey
privateKey = this@Mobile.privateKey
@ -126,73 +122,65 @@ class Mobile {
}
}
}
}
fun getStudents(): Single<List<Student>> {
suspend fun getStudents(): List<Student> {
return serviceManager.getRegisterRepository(baseUrl).getStudents()
}
fun getAttendance(start: LocalDate, end: LocalDate, classificationPeriodId: Int): Single<List<Attendance>> {
suspend fun getAttendance(start: LocalDate, end: LocalDate, classificationPeriodId: Int): List<Attendance> {
return mobile.getAttendance(start, end, classId, classificationPeriodId, studentId)
}
fun getExams(start: LocalDate, end: LocalDate, classificationPeriodId: Int): Single<List<Exam>> {
suspend fun getExams(start: LocalDate, end: LocalDate, classificationPeriodId: Int): List<Exam> {
return mobile.getExams(start, end, classId, classificationPeriodId, studentId)
}
fun getGrades(classificationPeriodId: Int): Single<Pair<List<Grade>, GradesSummaryResponse>> {
return getGradesDetails(classificationPeriodId).flatMap { details ->
getGradesSummary(classificationPeriodId).map { summary ->
details to summary
}
}
suspend fun getGrades(classificationPeriodId: Int): Pair<List<Grade>, GradesSummaryResponse> {
return getGradesDetails(classificationPeriodId) to getGradesSummary(classificationPeriodId)
}
fun getGradesDetails(classificationPeriodId: Int): Single<List<Grade>> {
suspend fun getGradesDetails(classificationPeriodId: Int): List<Grade> {
return mobile.getGradesDetails(classId, classificationPeriodId, studentId)
}
fun getGradesSummary(classificationPeriodId: Int): Single<GradesSummaryResponse> {
suspend fun getGradesSummary(classificationPeriodId: Int): GradesSummaryResponse {
return mobile.getGradesSummary(classId, classificationPeriodId, studentId)
}
fun getHomework(start: LocalDate, end: LocalDate, classificationPeriodId: Int): Single<List<Homework>> {
suspend fun getHomework(start: LocalDate, end: LocalDate, classificationPeriodId: Int): List<Homework> {
return mobile.getHomework(start, end, classId, classificationPeriodId, studentId)
}
fun getNotes(classificationPeriodId: Int): Single<List<Note>> {
suspend fun getNotes(classificationPeriodId: Int): List<Note> {
return mobile.getNotes(classificationPeriodId, studentId)
}
fun getTeachers(studentId: Int, semesterId: Int): Single<List<Teacher>> {
suspend fun getTeachers(studentId: Int, semesterId: Int): List<Teacher> {
return mobile.getTeachers(studentId, semesterId)
}
fun getMessages(start: LocalDateTime, end: LocalDateTime): Single<List<Message>> {
suspend fun getMessages(start: LocalDateTime, end: LocalDateTime): List<Message> {
return mobile.getMessages(start, end, loginId, studentId)
}
fun getMessagesSent(start: LocalDateTime, end: LocalDateTime): Single<List<Message>> {
suspend fun getMessagesSent(start: LocalDateTime, end: LocalDateTime): List<Message> {
return mobile.getMessagesSent(start, end, loginId, studentId)
}
fun getMessagesDeleted(start: LocalDateTime, end: LocalDateTime): Single<List<Message>> {
suspend fun getMessagesDeleted(start: LocalDateTime, end: LocalDateTime): List<Message> {
return mobile.getMessagesDeleted(start, end, loginId, studentId)
}
fun changeMessageStatus(messageId: Int, folder: String, status: String): Single<String> {
suspend fun changeMessageStatus(messageId: Int, folder: String, status: String): String {
return mobile.changeMessageStatus(messageId, folder, status, loginId, studentId)
}
fun sendMessage(subject: String, content: String, recipients: List<Recipient>): Single<Message> {
return getStudents().map { students ->
students.singleOrNull { it.loginId == loginId }?.name.orEmpty()
}.flatMap { sender ->
mobile.sendMessage(sender, subject, content, recipients, loginId, studentId)
}
suspend fun sendMessage(subject: String, content: String, recipients: List<Recipient>): Message {
val sender = getStudents().singleOrNull { it.loginId == loginId }?.name.orEmpty()
return mobile.sendMessage(sender, subject, content, recipients, loginId, studentId)
}
fun getTimetable(start: LocalDate, end: LocalDate, classificationPeriodId: Int): Single<List<Lesson>> {
suspend fun getTimetable(start: LocalDate, end: LocalDate, classificationPeriodId: Int): List<Lesson> {
return mobile.getTimetable(start, end, classId, classificationPeriodId, studentId)
}
}

View file

@ -17,5 +17,5 @@ data class AttendanceResponse(
val dateEndText: String,
@SerializedName("Frekwencje")
val data: List<Attendance>
val items: List<Attendance>
)

View file

@ -26,69 +26,68 @@ import io.github.wulkanowy.sdk.mobile.service.MobileService
import io.github.wulkanowy.sdk.mobile.timetable.Lesson
import io.github.wulkanowy.sdk.mobile.timetable.TimetableRequest
import io.github.wulkanowy.sdk.mobile.toFormat
import io.reactivex.Single
import org.threeten.bp.LocalDate
import org.threeten.bp.LocalDateTime
class MobileRepository(private val api: MobileService) {
fun logStart(): Single<ApiResponse<String>> = api.logAppStart(object : ApiRequest() {})
suspend fun logStart(): ApiResponse<String> = api.logAppStart(object : ApiRequest() {})
fun getDictionaries(userId: Int, classificationPeriodId: Int, classId: Int): Single<Dictionaries> {
return api.getDictionaries(DictionariesRequest(userId, classificationPeriodId, classId)).map { requireNotNull(it.data) }
suspend fun getDictionaries(userId: Int, classificationPeriodId: Int, classId: Int): Dictionaries {
return api.getDictionaries(DictionariesRequest(userId, classificationPeriodId, classId)).data!!
}
fun getTeachers(studentId: Int, semesterId: Int): Single<List<Teacher>> {
return api.getTeachers(TeachersRequest(studentId, semesterId)).map { requireNotNull(it.data) }.map {
it.schoolTeachers.union(it.teachersSubjects).toList()
suspend fun getTeachers(studentId: Int, semesterId: Int): List<Teacher> {
return api.getTeachers(TeachersRequest(studentId, semesterId)).data.let {
it?.schoolTeachers.orEmpty().union(it?.teachersSubjects.orEmpty()).toList()
}
}
fun getTimetable(start: LocalDate, end: LocalDate, classId: Int, classificationPeriodId: Int, studentId: Int): Single<List<Lesson>> {
return api.getTimetable(TimetableRequest(start.toFormat(), end.toFormat(), classId, classificationPeriodId, studentId)).map { requireNotNull(it.data) }
suspend fun getTimetable(start: LocalDate, end: LocalDate, classId: Int, classificationPeriodId: Int, studentId: Int): List<Lesson> {
return api.getTimetable(TimetableRequest(start.toFormat(), end.toFormat(), classId, classificationPeriodId, studentId)).data!!
}
fun getGradesDetails(classId: Int, classificationPeriodId: Int, studentId: Int): Single<List<Grade>> {
return api.getGrades(GradesRequest(classId, classificationPeriodId, studentId)).map { requireNotNull(it.data) }
suspend fun getGradesDetails(classId: Int, classificationPeriodId: Int, studentId: Int): List<Grade> {
return api.getGrades(GradesRequest(classId, classificationPeriodId, studentId)).data!!
}
fun getGradesSummary(classId: Int, classificationPeriodId: Int, studentId: Int): Single<GradesSummaryResponse> {
return api.getGradesSummary(GradesRequest(classId, classificationPeriodId, studentId)).map { requireNotNull(it.data) }
suspend fun getGradesSummary(classId: Int, classificationPeriodId: Int, studentId: Int): GradesSummaryResponse {
return api.getGradesSummary(GradesRequest(classId, classificationPeriodId, studentId)).data!!
}
fun getExams(start: LocalDate, end: LocalDate, classId: Int, classificationPeriodId: Int, studentId: Int): Single<List<Exam>> {
return api.getExams(ExamsRequest(start.toFormat(), end.toFormat(), classId, classificationPeriodId, studentId)).map { requireNotNull(it.data) }
suspend fun getExams(start: LocalDate, end: LocalDate, classId: Int, classificationPeriodId: Int, studentId: Int): List<Exam> {
return api.getExams(ExamsRequest(start.toFormat(), end.toFormat(), classId, classificationPeriodId, studentId)).data!!
}
fun getNotes(classificationPeriodId: Int, studentId: Int): Single<List<Note>> {
return api.getNotes(NotesRequest(classificationPeriodId, studentId)).map { requireNotNull(it.data) }
suspend fun getNotes(classificationPeriodId: Int, studentId: Int): List<Note> {
return api.getNotes(NotesRequest(classificationPeriodId, studentId)).data!!
}
fun getAttendance(start: LocalDate, end: LocalDate, classId: Int, classificationPeriodId: Int, studentId: Int): Single<List<Attendance>> {
return api.getAttendance(AttendanceRequest(start.toFormat(), end.toFormat(), classId, classificationPeriodId, studentId)).map { requireNotNull(it.data?.data) }
suspend fun getAttendance(start: LocalDate, end: LocalDate, classId: Int, classificationPeriodId: Int, studentId: Int): List<Attendance> {
return api.getAttendance(AttendanceRequest(start.toFormat(), end.toFormat(), classId, classificationPeriodId, studentId)).data!!.items
}
fun getHomework(start: LocalDate, end: LocalDate, classId: Int, classificationPeriodId: Int, studentId: Int): Single<List<Homework>> {
return api.getHomework(HomeworkRequest(start.toFormat(), end.toFormat(), classId, classificationPeriodId, studentId)).map { requireNotNull(it.data) }
suspend fun getHomework(start: LocalDate, end: LocalDate, classId: Int, classificationPeriodId: Int, studentId: Int): List<Homework> {
return api.getHomework(HomeworkRequest(start.toFormat(), end.toFormat(), classId, classificationPeriodId, studentId)).data!!
}
fun getMessages(start: LocalDateTime, end: LocalDateTime, loginId: Int, studentId: Int): Single<List<Message>> {
return api.getMessages(MessagesRequest(start.toFormat(), end.toFormat(), loginId, studentId)).map { requireNotNull(it.data) }
suspend fun getMessages(start: LocalDateTime, end: LocalDateTime, loginId: Int, studentId: Int): List<Message> {
return api.getMessages(MessagesRequest(start.toFormat(), end.toFormat(), loginId, studentId)).data!!
}
fun getMessagesDeleted(start: LocalDateTime, end: LocalDateTime, loginId: Int, studentId: Int): Single<List<Message>> {
return api.getMessagesDeleted(MessagesRequest(start.toFormat(), end.toFormat(), loginId, studentId)).map { requireNotNull(it.data) }
suspend fun getMessagesDeleted(start: LocalDateTime, end: LocalDateTime, loginId: Int, studentId: Int): List<Message> {
return api.getMessagesDeleted(MessagesRequest(start.toFormat(), end.toFormat(), loginId, studentId)).data!!
}
fun getMessagesSent(start: LocalDateTime, end: LocalDateTime, loginId: Int, studentId: Int): Single<List<Message>> {
return api.getMessagesSent(MessagesRequest(start.toFormat(), end.toFormat(), loginId, studentId)).map { requireNotNull(it.data) }
suspend fun getMessagesSent(start: LocalDateTime, end: LocalDateTime, loginId: Int, studentId: Int): List<Message> {
return api.getMessagesSent(MessagesRequest(start.toFormat(), end.toFormat(), loginId, studentId)).data!!
}
fun changeMessageStatus(messageId: Int, folder: String, status: String, loginId: Int, studentId: Int): Single<String> {
return api.changeMessageStatus(MessageStatusChangeRequest(messageId, folder, status, loginId, studentId)).map { requireNotNull(it.data) }
suspend fun changeMessageStatus(messageId: Int, folder: String, status: String, loginId: Int, studentId: Int): String {
return api.changeMessageStatus(MessageStatusChangeRequest(messageId, folder, status, loginId, studentId)).data!!
}
fun sendMessage(sender: String, subject: String, content: String, recipients: List<Recipient>, loginId: Int, studentId: Int): Single<Message> {
suspend fun sendMessage(sender: String, subject: String, content: String, recipients: List<Recipient>, loginId: Int, studentId: Int): Message {
return api.sendMessage(SendMessageRequest(
sender = sender,
subject = subject,

View file

@ -5,11 +5,10 @@ import io.github.wulkanowy.sdk.mobile.register.CertificateRequest
import io.github.wulkanowy.sdk.mobile.register.CertificateResponse
import io.github.wulkanowy.sdk.mobile.register.Student
import io.github.wulkanowy.sdk.mobile.service.RegisterService
import io.reactivex.Single
class RegisterRepository(private val api: RegisterService) {
fun getCertificate(token: String, pin: String, deviceName: String, android: String, firebaseToken: String): Single<CertificateResponse> {
suspend fun getCertificate(token: String, pin: String, deviceName: String, android: String, firebaseToken: String): CertificateResponse {
return api.getCertificate(CertificateRequest(
tokenKey = token,
pin = pin,
@ -19,5 +18,5 @@ class RegisterRepository(private val api: RegisterService) {
))
}
fun getStudents(): Single<List<Student>> = api.getPupils(object : ApiRequest() {}).map { requireNotNull(it.data) }
suspend fun getStudents(): List<Student> = api.getPupils(object : ApiRequest() {}).data.orEmpty()
}

View file

@ -6,7 +6,6 @@ import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.scalars.ScalarsConverterFactory
import retrofit2.create
@ -36,7 +35,6 @@ class RepositoryManager(
private fun getRetrofitBuilder(interceptors: MutableList<Pair<Interceptor, Boolean>>): Retrofit.Builder {
return Retrofit.Builder()
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.client(OkHttpClient().newBuilder()

View file

@ -3,22 +3,19 @@ package io.github.wulkanowy.sdk.mobile.repository
import io.github.wulkanowy.sdk.mobile.exception.InvalidTokenException
import io.github.wulkanowy.sdk.mobile.exception.UnknownTokenException
import io.github.wulkanowy.sdk.mobile.service.RoutingRulesService
import io.reactivex.Single
class RoutingRulesRepository(private val api: RoutingRulesService) {
fun getRouteByToken(token: String): Single<String> {
if (token.length < 4) return Single.error<String>(InvalidTokenException("Token '$token' is too short"))
suspend fun getRouteByToken(token: String): String {
if (token.length < 4) throw InvalidTokenException("Token '$token' is too short")
val tokenSymbol = token.substring(0..2)
if ("FK1" == tokenSymbol) return Single.just("https://api.fakelog.tk")
if ("FK1" == tokenSymbol) return "https://api.fakelog.tk"
return api.getRoutingRules().map { routes ->
routes.split("\r?\n".toRegex())
return api.getRoutingRules().split("\r?\n".toRegex())
.singleOrNull { tokenSymbol == it.substringBefore(",") }
?.substringAfter(",")
?: throw UnknownTokenException("This token: '$token' is unsupported")
}
}
}

View file

@ -23,54 +23,53 @@ import io.github.wulkanowy.sdk.mobile.school.TeachersRequest
import io.github.wulkanowy.sdk.mobile.school.TeachersResponse
import io.github.wulkanowy.sdk.mobile.timetable.Lesson
import io.github.wulkanowy.sdk.mobile.timetable.TimetableRequest
import io.reactivex.Single
import retrofit2.http.Body
import retrofit2.http.POST
interface MobileService {
@POST("LogAppStart")
fun logAppStart(@Body logAppStartRequest: ApiRequest): Single<ApiResponse<String>>
suspend fun logAppStart(@Body logAppStartRequest: ApiRequest): ApiResponse<String>
@POST("Slowniki")
fun getDictionaries(@Body dictionariesRequest: DictionariesRequest): Single<ApiResponse<Dictionaries>>
suspend fun getDictionaries(@Body dictionariesRequest: DictionariesRequest): ApiResponse<Dictionaries>
@POST("Nauczyciele")
fun getTeachers(@Body teachersRequest: TeachersRequest): Single<ApiResponse<TeachersResponse>>
suspend fun getTeachers(@Body teachersRequest: TeachersRequest): ApiResponse<TeachersResponse>
@POST("PlanLekcjiZeZmianami")
fun getTimetable(@Body timetableRequest: TimetableRequest): Single<ApiResponse<List<Lesson>>>
suspend fun getTimetable(@Body timetableRequest: TimetableRequest): ApiResponse<List<Lesson>>
@POST("Oceny")
fun getGrades(@Body gradesRequest: GradesRequest): Single<ApiResponse<List<Grade>>>
suspend fun getGrades(@Body gradesRequest: GradesRequest): ApiResponse<List<Grade>>
@POST("OcenyPodsumowanie")
fun getGradesSummary(@Body gradesRequest: GradesRequest): Single<ApiResponse<GradesSummaryResponse>>
suspend fun getGradesSummary(@Body gradesRequest: GradesRequest): ApiResponse<GradesSummaryResponse>
@POST("Sprawdziany")
fun getExams(@Body examsRequest: ExamsRequest): Single<ApiResponse<List<Exam>>>
suspend fun getExams(@Body examsRequest: ExamsRequest): ApiResponse<List<Exam>>
@POST("UwagiUcznia")
fun getNotes(@Body notesRequest: NotesRequest): Single<ApiResponse<List<Note>>>
suspend fun getNotes(@Body notesRequest: NotesRequest): ApiResponse<List<Note>>
@POST("Frekwencje")
fun getAttendance(@Body attendanceRequest: AttendanceRequest): Single<ApiResponse<AttendanceResponse>>
suspend fun getAttendance(@Body attendanceRequest: AttendanceRequest): ApiResponse<AttendanceResponse>
@POST("ZadaniaDomowe")
fun getHomework(@Body homeworkRequest: HomeworkRequest): Single<ApiResponse<List<Homework>>>
suspend fun getHomework(@Body homeworkRequest: HomeworkRequest): ApiResponse<List<Homework>>
@POST("WiadomosciOdebrane")
fun getMessages(@Body messagesRequest: MessagesRequest): Single<ApiResponse<List<Message>>>
suspend fun getMessages(@Body messagesRequest: MessagesRequest): ApiResponse<List<Message>>
@POST("WiadomosciWyslane")
fun getMessagesSent(@Body messagesRequest: MessagesRequest): Single<ApiResponse<List<Message>>>
suspend fun getMessagesSent(@Body messagesRequest: MessagesRequest): ApiResponse<List<Message>>
@POST("WiadomosciUsuniete")
fun getMessagesDeleted(@Body messagesRequest: MessagesRequest): Single<ApiResponse<List<Message>>>
suspend fun getMessagesDeleted(@Body messagesRequest: MessagesRequest): ApiResponse<List<Message>>
@POST("ZmienStatusWiadomosci")
fun changeMessageStatus(@Body messageStatusChangeRequest: MessageStatusChangeRequest): Single<ApiResponse<String>>
suspend fun changeMessageStatus(@Body messageStatusChangeRequest: MessageStatusChangeRequest): ApiResponse<String>
@POST("DodajWiadomosc")
fun sendMessage(@Body sendMessageRequest: SendMessageRequest): Single<Message>
suspend fun sendMessage(@Body sendMessageRequest: SendMessageRequest): Message
}

View file

@ -5,7 +5,6 @@ import io.github.wulkanowy.sdk.mobile.ApiResponse
import io.github.wulkanowy.sdk.mobile.register.CertificateRequest
import io.github.wulkanowy.sdk.mobile.register.CertificateResponse
import io.github.wulkanowy.sdk.mobile.register.Student
import io.reactivex.Single
import retrofit2.http.Body
import retrofit2.http.Headers
import retrofit2.http.POST
@ -14,8 +13,8 @@ interface RegisterService {
@POST("Certyfikat")
@Headers("RequestMobileType: RegisterDevice")
fun getCertificate(@Body certificateRequest: CertificateRequest): Single<CertificateResponse>
suspend fun getCertificate(@Body certificateRequest: CertificateRequest): CertificateResponse
@POST("ListaUczniow")
fun getPupils(@Body pupilsListRequest: ApiRequest): Single<ApiResponse<List<Student>>>
suspend fun getPupils(@Body pupilsListRequest: ApiRequest): ApiResponse<List<Student>>
}

View file

@ -1,10 +1,9 @@
package io.github.wulkanowy.sdk.mobile.service
import io.reactivex.Single
import retrofit2.http.GET
interface RoutingRulesService {
@GET("/UonetPlusMobile/RoutingRules.txt")
fun getRoutingRules(): Single<String>
suspend fun getRoutingRules(): String
}

View file

@ -7,7 +7,6 @@ import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.scalars.ScalarsConverterFactory
@ -32,7 +31,6 @@ open class BaseLocalTest {
fun getRetrofit(baseUrl: String = server.url("/").toString()): Retrofit = getRetrofitBuilder().baseUrl(baseUrl).build()
fun getRetrofitBuilder(): Retrofit.Builder = Retrofit.Builder()
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.client(OkHttpClient().newBuilder()

View file

@ -1,20 +1,12 @@
package io.github.wulkanowy.sdk.mobile
import io.github.wulkanowy.sdk.mobile.attendance.Attendance
import io.github.wulkanowy.sdk.mobile.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.mobile.exams.Exam
import io.github.wulkanowy.sdk.mobile.grades.Grade
import io.github.wulkanowy.sdk.mobile.homework.Homework
import io.github.wulkanowy.sdk.mobile.interceptor.SignInterceptor
import io.github.wulkanowy.sdk.mobile.notes.Note
import io.github.wulkanowy.sdk.mobile.register.CertificateResponse
import io.github.wulkanowy.sdk.mobile.register.Student
import io.github.wulkanowy.sdk.mobile.repository.MobileRepository
import io.github.wulkanowy.sdk.mobile.repository.RegisterRepository
import io.github.wulkanowy.sdk.mobile.timetable.Lesson
import io.github.wulkanowy.signer.getPrivateKeyFromCert
import io.reactivex.observers.TestObserver
import junit.framework.TestCase.assertEquals
import kotlinx.coroutines.runBlocking
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.junit.BeforeClass
@ -22,7 +14,6 @@ import org.junit.Ignore
import org.junit.Test
import org.threeten.bp.LocalDate.of
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.scalars.ScalarsConverterFactory
import retrofit2.create
@ -45,7 +36,6 @@ class UonetTest {
private fun getRetrofitBuilder(privateKey: String, certKey: String): Retrofit.Builder {
return Retrofit.Builder()
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.client(OkHttpClient().newBuilder()
@ -64,29 +54,21 @@ class UonetTest {
.build().create()
)
val certificate = register.getCertificate(TOKEN, PIN, DEVICE_NAME, "8.1.0", "")
val certSubscriber = TestObserver<CertificateResponse>()
certificate.subscribe(certSubscriber)
certSubscriber.assertComplete()
certSubscriber.assertNoErrors()
val certificate = runBlocking { register.getCertificate(TOKEN, PIN, DEVICE_NAME, "8.1.0", "") }
assertEquals(false, certSubscriber.values()[0].isError)
assertEquals(false, certificate.isError)
val tokenCrt = certSubscriber.values()[0].tokenCert
val tokenCrt = certificate.tokenCert
val certKey = tokenCrt!!.certificateKey
val cert = tokenCrt.certificatePfx
val privateKey = getPrivateKeyFromCert(PASSWORD, cert)
val pupils = register.getStudents()
val pupilSubscriber = TestObserver<List<Student>>()
pupils.subscribe(pupilSubscriber)
pupilSubscriber.assertComplete()
pupilSubscriber.assertNoErrors()
assertEquals(2, pupilSubscriber.values()[0].size)
val pupils = runBlocking { register.getStudents() }
assertEquals(2, pupils.size)
student = pupilSubscriber.values()[0][0]
student = pupils[0]
// MobileRepository
mobile = MobileRepository(getRetrofitBuilder(privateKey, certKey)
@ -98,74 +80,42 @@ class UonetTest {
@Test
fun logStartTest() {
val start = mobile.logStart()
val startSubscriber = TestObserver<ApiResponse<String>>()
start.subscribe(startSubscriber)
startSubscriber.assertComplete()
startSubscriber.assertNoErrors()
assertEquals("Ok", startSubscriber.values()[0].status)
val start = runBlocking { mobile.logStart() }
assertEquals("Ok", start.status)
}
@Test
fun dictionariesTest() {
val dictionaries = mobile.getDictionaries(student.userLoginId, student.classificationPeriodId, student.classId)
val dictionariesSubscriber = TestObserver<Dictionaries>()
dictionaries.subscribe(dictionariesSubscriber)
dictionariesSubscriber.assertComplete()
dictionariesSubscriber.assertNoErrors()
runBlocking { mobile.getDictionaries(student.userLoginId, student.classificationPeriodId, student.classId) }
}
@Test
fun timetableTest() {
val lessons = mobile.getTimetable(of(2018, 4, 23), of(2018, 4, 24), student.classId, student.classificationPeriodId, student.id)
val lessonsSubscriber = TestObserver<List<Lesson>>()
lessons.subscribe(lessonsSubscriber)
lessonsSubscriber.assertComplete()
lessonsSubscriber.assertNoErrors()
runBlocking { mobile.getTimetable(of(2018, 4, 23), of(2018, 4, 24), student.classId, student.classificationPeriodId, student.id) }
}
@Test
fun gradesTest() {
val grades = mobile.getGradesDetails(student.classId, student.classificationPeriodId, student.id)
val gradesSubscriber = TestObserver<List<Grade>>()
grades.subscribe(gradesSubscriber)
gradesSubscriber.assertComplete()
gradesSubscriber.assertNoErrors()
runBlocking { mobile.getGradesDetails(student.classId, student.classificationPeriodId, student.id) }
}
@Test
fun examsTest() {
val exams = mobile.getExams(of(2018, 5, 28), of(2018, 6, 3), student.classId, student.classificationPeriodId, student.id)
val examsSubscriber = TestObserver<List<Exam>>()
exams.subscribe(examsSubscriber)
examsSubscriber.assertComplete()
examsSubscriber.assertNoErrors()
runBlocking { mobile.getExams(of(2018, 5, 28), of(2018, 6, 3), student.classId, student.classificationPeriodId, student.id) }
}
@Test
fun notesTest() {
val notes = mobile.getNotes(student.classificationPeriodId, student.id)
val notesSubscriber = TestObserver<List<Note>>()
notes.subscribe(notesSubscriber)
notesSubscriber.assertComplete()
notesSubscriber.assertNoErrors()
runBlocking { mobile.getNotes(student.classificationPeriodId, student.id) }
}
@Test
fun attendanceTest() {
val attendance = mobile.getAttendance(of(2018, 4, 23), of(2018, 4, 24), student.classId, student.classificationPeriodId, student.id)
val attendanceSubscriber = TestObserver<List<Attendance>>()
attendance.subscribe(attendanceSubscriber)
attendanceSubscriber.assertComplete()
attendanceSubscriber.assertNoErrors()
runBlocking { mobile.getAttendance(of(2018, 4, 23), of(2018, 4, 24), student.classId, student.classificationPeriodId, student.id) }
}
@Test
fun homeworkTest() {
val homework = mobile.getHomework(of(2017, 10, 23), of(2017, 10, 27), student.classId, student.classificationPeriodId, student.id)
val homeworkSubscriber = TestObserver<List<Homework>>()
homework.subscribe(homeworkSubscriber)
homeworkSubscriber.assertComplete()
homeworkSubscriber.assertNoErrors()
runBlocking { mobile.getHomework(of(2017, 10, 23), of(2017, 10, 27), student.classId, student.classificationPeriodId, student.id) }
}
}

View file

@ -2,6 +2,7 @@ package io.github.wulkanowy.sdk.mobile.exams
import io.github.wulkanowy.sdk.mobile.BaseLocalTest
import io.github.wulkanowy.sdk.mobile.repository.MobileRepository
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Test
import org.threeten.bp.LocalDate.of
@ -15,7 +16,7 @@ class ExamsTest : BaseLocalTest() {
fun getExams() {
server.enqueueAndStart("Sprawdziany.json")
val items = exams.getExams(of(2020, 1, 16), of(2020, 1, 17), 1, 2, 3).blockingGet()
val items = runBlocking { exams.getExams(of(2020, 1, 16), of(2020, 1, 17), 1, 2, 3) }
assertEquals(3, items.size)
}

View file

@ -2,6 +2,7 @@ package io.github.wulkanowy.sdk.mobile.grades
import io.github.wulkanowy.sdk.mobile.BaseLocalTest
import io.github.wulkanowy.sdk.mobile.repository.MobileRepository
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Test
import retrofit2.create
@ -14,7 +15,7 @@ class GradesTest : BaseLocalTest() {
fun getGrades() {
server.enqueueAndStart("Oceny.json")
val items = grades.getGradesDetails(0, 0, 0).blockingGet()
val items = runBlocking { grades.getGradesDetails(0, 0, 0) }
assertEquals(2, items.size)
}

View file

@ -2,9 +2,9 @@ package io.github.wulkanowy.sdk.mobile.interceptor
import io.github.wulkanowy.sdk.mobile.BaseLocalTest
import io.github.wulkanowy.sdk.mobile.exception.InvalidSymbolException
import io.github.wulkanowy.sdk.mobile.register.Student
import io.github.wulkanowy.sdk.mobile.repository.RegisterRepository
import io.reactivex.observers.TestObserver
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertTrue
import org.junit.Test
import retrofit2.create
import java.io.IOException
@ -16,11 +16,12 @@ class ErrorInterceptorTest : BaseLocalTest() {
server.enqueueAndStart("bad-request.txt")
val repo = RegisterRepository(getRetrofitBuilder().baseUrl("http://localhost:3030/").build().create())
val students = repo.getStudents()
val studentsObserver = TestObserver<List<Student>>()
students.subscribe(studentsObserver)
studentsObserver.assertNotComplete()
studentsObserver.assertError(IOException::class.java)
try {
runBlocking { repo.getStudents() }
} catch (e: Throwable) {
assertTrue(e is IOException)
}
}
@Test
@ -28,10 +29,11 @@ class ErrorInterceptorTest : BaseLocalTest() {
server.enqueueAndStart("invalid-symbol.html")
val repo = RegisterRepository(getRetrofitBuilder().baseUrl("http://localhost:3030/").build().create())
val students = repo.getStudents()
val studentsObserver = TestObserver<List<Student>>()
students.subscribe(studentsObserver)
studentsObserver.assertNotComplete()
studentsObserver.assertError(InvalidSymbolException::class.java)
try {
runBlocking { repo.getStudents() }
} catch (e: Throwable) {
assertTrue(e is InvalidSymbolException)
}
}
}

View file

@ -2,6 +2,7 @@ package io.github.wulkanowy.sdk.mobile.register
import io.github.wulkanowy.sdk.mobile.BaseLocalTest
import io.github.wulkanowy.sdk.mobile.repository.RegisterRepository
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Test
import retrofit2.create
@ -14,7 +15,7 @@ class RegisterTest : BaseLocalTest() {
fun getStudents() {
server.enqueueAndStart("ListaUczniow.json")
val students = repo.getStudents().blockingGet()
val students = runBlocking { repo.getStudents() }
assertEquals(2, students.size)
}
}

View file

@ -2,8 +2,9 @@ package io.github.wulkanowy.sdk.mobile.repository
import io.github.wulkanowy.sdk.mobile.BaseLocalTest
import io.github.wulkanowy.sdk.mobile.exception.InvalidTokenException
import io.reactivex.observers.TestObserver
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import retrofit2.create
@ -14,7 +15,7 @@ class RoutingRulesRepositoryTest : BaseLocalTest() {
server.enqueueAndStart("RoutingRules.txt")
val repo = RoutingRulesRepository(getRetrofit().create())
val route = repo.getRouteByToken("KA2000").blockingGet()
val route = runBlocking { repo.getRouteByToken("KA2000") }
assertEquals("https://uonetplus-komunikacja-test.mcuw.katowice.eu", route)
}
@ -24,11 +25,12 @@ class RoutingRulesRepositoryTest : BaseLocalTest() {
server.enqueueAndStart("RoutingRules.txt")
val repo = RoutingRulesRepository(getRetrofit().create())
val route = repo.getRouteByToken("ERR00000")
val routeObserver = TestObserver<String>()
route.subscribe(routeObserver)
routeObserver.assertNotComplete()
routeObserver.assertError(InvalidTokenException::class.java)
try {
runBlocking { repo.getRouteByToken("ERR00000") }
} catch (e: Throwable) {
assertTrue(e is InvalidTokenException)
}
}
@Test
@ -36,10 +38,12 @@ class RoutingRulesRepositoryTest : BaseLocalTest() {
server.enqueueAndStart("RoutingRules.txt")
val repo = RoutingRulesRepository(getRetrofit().create())
val route = repo.getRouteByToken("ER")
val routeObserver = TestObserver<String>()
route.subscribe(routeObserver)
routeObserver.assertNotComplete()
routeObserver.assertError(InvalidTokenException::class.java)
// TODO: fix assert to run event if no exception thrown
try {
runBlocking { repo.getRouteByToken("ER") }
} catch (e: Throwable) {
assertTrue(e is InvalidTokenException)
}
}
}

View file

@ -2,6 +2,7 @@ package io.github.wulkanowy.sdk.mobile.timetable
import io.github.wulkanowy.sdk.mobile.BaseLocalTest
import io.github.wulkanowy.sdk.mobile.repository.MobileRepository
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Test
import org.threeten.bp.LocalDate.of
@ -15,7 +16,7 @@ class TimetableTest : BaseLocalTest() {
fun getTimetable() {
server.enqueueAndStart("PlanLekcji.json")
val items = timetable.getTimetable(of(2020, 1, 10), of(2020, 2, 11), 1, 2, 3).blockingGet()
val items = runBlocking { timetable.getTimetable(of(2020, 1, 10), of(2020, 2, 11), 1, 2, 3) }
assertEquals(5, items.size)
}

View file

@ -181,8 +181,8 @@ class Sdk {
}
fun getStudentsFromMobileApi(token: String, pin: String, symbol: String, firebaseToken: String, apiKey: String = ""): Single<List<Student>> {
return mobile.getCertificate(token, pin, symbol, buildTag, androidVersion, firebaseToken)
.flatMap { mobile.getStudents(it, apiKey) }
return rxSingle { mobile.getCertificate(token, pin, symbol, buildTag, androidVersion, firebaseToken) }
.flatMap { rxSingle { mobile.getStudents(it, apiKey) } }
.map { it.mapStudents(symbol) }
}
@ -227,16 +227,14 @@ class Sdk {
fun getSemesters(now: LocalDate = LocalDate.now()): Single<List<Semester>> {
return when (mode) {
Mode.HYBRID, Mode.SCRAPPER -> rxSingle { scrapper.getSemesters() }.compose(ScrapperExceptionTransformer()).map { it.mapSemesters() }
Mode.API -> mobile.getStudents().map { it.mapSemesters(studentId, now) }
Mode.API -> rxSingle { mobile.getStudents().mapSemesters(studentId, now) }
}
}
fun getAttendance(startDate: LocalDate, endDate: LocalDate, semesterId: Int): Single<List<Attendance>> {
return when (mode) {
Mode.SCRAPPER -> rxSingle { scrapper.getAttendance(startDate, endDate) }.compose(ScrapperExceptionTransformer()).map { it.mapAttendance() }
Mode.HYBRID, Mode.API -> mobile.getDictionaries().flatMap { dict ->
mobile.getAttendance(startDate, endDate, semesterId).map { it.mapAttendance(dict) }
}
Mode.HYBRID, Mode.API -> rxSingle { mobile.getAttendance(startDate, endDate, semesterId).mapAttendance(mobile.getDictionaries()) }
}
}
@ -257,43 +255,35 @@ class Sdk {
fun getSubjects(): Single<List<Subject>> {
return when (mode) {
Mode.HYBRID, Mode.SCRAPPER -> rxSingle { scrapper.getSubjects() }.compose(ScrapperExceptionTransformer()).map { it.mapSubjects() }
Mode.API -> mobile.getDictionaries().map { it.subjects }.map { it.mapSubjects() }
Mode.API -> rxSingle { mobile.getDictionaries().subjects.mapSubjects() }
}
}
fun getExams(start: LocalDate, end: LocalDate, semesterId: Int): Single<List<Exam>> {
return when (mode) {
Mode.SCRAPPER -> rxSingle { scrapper.getExams(start, end) }.compose(ScrapperExceptionTransformer()).map { it.mapExams() }
Mode.HYBRID, Mode.API -> mobile.getDictionaries().flatMap { dict ->
mobile.getExams(start, end, semesterId).map { it.mapExams(dict) }
}
Mode.HYBRID, Mode.API -> rxSingle { mobile.getExams(start, end, semesterId).mapExams(mobile.getDictionaries()) }
}
}
fun getGrades(semesterId: Int): Single<Pair<List<Grade>, List<GradeSummary>>> {
return when (mode) {
Mode.SCRAPPER -> rxSingle { scrapper.getGrades(semesterId) }.compose(ScrapperExceptionTransformer()).map { grades -> grades.mapGrades() }
Mode.HYBRID, Mode.API -> mobile.getDictionaries().flatMap { dict ->
mobile.getGrades(semesterId).map { grades -> grades.mapGrades(dict) }
}
Mode.HYBRID, Mode.API -> rxSingle { mobile.getGrades(semesterId).mapGrades(mobile.getDictionaries()) }
}
}
fun getGradesDetails(semesterId: Int): Single<List<Grade>> {
return when (mode) {
Mode.SCRAPPER -> rxSingle { scrapper.getGradesDetails(semesterId) }.compose(ScrapperExceptionTransformer()).map { grades -> grades.mapGradesDetails() }
Mode.HYBRID, Mode.API -> mobile.getDictionaries().flatMap { dict ->
mobile.getGradesDetails(semesterId).map { it.mapGradesDetails(dict) }
}
Mode.HYBRID, Mode.API -> rxSingle { mobile.getGradesDetails(semesterId).mapGradesDetails(mobile.getDictionaries()) }
}
}
fun getGradesSummary(semesterId: Int): Single<List<GradeSummary>> {
return when (mode) {
Mode.SCRAPPER -> rxSingle { scrapper.getGradesSummary(semesterId) }.compose(ScrapperExceptionTransformer()).map { it.mapGradesSummary() }
Mode.HYBRID, Mode.API -> mobile.getDictionaries().flatMap { dict ->
mobile.getGradesSummary(semesterId).map { it.mapGradesSummary(dict) }
}
Mode.HYBRID, Mode.API -> rxSingle { mobile.getGradesSummary(semesterId).mapGradesSummary(mobile.getDictionaries()) }
}
}
@ -321,18 +311,14 @@ class Sdk {
fun getHomework(start: LocalDate, end: LocalDate, semesterId: Int = 0): Single<List<Homework>> {
return when (mode) {
Mode.SCRAPPER -> rxSingle { scrapper.getHomework(start, end) }.compose(ScrapperExceptionTransformer()).map { it.mapHomework() }
Mode.HYBRID, Mode.API -> mobile.getDictionaries().flatMap { dict ->
mobile.getHomework(start, end, semesterId).map { it.mapHomework(dict) }
}
Mode.HYBRID, Mode.API -> rxSingle { mobile.getHomework(start, end, semesterId).mapHomework(mobile.getDictionaries()) }
}
}
fun getNotes(semesterId: Int): Single<List<Note>> {
return when (mode) {
Mode.SCRAPPER -> rxSingle { scrapper.getNotes() }.compose(ScrapperExceptionTransformer()).map { it.mapNotes() }
Mode.HYBRID, Mode.API -> mobile.getDictionaries().flatMap { dict ->
mobile.getNotes(semesterId).map { it.mapNotes(dict) }
}
Mode.HYBRID, Mode.API -> rxSingle { mobile.getNotes(semesterId).mapNotes(mobile.getDictionaries()) }
}
}
@ -360,9 +346,7 @@ class Sdk {
fun getTeachers(semesterId: Int): Single<List<Teacher>> {
return when (mode) {
Mode.SCRAPPER -> rxSingle { scrapper.getTeachers() }.compose(ScrapperExceptionTransformer()).map { it.mapTeachers() }
Mode.HYBRID, Mode.API -> mobile.getDictionaries().flatMap { dict ->
mobile.getTeachers(studentId, semesterId).map { it.mapTeachers(dict) }
}
Mode.HYBRID, Mode.API -> rxSingle { mobile.getTeachers(studentId, semesterId).mapTeachers(mobile.getDictionaries()) }
}
}
@ -383,14 +367,14 @@ class Sdk {
fun getReportingUnits(): Single<List<ReportingUnit>> {
return when (mode) {
Mode.HYBRID, Mode.SCRAPPER -> rxSingle { scrapper.getReportingUnits() }.compose(ScrapperExceptionTransformer()).map { it.mapReportingUnits() }
Mode.API -> mobile.getStudents().map { it.mapReportingUnits(studentId) }
Mode.API -> rxSingle { mobile.getStudents().mapReportingUnits(studentId) }
}
}
fun getRecipients(unitId: Int, role: Int = 2): Single<List<Recipient>> {
return when (mode) {
Mode.HYBRID, Mode.SCRAPPER -> rxSingle { scrapper.getRecipients(unitId, role) }.compose(ScrapperExceptionTransformer()).map { it.mapRecipients() }
Mode.API -> mobile.getDictionaries().map { it.teachers }.map { it.mapRecipients(unitId) }
Mode.API -> rxSingle { mobile.getDictionaries().teachers.mapRecipients(unitId) }
}
}
@ -405,27 +389,21 @@ class Sdk {
fun getReceivedMessages(start: LocalDateTime, end: LocalDateTime): Single<List<Message>> {
return when (mode) {
Mode.HYBRID, Mode.SCRAPPER -> rxSingle { scrapper.getReceivedMessages() }.compose(ScrapperExceptionTransformer()).map { it.mapMessages() } // TODO
Mode.API -> mobile.getDictionaries().flatMap { dict ->
mobile.getMessages(start, end).map { it.mapMessages(dict) }
}
Mode.API -> rxSingle { mobile.getMessages(start, end).mapMessages(mobile.getDictionaries()) }
}
}
fun getSentMessages(start: LocalDateTime, end: LocalDateTime): Single<List<Message>> {
return when (mode) {
Mode.HYBRID, Mode.SCRAPPER -> rxSingle { scrapper.getSentMessages() }.compose(ScrapperExceptionTransformer()).map { it.mapMessages() }
Mode.API -> mobile.getDictionaries().flatMap { dict ->
mobile.getMessagesSent(start, end).map { it.mapMessages(dict) }
}
Mode.API -> rxSingle { mobile.getMessagesSent(start, end).mapMessages(mobile.getDictionaries()) }
}
}
fun getDeletedMessages(start: LocalDateTime, end: LocalDateTime): Single<List<Message>> {
return when (mode) {
Mode.HYBRID, Mode.SCRAPPER -> rxSingle { scrapper.getDeletedMessages() }.compose(ScrapperExceptionTransformer()).map { it.mapMessages() }
Mode.API -> mobile.getDictionaries().flatMap { dict ->
mobile.getMessagesDeleted(start, end).map { it.mapMessages(dict) }
}
Mode.API -> rxSingle { mobile.getMessagesDeleted(start, end).mapMessages(mobile.getDictionaries()) }
}
}
@ -439,11 +417,13 @@ class Sdk {
fun getMessageDetails(messageId: Int, folderId: Int, read: Boolean = false, id: Int? = null): Single<MessageDetails> {
return when (mode) {
Mode.HYBRID, Mode.SCRAPPER -> rxSingle { scrapper.getMessageDetails(messageId, folderId, read, id) }.compose(ScrapperExceptionTransformer()).map { it.mapScrapperMessage() }
Mode.API -> mobile.changeMessageStatus(messageId, when (folderId) {
Mode.API -> rxSingle {
mobile.changeMessageStatus(messageId, when (folderId) {
1 -> "Odebrane"
2 -> "Wysłane"
else -> "Usunięte"
}, "Widoczna").map { MessageDetails("", emptyList()) }
}, "Widoczna").let { MessageDetails("", emptyList()) }
}
}
}
@ -452,7 +432,7 @@ class Sdk {
Mode.HYBRID, Mode.SCRAPPER -> rxSingle { scrapper.sendMessage(subject, content, recipients.mapFromRecipientsToScraper()) }
.compose(ScrapperExceptionTransformer())
.map { it.mapSentMessage() }
Mode.API -> mobile.sendMessage(subject, content, recipients.mapFromRecipientsToMobile()).map { it.mapSentMessage(loginId) }
Mode.API -> rxSingle { mobile.sendMessage(subject, content, recipients.mapFromRecipientsToMobile()).mapSentMessage(loginId) }
}
}
@ -460,11 +440,13 @@ class Sdk {
return when (mode) {
Mode.SCRAPPER -> rxSingle { scrapper.deleteMessages(messages) }.compose(ScrapperExceptionTransformer())
Mode.HYBRID, Mode.API -> Completable.mergeDelayError(messages.map { (messageId, folderId) ->
rxSingle {
mobile.changeMessageStatus(messageId, when (folderId) {
1 -> "Odebrane"
2 -> "Wysłane"
else -> "Usunięte"
}, "Usunieta").ignoreElement()
}, "Usunieta")
}.ignoreElement()
}).toSingleDefault(true)
}
}
@ -472,9 +454,7 @@ class Sdk {
fun getTimetable(start: LocalDate, end: LocalDate): Single<List<Timetable>> {
return when (mode) {
Mode.SCRAPPER -> rxSingle { scrapper.getTimetable(start, end) }.compose(ScrapperExceptionTransformer()).map { it.mapTimetable() }
Mode.HYBRID, Mode.API -> mobile.getDictionaries().flatMap { dict ->
mobile.getTimetable(start, end, 0).map { it.mapTimetable(dict) }
}
Mode.HYBRID, Mode.API -> rxSingle { mobile.getTimetable(start, end, 0).mapTimetable(mobile.getDictionaries()) }
}
}

View file

@ -9,7 +9,7 @@ import org.threeten.bp.format.DateTimeFormatter.ofPattern
import java.sql.Timestamp
import java.util.Date
fun String.toLocalDateTime(format: String) = LocalDateTime.parse(this, ofPattern(format))
fun String.toLocalDateTime(format: String): LocalDateTime = LocalDateTime.parse(this, ofPattern(format))
fun Long.toLocalDate(): LocalDate = Instant
.ofEpochMilli(this * 1000L)