Split project to mobile and sdk modules

This commit is contained in:
Mikołaj Pich 2019-11-14 13:36:46 +01:00
parent d75cbdaf61
commit 79ad6d7eb3
No known key found for this signature in database
GPG key ID: F62B26E36D4C4BAA
78 changed files with 589 additions and 318 deletions

View file

@ -6,6 +6,13 @@ allprojects {
}
}
subprojects {
version = '0.1.0'
ext {
okhttp3 = "3.12.5"
retrofit = "2.6.2"
threetenbp = "1.4.0"
}
subprojects {
version = "0.1.0-SNAPSHOT"
group = "io.github.wulkanowy"
}

60
mobile/build.gradle Normal file
View file

@ -0,0 +1,60 @@
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.50'
id 'jacoco'
}
sourceCompatibility = 1.8
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "io.github.wulkanowy:api:02e3190"
implementation "io.github.wulkanowy:uonet-request-signer:6d7aebf0e9"
compileOnly "org.threeten:threetenbp:$threetenbp:no-tzdb"
testImplementation "org.threeten:threetenbp:$threetenbp"
implementation 'com.google.code.gson:gson:2.8.6'
implementation "com.squareup.retrofit2:retrofit:$retrofit"
implementation "com.squareup.retrofit2:converter-gson:$retrofit"
implementation "com.squareup.retrofit2:converter-scalars:$retrofit"
implementation "com.squareup.retrofit2:retrofit:$retrofit"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp3"
testImplementation "com.squareup.okhttp3:mockwebserver:$okhttp3"
testImplementation "junit:junit:4.12"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
jacocoTestReport {
reports {
xml.enabled true
}
}
test {
testLogging.showStandardStreams = true
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk
package io.github.wulkanowy.sdk.mobile
import com.google.gson.annotations.SerializedName
import java.time.Instant.now

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk
package io.github.wulkanowy.sdk.mobile
import com.google.gson.annotations.SerializedName

View file

@ -0,0 +1,194 @@
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.grades.GradesSummaryResponse
import io.github.wulkanowy.sdk.mobile.homework.Homework
import io.github.wulkanowy.sdk.mobile.messages.Message
import io.github.wulkanowy.sdk.mobile.notes.Note
import io.github.wulkanowy.sdk.mobile.register.Student
import io.github.wulkanowy.sdk.mobile.repository.RegisterRepository
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
import org.threeten.bp.LocalDateTime
class Mobile {
var apiKey = ""
var pin = ""
var token = ""
var apiBaseUrl = ""
set(value) {
field = value
resettableManager.reset()
}
var deviceName = "Wulkanowy SDK"
var certKey = ""
set(value) {
field = value
resettableManager.reset()
}
var certificate = ""
set(value) {
field = value
resettableManager.reset()
}
var privateKey = ""
set(value) {
field = value
resettableManager.reset()
}
var classId = 0
set(value) {
field = value
}
var studentId = 0
set(value) {
field = value
}
var schoolSymbol = ""
set(value) {
field = value
}
var loginId = 0
var diaryId = 0
set(value) {
field = value
}
var symbol = ""
set(value) {
field = value
}
var logLevel = HttpLoggingInterceptor.Level.BASIC
set(value) {
field = value
}
private val resettableManager = resettableManager()
private val serviceManager by resettableLazy(resettableManager) {
RepositoryManager(logLevel, privateKey, certKey, interceptors, apiBaseUrl, schoolSymbol)
}
private val routes by resettableLazy(resettableManager) {
serviceManager.getRoutesRepository()
}
private val mobile by resettableLazy(resettableManager) {
serviceManager.getMobileRepository()
}
fun getRegisterRepo(host: String, symbol: String): RegisterRepository {
return serviceManager.getRegisterRepository(host, symbol)
}
private lateinit var dictionaries: Dictionaries
fun getDictionaries(): Single<Dictionaries> {
if (::dictionaries.isInitialized) return Single.just(dictionaries)
return mobile.getDictionaries(0, 0, 0).map {
it.apply { dictionaries = this }
}
}
private val interceptors: MutableList<Pair<Interceptor, Boolean>> = mutableListOf()
fun setInterceptor(interceptor: Interceptor, network: Boolean = false, index: Int = -1) {
interceptors.add(interceptor to network)
}
fun getApiStudents(token: String, pin: String, symbol: String): Single<List<Student>> {
return routes.getRouteByToken(token).flatMap {
this@Mobile.apiBaseUrl = it
this@Mobile.symbol = symbol
getRegisterRepo(apiBaseUrl, symbol).getCertificate(token, pin, deviceName)
}.flatMap { certificateResponse ->
if (certificateResponse.isError) throw RuntimeException(certificateResponse.message)
this@Mobile.certKey = certificateResponse.tokenCert!!.certificateKey
this@Mobile.privateKey = getPrivateKeyFromCert(apiKey, certificateResponse.tokenCert.certificatePfx)
getRegisterRepo(apiBaseUrl, this@Mobile.symbol).getPupils().map { students ->
students.map {
it.copy().apply {
privateKey = this@Mobile.privateKey
ssl = certificateResponse.tokenCert.apiEndpoint.startsWith("https")
certificateKey = certificateResponse.tokenCert.certificateKey
apiHost = certificateResponse.tokenCert.apiEndpoint.removeSuffix("/")
}
}
}
}
}
fun getPupils(): Single<List<Student>> {
return getRegisterRepo(apiBaseUrl.replace("/$symbol", ""), symbol).getPupils()
}
fun getAttendance(start: LocalDate, end: LocalDate, classId: Int, classificationPeriodId: Int, studentId: Int): Single<List<Attendance>> {
return mobile.getAttendance(start, end, classId, classificationPeriodId, studentId)
}
fun getExams(start: LocalDate, end: LocalDate, classId: Int, classificationPeriodId: Int, studentId: Int): Single<List<Exam>> {
return mobile.getExams(start, end, classId, classificationPeriodId, studentId)
}
fun getGrades(classId: Int, classificationPeriodId: Int, studentId: Int): Single<List<Grade>> {
return mobile.getGrades(classId, classificationPeriodId, studentId)
}
fun getGradesSummary(classId: Int, classificationPeriodId: Int, studentId: Int): Single<GradesSummaryResponse> {
return mobile.getGradesSummary(classId, classificationPeriodId, studentId)
}
fun getHomework(start: LocalDate, end: LocalDate, classId: Int, classificationPeriodId: Int, studentId: Int): Single<List<Homework>> {
return mobile.getHomework(start, end, classId, classificationPeriodId, studentId)
}
fun getNotes(classificationPeriodId: Int, studentId: Int): Single<List<Note>> {
return mobile.getNotes(classificationPeriodId, studentId)
}
fun getTeachers(studentId: Int, semesterId: Int): Single<List<Teacher>> {
return mobile.getTeachers(studentId, semesterId)
}
fun getMessages(start: LocalDateTime, end: LocalDateTime, loginId: Int, studentId: Int): Single<List<Message>> {
return mobile.getMessages(start, end, loginId, studentId)
}
fun getMessagesSent(start: LocalDateTime, end: LocalDateTime, loginId: Int, studentId: Int): Single<List<Message>> {
return mobile.getMessagesSent(start, end, loginId, studentId)
}
fun getMessagesDeleted(start: LocalDateTime, end: LocalDateTime, loginId: Int, studentId: Int): Single<List<Message>> {
return mobile.getMessagesDeleted(start, end, loginId, studentId)
}
fun changeMessageStatus(messageId: Int, folder: String, status: String, loginId: Int, studentId: Int): Single<String> {
return mobile.changeMessageStatus(messageId, folder, status, loginId, studentId)
}
fun getTimetable(start: LocalDate, end: LocalDate, classId: Int, classificationPeriodId: Int, studentId: Int): Single<List<Lesson>> {
return mobile.getTimetable(start, end, classId, classificationPeriodId, studentId)
}
}

View file

@ -0,0 +1,56 @@
package io.github.wulkanowy.sdk.mobile
import java.util.LinkedList
import kotlin.reflect.KProperty
/**
* see https://stackoverflow.com/a/35757638/6695449
*/
class ResettableLazyManager {
// we synchronize to make sure the timing of a reset() call and new inits do not collide
val managedDelegates = LinkedList<Resettable>()
fun register(managed: Resettable) {
synchronized(managedDelegates) {
managedDelegates.add(managed)
}
}
fun reset() {
synchronized(managedDelegates) {
managedDelegates.forEach { it.reset() }
managedDelegates.clear()
}
}
}
interface Resettable {
fun reset()
}
class ResettableLazy<PROPTYPE>(val manager: ResettableLazyManager, val init: () -> PROPTYPE) : Resettable {
@Volatile
var lazyHolder = makeInitBlock()
operator fun getValue(thisRef: Any?, property: KProperty<*>): PROPTYPE {
return lazyHolder.value
}
override fun reset() {
lazyHolder = makeInitBlock()
}
fun makeInitBlock(): Lazy<PROPTYPE> {
return lazy {
manager.register(this)
init()
}
}
}
fun <PROPTYPE> resettableLazy(manager: ResettableLazyManager, init: () -> PROPTYPE): ResettableLazy<PROPTYPE> {
return ResettableLazy(manager, init)
}
fun resettableManager(): ResettableLazyManager = ResettableLazyManager()

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.attendance
package io.github.wulkanowy.sdk.mobile.attendance
import com.google.gson.annotations.SerializedName

View file

@ -1,7 +1,7 @@
package io.github.wulkanowy.sdk.attendance
package io.github.wulkanowy.sdk.mobile.attendance
import com.google.gson.annotations.SerializedName
import io.github.wulkanowy.sdk.ApiRequest
import io.github.wulkanowy.sdk.mobile.ApiRequest
data class AttendanceRequest(

View file

@ -1,6 +1,7 @@
package io.github.wulkanowy.sdk.attendance
package io.github.wulkanowy.sdk.mobile.attendance
import com.google.gson.annotations.SerializedName
import io.github.wulkanowy.sdk.mobile.attendance.Attendance
data class AttendanceResponse(

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.dictionaries
package io.github.wulkanowy.sdk.mobile.dictionaries
import com.google.gson.annotations.SerializedName

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.dictionaries
package io.github.wulkanowy.sdk.mobile.dictionaries
import com.google.gson.annotations.SerializedName

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.dictionaries
package io.github.wulkanowy.sdk.mobile.dictionaries
import com.google.gson.annotations.SerializedName

View file

@ -1,7 +1,7 @@
package io.github.wulkanowy.sdk.dictionaries
package io.github.wulkanowy.sdk.mobile.dictionaries
import com.google.gson.annotations.SerializedName
import io.github.wulkanowy.sdk.ApiRequest
import io.github.wulkanowy.sdk.mobile.ApiRequest
data class DictionariesRequest(

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.dictionaries
package io.github.wulkanowy.sdk.mobile.dictionaries
import com.google.gson.annotations.SerializedName

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.dictionaries
package io.github.wulkanowy.sdk.mobile.dictionaries
import com.google.gson.annotations.SerializedName

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.dictionaries
package io.github.wulkanowy.sdk.mobile.dictionaries
import com.google.gson.annotations.SerializedName

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.dictionaries
package io.github.wulkanowy.sdk.mobile.dictionaries
import com.google.gson.annotations.SerializedName

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.dictionaries
package io.github.wulkanowy.sdk.mobile.dictionaries
import com.google.gson.annotations.SerializedName

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.dictionaries
package io.github.wulkanowy.sdk.mobile.dictionaries
import com.google.gson.annotations.SerializedName

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.exams
package io.github.wulkanowy.sdk.mobile.exams
import com.google.gson.annotations.SerializedName

View file

@ -1,7 +1,7 @@
package io.github.wulkanowy.sdk.exams
package io.github.wulkanowy.sdk.mobile.exams
import com.google.gson.annotations.SerializedName
import io.github.wulkanowy.sdk.ApiRequest
import io.github.wulkanowy.sdk.mobile.ApiRequest
data class ExamsRequest(

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.grades
package io.github.wulkanowy.sdk.mobile.grades
import com.google.gson.annotations.SerializedName

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.grades
package io.github.wulkanowy.sdk.mobile.grades
import com.google.gson.annotations.SerializedName

View file

@ -1,7 +1,7 @@
package io.github.wulkanowy.sdk.grades
package io.github.wulkanowy.sdk.mobile.grades
import com.google.gson.annotations.SerializedName
import io.github.wulkanowy.sdk.ApiRequest
import io.github.wulkanowy.sdk.mobile.ApiRequest
data class GradesRequest(

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.grades
package io.github.wulkanowy.sdk.mobile.grades
import com.google.gson.annotations.SerializedName

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.homework
package io.github.wulkanowy.sdk.mobile.homework
import com.google.gson.annotations.SerializedName

View file

@ -1,7 +1,7 @@
package io.github.wulkanowy.sdk.homework
package io.github.wulkanowy.sdk.mobile.homework
import com.google.gson.annotations.SerializedName
import io.github.wulkanowy.sdk.ApiRequest
import io.github.wulkanowy.sdk.mobile.ApiRequest
data class HomeworkRequest(

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.interceptor
package io.github.wulkanowy.sdk.mobile.interceptor
import io.github.wulkanowy.signer.signContent
import okhttp3.Interceptor
@ -18,7 +18,6 @@ class SignInterceptor(
request.header("User-Agent", "MobileUserAgent")
if (privateKey.isNotBlank()) {
val signature = Buffer().run {
original.body()?.writeTo(this)
signContent(privateKey, readString(Charset.defaultCharset()))

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.messages
package io.github.wulkanowy.sdk.mobile.messages
import com.google.gson.annotations.SerializedName

View file

@ -1,7 +1,7 @@
package io.github.wulkanowy.sdk.messages
package io.github.wulkanowy.sdk.mobile.messages
import com.google.gson.annotations.SerializedName
import io.github.wulkanowy.sdk.ApiRequest
import io.github.wulkanowy.sdk.mobile.ApiRequest
data class MessageStatusChangeRequest(

View file

@ -1,7 +1,7 @@
package io.github.wulkanowy.sdk.messages
package io.github.wulkanowy.sdk.mobile.messages
import com.google.gson.annotations.SerializedName
import io.github.wulkanowy.sdk.ApiRequest
import io.github.wulkanowy.sdk.mobile.ApiRequest
data class MessagesRequest(

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.messages
package io.github.wulkanowy.sdk.mobile.messages
import com.google.gson.annotations.SerializedName

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.notes
package io.github.wulkanowy.sdk.mobile.notes
import com.google.gson.annotations.SerializedName

View file

@ -1,7 +1,7 @@
package io.github.wulkanowy.sdk.notes
package io.github.wulkanowy.sdk.mobile.notes
import com.google.gson.annotations.SerializedName
import io.github.wulkanowy.sdk.ApiRequest
import io.github.wulkanowy.sdk.mobile.ApiRequest
data class NotesRequest(

View file

@ -1,7 +1,7 @@
package io.github.wulkanowy.sdk.register
package io.github.wulkanowy.sdk.mobile.register
import com.google.gson.annotations.SerializedName
import io.github.wulkanowy.sdk.ApiRequest
import io.github.wulkanowy.sdk.mobile.ApiRequest
import java.util.*
data class CertificateRequest(

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.register
package io.github.wulkanowy.sdk.mobile.register
import com.google.gson.annotations.SerializedName

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.register
package io.github.wulkanowy.sdk.mobile.register
import com.google.gson.annotations.SerializedName
@ -90,4 +90,9 @@ data class Student(
@SerializedName("LoginId")
val loginId: Int?
)
) {
var privateKey = ""
var certificateKey = ""
var apiHost = ""
var ssl = false
}

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.register
package io.github.wulkanowy.sdk.mobile.register
import com.google.gson.annotations.SerializedName

View file

@ -1,35 +1,40 @@
package io.github.wulkanowy.sdk.repository
package io.github.wulkanowy.sdk.mobile.repository
import io.github.wulkanowy.sdk.ApiRequest
import io.github.wulkanowy.sdk.ApiResponse
import io.github.wulkanowy.sdk.attendance.Attendance
import io.github.wulkanowy.sdk.attendance.AttendanceRequest
import io.github.wulkanowy.sdk.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.dictionaries.DictionariesRequest
import io.github.wulkanowy.sdk.exams.Exam
import io.github.wulkanowy.sdk.exams.ExamsRequest
import io.github.wulkanowy.sdk.grades.Grade
import io.github.wulkanowy.sdk.grades.GradesRequest
import io.github.wulkanowy.sdk.grades.GradesSummaryResponse
import io.github.wulkanowy.sdk.homework.Homework
import io.github.wulkanowy.sdk.homework.HomeworkRequest
import io.github.wulkanowy.sdk.messages.Message
import io.github.wulkanowy.sdk.messages.MessageStatusChangeRequest
import io.github.wulkanowy.sdk.messages.MessagesRequest
import io.github.wulkanowy.sdk.notes.Note
import io.github.wulkanowy.sdk.notes.NotesRequest
import io.github.wulkanowy.sdk.school.Teacher
import io.github.wulkanowy.sdk.school.TeachersRequest
import io.github.wulkanowy.sdk.service.MobileService
import io.github.wulkanowy.sdk.timetable.Lesson
import io.github.wulkanowy.sdk.timetable.TimetableRequest
import io.github.wulkanowy.sdk.toFormat
import io.github.wulkanowy.api.toFormat
import io.github.wulkanowy.sdk.mobile.ApiRequest
import io.github.wulkanowy.sdk.mobile.ApiResponse
import io.github.wulkanowy.sdk.mobile.attendance.Attendance
import io.github.wulkanowy.sdk.mobile.attendance.AttendanceRequest
import io.github.wulkanowy.sdk.mobile.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.mobile.dictionaries.DictionariesRequest
import io.github.wulkanowy.sdk.mobile.exams.Exam
import io.github.wulkanowy.sdk.mobile.exams.ExamsRequest
import io.github.wulkanowy.sdk.mobile.grades.Grade
import io.github.wulkanowy.sdk.mobile.grades.GradesRequest
import io.github.wulkanowy.sdk.mobile.grades.GradesSummaryResponse
import io.github.wulkanowy.sdk.mobile.homework.Homework
import io.github.wulkanowy.sdk.mobile.homework.HomeworkRequest
import io.github.wulkanowy.sdk.mobile.messages.Message
import io.github.wulkanowy.sdk.mobile.messages.MessageStatusChangeRequest
import io.github.wulkanowy.sdk.mobile.messages.MessagesRequest
import io.github.wulkanowy.sdk.mobile.notes.Note
import io.github.wulkanowy.sdk.mobile.notes.NotesRequest
import io.github.wulkanowy.sdk.mobile.school.Teacher
import io.github.wulkanowy.sdk.mobile.school.TeachersRequest
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.reactivex.Single
import org.threeten.bp.LocalDate
import org.threeten.bp.LocalDateTime
class MobileRepository(private val api: MobileService) {
// TODO move these to utils
private fun LocalDate.toFormat() = toFormat("yyyy-MM-dd")
private fun LocalDateTime.toFormat() = toFormat("yyyy-MM-dd")
fun logStart(): Single<ApiResponse<String>> = api.logAppStart(object : ApiRequest() {})
fun getDictionaries(userId: Int, classificationPeriodId: Int, classId: Int): Single<Dictionaries> {

View file

@ -1,10 +1,10 @@
package io.github.wulkanowy.sdk.repository
package io.github.wulkanowy.sdk.mobile.repository
import io.github.wulkanowy.sdk.ApiRequest
import io.github.wulkanowy.sdk.register.CertificateRequest
import io.github.wulkanowy.sdk.register.CertificateResponse
import io.github.wulkanowy.sdk.register.Student
import io.github.wulkanowy.sdk.service.RegisterService
import io.github.wulkanowy.sdk.mobile.ApiRequest
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) {

View file

@ -1,6 +1,6 @@
package io.github.wulkanowy.sdk.repository
package io.github.wulkanowy.sdk.mobile.repository
import io.github.wulkanowy.sdk.interceptor.SignInterceptor
import io.github.wulkanowy.sdk.mobile.interceptor.SignInterceptor
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor

View file

@ -1,6 +1,6 @@
package io.github.wulkanowy.sdk.repository
package io.github.wulkanowy.sdk.mobile.repository
import io.github.wulkanowy.sdk.service.RoutingRulesService
import io.github.wulkanowy.sdk.mobile.service.RoutingRulesService
import io.reactivex.Single
class RoutingRulesRepository(private val api: RoutingRulesService) {

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.school
package io.github.wulkanowy.sdk.mobile.school
import com.google.gson.annotations.SerializedName

View file

@ -1,7 +1,7 @@
package io.github.wulkanowy.sdk.school
package io.github.wulkanowy.sdk.mobile.school
import com.google.gson.annotations.SerializedName
import io.github.wulkanowy.sdk.ApiRequest
import io.github.wulkanowy.sdk.mobile.ApiRequest
class TeachersRequest(

View file

@ -1,6 +1,7 @@
package io.github.wulkanowy.sdk.school
package io.github.wulkanowy.sdk.mobile.school
import com.google.gson.annotations.SerializedName
import io.github.wulkanowy.sdk.mobile.school.Teacher
data class TeachersResponse(

View file

@ -1,27 +1,27 @@
package io.github.wulkanowy.sdk.service
package io.github.wulkanowy.sdk.mobile.service
import io.github.wulkanowy.sdk.ApiRequest
import io.github.wulkanowy.sdk.ApiResponse
import io.github.wulkanowy.sdk.attendance.AttendanceRequest
import io.github.wulkanowy.sdk.attendance.AttendanceResponse
import io.github.wulkanowy.sdk.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.dictionaries.DictionariesRequest
import io.github.wulkanowy.sdk.exams.Exam
import io.github.wulkanowy.sdk.exams.ExamsRequest
import io.github.wulkanowy.sdk.grades.Grade
import io.github.wulkanowy.sdk.grades.GradesRequest
import io.github.wulkanowy.sdk.grades.GradesSummaryResponse
import io.github.wulkanowy.sdk.homework.Homework
import io.github.wulkanowy.sdk.homework.HomeworkRequest
import io.github.wulkanowy.sdk.messages.Message
import io.github.wulkanowy.sdk.messages.MessageStatusChangeRequest
import io.github.wulkanowy.sdk.messages.MessagesRequest
import io.github.wulkanowy.sdk.notes.Note
import io.github.wulkanowy.sdk.notes.NotesRequest
import io.github.wulkanowy.sdk.school.TeachersRequest
import io.github.wulkanowy.sdk.school.TeachersResponse
import io.github.wulkanowy.sdk.timetable.Lesson
import io.github.wulkanowy.sdk.timetable.TimetableRequest
import io.github.wulkanowy.sdk.mobile.ApiRequest
import io.github.wulkanowy.sdk.mobile.ApiResponse
import io.github.wulkanowy.sdk.mobile.attendance.AttendanceRequest
import io.github.wulkanowy.sdk.mobile.attendance.AttendanceResponse
import io.github.wulkanowy.sdk.mobile.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.mobile.dictionaries.DictionariesRequest
import io.github.wulkanowy.sdk.mobile.exams.Exam
import io.github.wulkanowy.sdk.mobile.exams.ExamsRequest
import io.github.wulkanowy.sdk.mobile.grades.Grade
import io.github.wulkanowy.sdk.mobile.grades.GradesRequest
import io.github.wulkanowy.sdk.mobile.grades.GradesSummaryResponse
import io.github.wulkanowy.sdk.mobile.homework.Homework
import io.github.wulkanowy.sdk.mobile.homework.HomeworkRequest
import io.github.wulkanowy.sdk.mobile.messages.Message
import io.github.wulkanowy.sdk.mobile.messages.MessageStatusChangeRequest
import io.github.wulkanowy.sdk.mobile.messages.MessagesRequest
import io.github.wulkanowy.sdk.mobile.notes.Note
import io.github.wulkanowy.sdk.mobile.notes.NotesRequest
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

View file

@ -1,10 +1,10 @@
package io.github.wulkanowy.sdk.service
package io.github.wulkanowy.sdk.mobile.service
import io.github.wulkanowy.sdk.ApiRequest
import io.github.wulkanowy.sdk.ApiResponse
import io.github.wulkanowy.sdk.register.CertificateRequest
import io.github.wulkanowy.sdk.register.CertificateResponse
import io.github.wulkanowy.sdk.register.Student
import io.github.wulkanowy.sdk.mobile.ApiRequest
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

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.service
package io.github.wulkanowy.sdk.mobile.service
import io.reactivex.Single
import retrofit2.http.GET

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.timetable
package io.github.wulkanowy.sdk.mobile.timetable
import com.google.gson.annotations.SerializedName

View file

@ -1,7 +1,7 @@
package io.github.wulkanowy.sdk.timetable
package io.github.wulkanowy.sdk.mobile.timetable
import com.google.gson.annotations.SerializedName
import io.github.wulkanowy.sdk.ApiRequest
import io.github.wulkanowy.sdk.mobile.ApiRequest
data class TimetableRequest(

View file

@ -1,17 +1,17 @@
package io.github.wulkanowy.sdk
package io.github.wulkanowy.sdk.mobile
import io.github.wulkanowy.sdk.attendance.Attendance
import io.github.wulkanowy.sdk.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.exams.Exam
import io.github.wulkanowy.sdk.grades.Grade
import io.github.wulkanowy.sdk.homework.Homework
import io.github.wulkanowy.sdk.interceptor.SignInterceptor
import io.github.wulkanowy.sdk.notes.Note
import io.github.wulkanowy.sdk.register.CertificateResponse
import io.github.wulkanowy.sdk.register.Student
import io.github.wulkanowy.sdk.repository.MobileRepository
import io.github.wulkanowy.sdk.repository.RegisterRepository
import io.github.wulkanowy.sdk.timetable.Lesson
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
@ -43,14 +43,14 @@ 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()
.addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BASIC))
.addInterceptor(SignInterceptor(privateKey, certKey))
.build()
)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.client(OkHttpClient().newBuilder()
.addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BASIC))
.addInterceptor(SignInterceptor(privateKey, certKey))
.build()
)
}
@JvmStatic
@ -58,8 +58,8 @@ class UonetTest {
fun setUp() {
// RegisterRepository
val register = RegisterRepository(getRetrofitBuilder("", "")
.baseUrl("$HOST/$SYMBOL/mobile-api/Uczen.v3.UczenStart/")
.build().create()
.baseUrl("$HOST/$SYMBOL/mobile-api/Uczen.v3.UczenStart/")
.build().create()
)
val certificate = register.getCertificate(TOKEN, PIN, DEVICE_NAME)
@ -88,8 +88,8 @@ class UonetTest {
// MobileRepository
mobile = MobileRepository(getRetrofitBuilder(privateKey, certKey)
.baseUrl("$HOST/Default/${student.reportingUnitSymbol}/mobile-api/Uczen.v3.Uczen/")
.build().create()
.baseUrl("$HOST/Default/${student.reportingUnitSymbol}/mobile-api/Uczen.v3.Uczen/")
.build().create()
)
}
}

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.repository
package io.github.wulkanowy.sdk.mobile.repository
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
@ -35,12 +35,12 @@ class RoutingRulesRepositoryTest {
private fun getRetrofitBuilder(): Retrofit.Builder {
return Retrofit.Builder()
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.client(OkHttpClient().newBuilder()
.addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
.build()
)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.client(OkHttpClient().newBuilder()
.addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
.build()
)
}
}

View file

@ -4,33 +4,18 @@ plugins {
id 'jacoco'
}
group 'io.github.wulkanowy'
version '0.1.0-SNAPSHOT'
sourceCompatibility = 1.8
ext {
okhttp3 = "3.12.5"
retrofit = "2.6.2"
threetenbp = "1.4.0"
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation project(":mobile")
implementation "io.github.wulkanowy:api:02e3190"
implementation "io.github.wulkanowy:uonet-request-signer:6d7aebf0e9"
compileOnly "org.threeten:threetenbp:$threetenbp:no-tzdb"
testImplementation "org.threeten:threetenbp:$threetenbp"
implementation 'com.google.code.gson:gson:2.8.6'
implementation "com.squareup.retrofit2:retrofit:$retrofit"
implementation "com.squareup.retrofit2:converter-gson:$retrofit"
implementation "com.squareup.retrofit2:converter-scalars:$retrofit"
implementation "com.squareup.retrofit2:retrofit:$retrofit"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit"
implementation "io.reactivex.rxjava2:rxjava:2.2.14"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp3"
testImplementation "com.squareup.okhttp3:mockwebserver:$okhttp3"

View file

@ -2,37 +2,10 @@ package io.github.wulkanowy.sdk
import io.github.wulkanowy.api.Api
import io.github.wulkanowy.api.attendance.Absent
import io.github.wulkanowy.api.resettableLazy
import io.github.wulkanowy.api.resettableManager
import io.github.wulkanowy.sdk.attendance.mapAttendance
import io.github.wulkanowy.sdk.attendance.mapAttendanceSummary
import io.github.wulkanowy.sdk.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.dictionaries.mapSubjects
import io.github.wulkanowy.sdk.exams.mapExams
import io.github.wulkanowy.sdk.exception.FeatureNotAvailableException
import io.github.wulkanowy.sdk.grades.mapGradePointsStatistics
import io.github.wulkanowy.sdk.grades.mapGradeStatistics
import io.github.wulkanowy.sdk.grades.mapGrades
import io.github.wulkanowy.sdk.grades.mapGradesSummary
import io.github.wulkanowy.sdk.homepage.mapLuckyNumbers
import io.github.wulkanowy.sdk.homework.mapHomework
import io.github.wulkanowy.sdk.messages.*
import io.github.wulkanowy.sdk.mobile.mapDevices
import io.github.wulkanowy.sdk.mobile.mapToken
import io.github.wulkanowy.sdk.notes.mapNotes
import io.github.wulkanowy.sdk.mapper.*
import io.github.wulkanowy.sdk.mobile.Mobile
import io.github.wulkanowy.sdk.pojo.*
import io.github.wulkanowy.sdk.pojo.Message
import io.github.wulkanowy.sdk.pojo.Recipient
import io.github.wulkanowy.sdk.register.mapSemesters
import io.github.wulkanowy.sdk.register.mapStudents
import io.github.wulkanowy.sdk.repository.RegisterRepository
import io.github.wulkanowy.sdk.repository.RepositoryManager
import io.github.wulkanowy.sdk.school.mapSchool
import io.github.wulkanowy.sdk.school.mapTeachers
import io.github.wulkanowy.sdk.student.mapStudent
import io.github.wulkanowy.sdk.timetable.mapCompletedLessons
import io.github.wulkanowy.sdk.timetable.mapTimetable
import io.github.wulkanowy.signer.getPrivateKeyFromCert
import io.reactivex.Completable
import io.reactivex.Maybe
import io.reactivex.Observable
@ -59,38 +32,60 @@ class Sdk {
ADFSLightScoped
}
private val mobile = Mobile()
private val scrapper = Api().apply {
useNewStudent = true
}
var mode = Mode.HYBRID
var apiKey = ""
set(value) {
field = value
mobile.apiKey = value
}
var pin = ""
set(value) {
field = value
mobile.pin = value
}
var token = ""
set(value) {
field = value
mobile.token = value
}
var apiBaseUrl = ""
set(value) {
field = value
resettableManager.reset()
mobile.apiBaseUrl = value
}
var deviceName = "Wulkanowy SDK"
set(value) {
field = value
mobile.deviceName = value
}
var certKey = ""
set(value) {
field = value
resettableManager.reset()
mobile.certKey = value
}
var certificate = ""
set(value) {
field = value
resettableManager.reset()
mobile.certificate = value
}
var privateKey = ""
set(value) {
field = value
resettableManager.reset()
mobile.privateKey = privateKey
}
var ssl = true
@ -120,31 +115,41 @@ class Sdk {
set(value) {
field = value
scrapper.schoolSymbol = value
mobile.schoolSymbol = value
}
var classId = 0
set(value) {
field = value
scrapper.classId = value
mobile.classId = value
}
var studentId = 0
set(value) {
field = value
scrapper.studentId = value
mobile.studentId = value
}
var loginId = 0
set(value) {
field = value
mobile.loginId = value
}
var diaryId = 0
set(value) {
field = value
scrapper.diaryId = value
mobile.diaryId = value
}
var symbol = ""
set(value) {
field = value
scrapper.symbol = value
mobile.symbol = value
}
var loginType = ScrapperLoginType.AUTO
@ -157,6 +162,7 @@ class Sdk {
set(value) {
field = value
scrapper.logLevel = value
mobile.logLevel = value
}
var androidVersion = ""
@ -171,48 +177,17 @@ class Sdk {
scrapper.buildTag = value
}
private val scrapper = Api().apply {
useNewStudent = true
}
private val resettableManager = resettableManager()
private val serviceManager by resettableLazy(resettableManager) {
RepositoryManager(logLevel, privateKey, certKey, interceptors, apiBaseUrl, schoolSymbol)
}
private val routes by resettableLazy(resettableManager) {
serviceManager.getRoutesRepository()
}
private val mobile by resettableLazy(resettableManager) {
serviceManager.getMobileRepository()
}
private fun getRegisterRepo(host: String, symbol: String): RegisterRepository {
return serviceManager.getRegisterRepository(host, symbol)
}
private lateinit var dictionaries: Dictionaries
private fun getDictionaries(): Single<Dictionaries> {
if (::dictionaries.isInitialized) return Single.just(dictionaries)
return mobile.getDictionaries(0, 0, 0).map {
it.apply { dictionaries = this }
}
}
private val interceptors: MutableList<Pair<Interceptor, Boolean>> = mutableListOf()
fun setInterceptor(interceptor: Interceptor, network: Boolean = false, index: Int = -1) {
scrapper.setInterceptor(interceptor, network, index)
mobile.setInterceptor(interceptor, network, index)
interceptors.add(interceptor to network)
}
fun getStudents(): Single<List<Student>> {
return when (mode) {
Mode.API -> getApiStudents(token, pin, symbol)
Mode.API -> mobile.getApiStudents(token, pin, symbol).map { it.mapStudents() }
Mode.SCRAPPER -> {
scrapper.run {
ssl = this@Sdk.ssl
@ -238,9 +213,9 @@ class Sdk {
loginType = it.loginType
}
scrapper.getToken().compose(ScrapperExceptionTransformer()).flatMap {
getApiStudents(it.token, it.pin, it.symbol)
mobile.getApiStudents(it.token, it.pin, it.symbol)
}.map { apiStudents ->
apiStudents.map { apiStudent ->
apiStudents.mapStudents().map { apiStudent ->
apiStudent.copy(
loginMode = Mode.HYBRID,
scrapperHost = scrapperHost,
@ -257,30 +232,17 @@ class Sdk {
}
}
private fun getApiStudents(token: String, pin: String, symbol: String): Single<List<Student>> {
return routes.getRouteByToken(token).flatMap {
this@Sdk.apiBaseUrl = it
this@Sdk.symbol = symbol
getRegisterRepo(apiBaseUrl, symbol).getCertificate(token, pin, deviceName)
}.flatMap { certificateResponse ->
if (certificateResponse.isError) throw RuntimeException(certificateResponse.message)
this@Sdk.certKey = certificateResponse.tokenCert!!.certificateKey
this@Sdk.privateKey = getPrivateKeyFromCert(apiKey, certificateResponse.tokenCert.certificatePfx)
getRegisterRepo(apiBaseUrl, this@Sdk.symbol).getPupils().map { it.mapStudents(symbol, certificateResponse, this@Sdk.privateKey) }
}
}
fun getSemesters(): Single<List<Semester>> {
return when (mode) {
Mode.HYBRID, Mode.SCRAPPER -> scrapper.getSemesters().compose(ScrapperExceptionTransformer()).map { it.mapSemesters() }
Mode.API -> getRegisterRepo(apiBaseUrl.replace("/$symbol", ""), symbol).getPupils().map { it.mapSemesters(studentId) }
Mode.API -> mobile.getRegisterRepo(apiBaseUrl.replace("/$symbol", ""), symbol).getPupils().map { it.mapSemesters(studentId) }
}
}
fun getAttendance(startDate: LocalDate, endDate: LocalDate, semesterId: Int): Single<List<Attendance>> {
return when (mode) {
Mode.SCRAPPER -> scrapper.getAttendance(startDate, endDate).compose(ScrapperExceptionTransformer()).map { it.mapAttendance() }
Mode.HYBRID, Mode.API -> getDictionaries().flatMap { dict ->
Mode.HYBRID, Mode.API -> mobile.getDictionaries().flatMap { dict ->
mobile.getAttendance(startDate, endDate, classId, semesterId, studentId).map { it.mapAttendance(dict) }
}
}
@ -303,14 +265,14 @@ class Sdk {
fun getSubjects(): Single<List<Subject>> {
return when (mode) {
Mode.SCRAPPER -> scrapper.getSubjects().compose(ScrapperExceptionTransformer()).map { it.mapSubjects() }
Mode.HYBRID, Mode.API -> getDictionaries().map { it.subjects }.map { it.mapSubjects() }
Mode.HYBRID, Mode.API -> mobile.getDictionaries().map { it.subjects }.map { it.mapSubjects() }
}
}
fun getExams(start: LocalDate, end: LocalDate, semesterId: Int): Single<List<Exam>> {
return when (mode) {
Mode.SCRAPPER -> scrapper.getExams(start, end).compose(ScrapperExceptionTransformer()).map { it.mapExams() }
Mode.HYBRID, Mode.API -> getDictionaries().flatMap { dict ->
Mode.HYBRID, Mode.API -> mobile.getDictionaries().flatMap { dict ->
mobile.getExams(start, end, classId, semesterId, studentId).map { it.mapExams(dict) }
}
}
@ -319,7 +281,7 @@ class Sdk {
fun getGrades(semesterId: Int): Single<List<Grade>> {
return when (mode) {
Mode.SCRAPPER -> scrapper.getGrades(semesterId).compose(ScrapperExceptionTransformer()).map { grades -> grades.mapGrades() }
Mode.HYBRID, Mode.API -> getDictionaries().flatMap { dict ->
Mode.HYBRID, Mode.API -> mobile.getDictionaries().flatMap { dict ->
mobile.getGrades(classId, semesterId, studentId).map { it.mapGrades(dict) }
}
}
@ -328,7 +290,7 @@ class Sdk {
fun getGradesSummary(semesterId: Int): Single<List<GradeSummary>> {
return when (mode) {
Mode.SCRAPPER -> scrapper.getGradesSummary(semesterId).compose(ScrapperExceptionTransformer()).map { it.mapGradesSummary() }
Mode.HYBRID, Mode.API -> getDictionaries().flatMap { dict ->
Mode.HYBRID, Mode.API -> mobile.getDictionaries().flatMap { dict ->
mobile.getGradesSummary(classId, semesterId, studentId).map { it.mapGradesSummary(dict) }
}
}
@ -358,7 +320,7 @@ class Sdk {
fun getHomework(start: LocalDate, end: LocalDate, semesterId: Int = 0): Single<List<Homework>> {
return when (mode) {
Mode.SCRAPPER -> scrapper.getHomework(start, end).compose(ScrapperExceptionTransformer()).map { it.mapHomework() }
Mode.HYBRID, Mode.API -> getDictionaries().flatMap { dict ->
Mode.HYBRID, Mode.API -> mobile.getDictionaries().flatMap { dict ->
mobile.getHomework(start, end, classId, semesterId, studentId).map { it.mapHomework(dict) }
}
}
@ -367,7 +329,7 @@ class Sdk {
fun getNotes(semesterId: Int): Single<List<Note>> {
return when (mode) {
Mode.SCRAPPER -> scrapper.getNotes().compose(ScrapperExceptionTransformer()).map { it.mapNotes() }
Mode.HYBRID, Mode.API -> getDictionaries().flatMap { dict ->
Mode.HYBRID, Mode.API -> mobile.getDictionaries().flatMap { dict ->
mobile.getNotes(semesterId, studentId).map { it.mapNotes(dict) }
}
}
@ -397,7 +359,7 @@ class Sdk {
fun getTeachers(semesterId: Int): Single<List<Teacher>> {
return when (mode) {
Mode.SCRAPPER -> scrapper.getTeachers().compose(ScrapperExceptionTransformer()).map { it.mapTeachers() }
Mode.HYBRID, Mode.API -> getDictionaries().flatMap { dict ->
Mode.HYBRID, Mode.API -> mobile.getDictionaries().flatMap { dict ->
mobile.getTeachers(studentId, semesterId).map { it.mapTeachers(dict) }
}
}
@ -420,15 +382,14 @@ class Sdk {
fun getReportingUnits(): Single<List<ReportingUnit>> {
return when (mode) {
Mode.HYBRID, Mode.SCRAPPER -> scrapper.getReportingUnits().compose(ScrapperExceptionTransformer()).map { it.mapReportingUnits() }
Mode.API -> getRegisterRepo(apiBaseUrl.replace("/$symbol", ""), symbol).getPupils()
.map { it.mapReportingUnits(studentId) }
Mode.API -> mobile.getPupils().map { it.mapReportingUnits(studentId) }
}
}
fun getRecipients(unitId: Int, role: Int = 2): Single<List<Recipient>> {
return when (mode) {
Mode.HYBRID, Mode.SCRAPPER -> scrapper.getRecipients(unitId, role).compose(ScrapperExceptionTransformer()).map { it.mapRecipients() }
Mode.API -> getDictionaries().map { it.teachers }.map { it.mapRecipients(unitId) }
Mode.API -> mobile.getDictionaries().map { it.teachers }.map { it.mapRecipients(unitId) }
}
}
@ -502,7 +463,7 @@ class Sdk {
fun getTimetable(start: LocalDate, end: LocalDate): Single<List<Timetable>> {
return when (mode) {
Mode.SCRAPPER -> scrapper.getTimetable(start, end).compose(ScrapperExceptionTransformer()).map { it.mapTimetable() }
Mode.HYBRID, Mode.API -> getDictionaries().flatMap { dict ->
Mode.HYBRID, Mode.API -> mobile.getDictionaries().flatMap { dict ->
mobile.getTimetable(start, end, classId, 0, studentId).map { it.mapTimetable(dict) }
}
}

View file

@ -1,6 +1,5 @@
package io.github.wulkanowy.sdk
import io.github.wulkanowy.api.toFormat
import org.threeten.bp.*
import java.sql.Timestamp
import java.util.*
@ -17,9 +16,4 @@ fun Long.toLocalDateTime(): LocalDateTime = Instant
fun Date.toLocalDateTime(): LocalDateTime = DateTimeUtils.toLocalDateTime(Timestamp(time))
fun LocalDate.toFormat() = toFormat("yyyy-MM-dd")
fun LocalDateTime.toFormat() = toFormat("yyyy-MM-dd")
fun String.normalizeRecipient() = substringBeforeLast("-").substringBefore(" [").substringBeforeLast(" (").trim()

View file

@ -1,13 +1,13 @@
package io.github.wulkanowy.sdk.attendance
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.api.attendance.AttendanceSummary as ScrapperAttendanceSummary
import io.github.wulkanowy.sdk.pojo.AttendanceSummary
import io.github.wulkanowy.api.toLocalDate
import io.github.wulkanowy.sdk.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.mobile.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.pojo.Attendance
import io.github.wulkanowy.sdk.pojo.AttendanceSummary
import io.github.wulkanowy.sdk.toLocalDate
import io.github.wulkanowy.api.attendance.Attendance as ScrapperAttendance
import io.github.wulkanowy.sdk.attendance.Attendance as ApiAttendance
import io.github.wulkanowy.api.attendance.AttendanceSummary as ScrapperAttendanceSummary
import io.github.wulkanowy.sdk.mobile.attendance.Attendance as ApiAttendance
fun List<ApiAttendance>.mapAttendance(dictionaries: Dictionaries): List<Attendance> {
return map {

View file

@ -1,11 +1,11 @@
package io.github.wulkanowy.sdk.exams
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.api.toLocalDate
import io.github.wulkanowy.sdk.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.mobile.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.pojo.Exam
import io.github.wulkanowy.sdk.toLocalDate
import io.github.wulkanowy.api.exams.Exam as ScrapperExam
import io.github.wulkanowy.sdk.exams.Exam as ApiExam
import io.github.wulkanowy.sdk.mobile.exams.Exam as ApiExam
fun List<ApiExam>.mapExams(dict: Dictionaries): List<Exam> {
return map { exam ->

View file

@ -1,12 +1,12 @@
package io.github.wulkanowy.sdk.grades
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.api.grades.isGradeValid
import io.github.wulkanowy.api.toLocalDate
import io.github.wulkanowy.sdk.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.mobile.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.pojo.Grade
import io.github.wulkanowy.sdk.toLocalDate
import io.github.wulkanowy.api.grades.Grade as ScrapperGrade
import io.github.wulkanowy.sdk.grades.Grade as ApiGrade
import io.github.wulkanowy.sdk.mobile.grades.Grade as ApiGrade
fun List<ApiGrade>.mapGrades(dict: Dictionaries): List<Grade> {
return map { grade ->

View file

@ -1,9 +1,10 @@
package io.github.wulkanowy.sdk.grades
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.api.grades.GradePointsSummary
import io.github.wulkanowy.api.grades.GradeStatistics as ScrapperGradeStatistics
import io.github.wulkanowy.sdk.pojo.GradeStatistics
import io.github.wulkanowy.sdk.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.mobile.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.mobile.grades.GradesSummaryResponse
import io.github.wulkanowy.sdk.pojo.GradePointsStatistics
import io.github.wulkanowy.sdk.pojo.GradeSummary
import io.github.wulkanowy.api.grades.GradeSummary as ScrapperGradeSummary

View file

@ -1,11 +1,11 @@
package io.github.wulkanowy.sdk.homework
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.api.toLocalDate
import io.github.wulkanowy.sdk.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.mobile.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.pojo.Homework
import io.github.wulkanowy.sdk.toLocalDate
import io.github.wulkanowy.api.homework.Homework as ScrapperHomework
import io.github.wulkanowy.sdk.homework.Homework as ApiHomework
import io.github.wulkanowy.sdk.mobile.homework.Homework as ApiHomework
fun List<ApiHomework>.mapHomework(dictionaries: Dictionaries): List<Homework> {
return map {

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.homepage
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.sdk.pojo.LuckyNumber
import io.github.wulkanowy.api.home.LuckyNumber as ScrapperLuckyNumber

View file

@ -1,10 +1,10 @@
package io.github.wulkanowy.sdk.messages
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.sdk.normalizeRecipient
import io.github.wulkanowy.sdk.pojo.Message
import io.github.wulkanowy.sdk.toLocalDateTime
import io.github.wulkanowy.api.messages.Message as ScrapperMessage
import io.github.wulkanowy.sdk.messages.Message as ApiMessage
import io.github.wulkanowy.sdk.mobile.messages.Message as ApiMessage
@JvmName("mapApiMessages")
fun List<ApiMessage>.mapMessages(): List<Message> {

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.mobile
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.api.mobile.Device as ScrapperDevice
import io.github.wulkanowy.api.mobile.TokenResponse

View file

@ -1,11 +1,11 @@
package io.github.wulkanowy.sdk.notes
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.api.toLocalDate
import io.github.wulkanowy.sdk.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.mobile.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.pojo.Note
import io.github.wulkanowy.sdk.toLocalDate
import io.github.wulkanowy.api.notes.Note as ScrapperNote
import io.github.wulkanowy.sdk.notes.Note as ApiNote
import io.github.wulkanowy.sdk.mobile.notes.Note as ApiNote
fun List<ApiNote>.mapNotes(dictionaries: Dictionaries): List<Note> {
return map {

View file

@ -1,6 +1,6 @@
package io.github.wulkanowy.sdk.messages
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.sdk.dictionaries.Teacher
import io.github.wulkanowy.sdk.mobile.dictionaries.Teacher
import io.github.wulkanowy.api.messages.Recipient as ScrapperRecipient
import io.github.wulkanowy.sdk.pojo.Recipient

View file

@ -1,7 +1,7 @@
package io.github.wulkanowy.sdk.messages
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.sdk.pojo.ReportingUnit
import io.github.wulkanowy.sdk.register.Student
import io.github.wulkanowy.sdk.mobile.register.Student
import io.github.wulkanowy.api.messages.ReportingUnit as ScrapperReportingUnit
fun List<ScrapperReportingUnit>.mapReportingUnits(): List<ReportingUnit> {

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.school
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.sdk.pojo.School
import io.github.wulkanowy.api.school.School as ScrapperSchool

View file

@ -1,6 +1,7 @@
package io.github.wulkanowy.sdk.register
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.sdk.pojo.Semester
import io.github.wulkanowy.sdk.mobile.register.Student
import io.github.wulkanowy.sdk.toLocalDate
import org.threeten.bp.LocalDate.now
import org.threeten.bp.Month

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.messages
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.sdk.pojo.Sender
import io.github.wulkanowy.sdk.pojo.SentMessage

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.student
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.api.toLocalDate
import io.github.wulkanowy.sdk.pojo.StudentInfo

View file

@ -1,15 +1,15 @@
package io.github.wulkanowy.sdk.register
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.sdk.Sdk
import io.github.wulkanowy.sdk.pojo.Student
import io.github.wulkanowy.api.register.Student as ScrapperStudent
import io.github.wulkanowy.sdk.register.Student as ApiStudent
import io.github.wulkanowy.sdk.mobile.register.Student as ApiStudent
fun List<ApiStudent>.mapStudents(symbol: String, certificateResponse: CertificateResponse, privateKey: String): List<Student> {
fun List<ApiStudent>.mapStudents(): List<Student> {
return map {
Student(
email = it.userLogin,
symbol = symbol,
symbol = it.reportingUnitSymbol,
studentId = it.id,
userLoginId = it.userLoginId,
classId = it.classId,
@ -19,11 +19,11 @@ fun List<ApiStudent>.mapStudents(symbol: String, certificateResponse: Certificat
schoolName = it.reportingUnitName,
loginType = Sdk.ScrapperLoginType.STANDARD,
loginMode = Sdk.Mode.API,
apiHost = certificateResponse.tokenCert!!.apiEndpoint.removeSuffix("/"),
apiHost = it.apiHost,
scrapperHost = "",
ssl = certificateResponse.tokenCert.apiEndpoint.startsWith("https"),
privateKey = privateKey,
certificateKey = certificateResponse.tokenCert.certificateKey
ssl = it.ssl,
privateKey = it.privateKey,
certificateKey = it.certificateKey
)
}
}

View file

@ -1,8 +1,8 @@
package io.github.wulkanowy.sdk.dictionaries
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.sdk.pojo.Subject
import io.github.wulkanowy.sdk.dictionaries.Subject as ApiSubject
import io.github.wulkanowy.api.attendance.Subject as ScrapperSubject
import io.github.wulkanowy.sdk.mobile.dictionaries.Subject as ApiSubject
@JvmName("mapApiSubjects")
fun List<ApiSubject>.mapSubjects(): List<Subject> {

View file

@ -1,9 +1,9 @@
package io.github.wulkanowy.sdk.school
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.sdk.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.mobile.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.pojo.Teacher
import io.github.wulkanowy.api.school.Teacher as ScrapperTeacher
import io.github.wulkanowy.sdk.school.Teacher as ApiTeacher
import io.github.wulkanowy.sdk.mobile.school.Teacher as ApiTeacher
fun List<ApiTeacher>.mapTeachers(dictionaries: Dictionaries): List<Teacher> {
return map { teacher ->

View file

@ -1,14 +1,14 @@
package io.github.wulkanowy.sdk.timetable
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.api.timetable.CompletedLesson as ScrapperCompletedLesson
import io.github.wulkanowy.sdk.pojo.CompletedLesson
import io.github.wulkanowy.api.toLocalDate
import io.github.wulkanowy.sdk.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.mobile.dictionaries.Dictionaries
import io.github.wulkanowy.sdk.pojo.Timetable
import io.github.wulkanowy.sdk.toLocalDate
import io.github.wulkanowy.sdk.toLocalDateTime
import io.github.wulkanowy.api.timetable.Timetable as ScrapperTimetable
import io.github.wulkanowy.sdk.timetable.Lesson as ApiTimetable
import io.github.wulkanowy.sdk.mobile.timetable.Lesson as ApiTimetable
fun List<ApiTimetable>.mapTimetable(dictionaries: Dictionaries): List<Timetable> {
return map {

View file

@ -1,4 +1,4 @@
package io.github.wulkanowy.sdk.messages
package io.github.wulkanowy.sdk.pojo
enum class Folder(val id: Int = 1) {

View file

@ -1,6 +1,6 @@
package io.github.wulkanowy.sdk
import io.github.wulkanowy.sdk.messages.Folder
import io.github.wulkanowy.sdk.pojo.Folder
import org.junit.Assert.assertEquals
import org.junit.Test
import org.threeten.bp.LocalDate.of

View file

@ -1,2 +1,3 @@
rootProject.name = 'sdk'
include 'sdk'
include 'mobile'