forked from github/wulkanowy-mirror
Add mobile access API (#126)
This commit is contained in:
parent
d4b172e022
commit
306092ce45
@ -1,4 +1,5 @@
|
||||
apply plugin: 'java-library'
|
||||
apply plugin: 'kotlin'
|
||||
apply plugin: 'org.sonarqube'
|
||||
apply plugin: 'jacoco'
|
||||
apply plugin: 'com.jfrog.bintray'
|
||||
@ -32,6 +33,8 @@ dependencies {
|
||||
implementation "org.apache.commons:commons-lang3:$apacheLang"
|
||||
implementation "com.google.code.gson:gson:$gson"
|
||||
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
|
||||
testImplementation "junit:junit:$junit"
|
||||
testImplementation "org.mockito:mockito-core:$mockito"
|
||||
}
|
||||
@ -115,3 +118,29 @@ artifacts {
|
||||
archives sourcesJar
|
||||
archives javadocJar
|
||||
}
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.2.41'
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
|
||||
compileTestKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ import io.github.wulkanowy.api.exams.ExamsWeek;
|
||||
import io.github.wulkanowy.api.grades.GradesList;
|
||||
import io.github.wulkanowy.api.grades.SubjectsList;
|
||||
import io.github.wulkanowy.api.messages.Messages;
|
||||
import io.github.wulkanowy.api.mobile.RegisterDevice;
|
||||
import io.github.wulkanowy.api.mobile.RegisteredDevices;
|
||||
import io.github.wulkanowy.api.notes.AchievementsList;
|
||||
import io.github.wulkanowy.api.notes.NotesList;
|
||||
import io.github.wulkanowy.api.school.SchoolInfo;
|
||||
@ -108,6 +110,14 @@ public class Vulcan {
|
||||
return new FamilyInformation(getStudentAndParent());
|
||||
}
|
||||
|
||||
public RegisteredDevices getRegisteredDevices() throws VulcanException, IOException {
|
||||
return new RegisteredDevices(getStudentAndParent());
|
||||
}
|
||||
|
||||
public RegisterDevice getRegisterDevice() throws VulcanException, IOException {
|
||||
return new RegisterDevice(getStudentAndParent());
|
||||
}
|
||||
|
||||
public Messages getMessages() throws VulcanException {
|
||||
return new Messages(getClient());
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
package io.github.wulkanowy.api.mobile
|
||||
|
||||
import io.github.wulkanowy.api.SnP
|
||||
import org.jsoup.nodes.Element
|
||||
|
||||
class RegisterDevice(private val snp: SnP) {
|
||||
|
||||
companion object {
|
||||
const val REGISTER_URL = "DostepMobilny.mvc/Rejestruj"
|
||||
}
|
||||
|
||||
data class Token(
|
||||
val token: String,
|
||||
val symbol: String,
|
||||
val pin: String
|
||||
)
|
||||
|
||||
fun getToken(): Token {
|
||||
val form = snp.getSnPPageDocument(REGISTER_URL).selectFirst("#rejestracja-formularz")
|
||||
|
||||
val fields = form.select(".blockElement")
|
||||
|
||||
return Token(
|
||||
getValue(fields[1]),
|
||||
getValue(fields[2]),
|
||||
getValue(fields[3])
|
||||
)
|
||||
}
|
||||
|
||||
fun getValue(e: Element): String {
|
||||
return e.text().split(":")[1].trim()
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package io.github.wulkanowy.api.mobile
|
||||
|
||||
import io.github.wulkanowy.api.SnP
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
class RegisteredDevices(private val snp: SnP) {
|
||||
|
||||
companion object {
|
||||
const val DEVICES_LIST_URL = "DostepMobilny.mvc"
|
||||
}
|
||||
|
||||
data class Device(
|
||||
val name: String,
|
||||
val system: String,
|
||||
val date: String,
|
||||
val id: Int
|
||||
)
|
||||
|
||||
fun getList(): List<Device> {
|
||||
val items = snp.getSnPPageDocument(DEVICES_LIST_URL).select("table tbody tr")
|
||||
val devices: MutableList<Device> = mutableListOf()
|
||||
|
||||
for (item in items) {
|
||||
val cells = item.select("td")
|
||||
val system = cells[0].text().split("(").last().removeSuffix(")")
|
||||
|
||||
devices.add(Device(
|
||||
cells[0].text().replace(" ($system)", ""),
|
||||
system,
|
||||
formatDate(cells[1].text()),
|
||||
cells[2].select("a").attr("href")
|
||||
.split("/").last().toInt()
|
||||
))
|
||||
}
|
||||
|
||||
return devices
|
||||
}
|
||||
|
||||
// TODO: Move to date utils
|
||||
private fun formatDate(date: String): String {
|
||||
val sdf = SimpleDateFormat("dd.MM.yyyy 'godz:' HH:mm:ss", Locale.ROOT)
|
||||
val d = sdf.parse(date)
|
||||
sdf.applyPattern("yyyy-MM-dd HH:mm:ss")
|
||||
|
||||
return sdf.format(d)
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package io.github.wulkanowy.api.mobile
|
||||
|
||||
import io.github.wulkanowy.api.StudentAndParentTestCase
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class RegisterDeviceTest : StudentAndParentTestCase() {
|
||||
|
||||
@Test
|
||||
fun getTokenTest() {
|
||||
val registration = RegisterDevice(getSnp("Rejestruj.html"))
|
||||
|
||||
assertEquals("3S1A1B2C", registration.getToken().token)
|
||||
assertEquals("Default", registration.getToken().symbol)
|
||||
assertEquals("1234567", registration.getToken().pin)
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package io.github.wulkanowy.api.mobile
|
||||
|
||||
import io.github.wulkanowy.api.StudentAndParentTestCase
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class RegisteredDevicesListTest : StudentAndParentTestCase() {
|
||||
|
||||
private val filled = RegisteredDevices(getSnp("DostepMobilny-filled.html"))
|
||||
|
||||
@Test
|
||||
fun getListTest() {
|
||||
assertEquals(2, filled.getList().size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getNameTest() {
|
||||
assertEquals("google Android SDK built for x86", filled.getList()[0].name)
|
||||
assertEquals("google (Android SDK) built for x86", filled.getList()[1].name)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getSystemTest() {
|
||||
assertEquals("Android 8.1.0", filled.getList()[0].system)
|
||||
assertEquals("Android 8.1.0", filled.getList()[1].system)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getDateTest() {
|
||||
assertEquals("2018-01-20 22:35:30", filled.getList()[0].date)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getIdTest() {
|
||||
assertEquals(321, filled.getList()[0].id)
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="pl">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Witryna ucznia i rodzica – dostęp mobilny</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<main class="mainContainer">
|
||||
<h1>Dostęp mobilny</h1>
|
||||
|
||||
<article>
|
||||
<h2>Zarejestrowane urządzenia</h2>
|
||||
</article>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Urządzenie</th>
|
||||
<th>Data rejestracji</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="text-center">
|
||||
<td>google Android SDK built for x86 (Android 8.1.0)</td>
|
||||
<td>20.01.2018 godz: 22:35:30</td>
|
||||
<td class="cellWithButton">
|
||||
<a href="/Default/123456/DostepMobilny.mvc/Wyrejestruj/321" class="button">Wyrejestruj</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="text-center">
|
||||
<td>google (Android SDK) built for x86 (Android 8.1.0)</td>
|
||||
<td>20.01.2018 godz: 22:35:30</td>
|
||||
<td class="cellWithButton">
|
||||
<a href="/Default/123456/DostepMobilny.mvc/Wyrejestruj/213" class="button">Wyrejestruj</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</main>
|
||||
|
||||
<footer>wersja: 18.01.0001.27311</footer>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="pl">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Witryna ucznia i rodzica – Rejestracja urządzenia mobilnego</title>
|
||||
<style>
|
||||
.blockElement {
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main class="mainContainer">
|
||||
<h1>Rejestracja urządzenia mobilnego</h1>
|
||||
<article class="text-center" id="rejestracja-formularz">
|
||||
<span class="blockElement">Za pomocą aplikacji "Dzienniczek+" zeskanuj kod QR.</span>
|
||||
<img src=" data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQCAYAAACAvzbMAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4gUdCTohm9rlswAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAFKklEQVR42u3dYYqDQAyA0abk/lfO/l+6LLZYksx7J3C09SPgaFRVPQDgoqdTAICAACAgAAgIAAICAAICgIAAICAACAgAAgIAAgKAgAAgIAAICAACAgACAoCAACAgAAgIAAICAAICgIAAICAACAgAAgIAAgKAgAAgIAAICAACAgACAoCAACAgAAgIAAICAFdltwOKiNUnvKqOXj/4/9y3fhMIACMICAACAoCAACAgAAgIAAgIAJ/IaQfc7Tno3+5+Dr37+sH/p+/6TSAACAgAAgKAgACAgAAgIAAICADj5bYF2YcBuH+YQAAQEAAEBAAEBAABAUBAABAQAAQEAAQEAAEBQEAAEBAABAQABAQAAQFAQAAQEAAEBAAEBAABAUBAABAQAAQEAP6R2xZUVa4q4P5hAgFAQAAQEAAQEAAEBAABAUBAANho3D6QiHDVAPcPEwgAAgKAgACAgAAgIAAICAACAsCJ2u0D8T5+wP3DBAKAgACAgAAgIAAICAACAoCAAMBL7faBeF8/4P7wWrd9LiYQAAQEAAEBQEAAEBAAEBAABASAr8tpB+x9/7DX6f/vaftcTCAACAgAAgKAgAAgIAAgIAAICAACAoCAACAgACAgAAgIAAICgIAAICAAICAACAgAAgKAgAAgIAAgIAAICAACAoCAACAgACAgAAgIAAICgIAAICAAICAACAgAAgKAgAAgIAAgIAAICAACAoCAAICAACAgAAgIAAICgIAAgIAAICAACAgAAgKAgACAgAAgIAAICAACAoCAAICAACAgAAgIAAICgIAAgIAAICAACAgAAgKAgACAgAAgIAAICAACAoCAAICAACAgAAgIAAICgIA4BQAICAACAoCAACAgACAgAAgIAAICgIAAICAAICAACAgAAgKAgAAgIAAgIAAICAACAoCAACAgACAgAAgIAAICgIAAICAAICAACAgAAgKAgAAgIAAgIAAICAACAoCAACAgACAgAAgIAAICgIAAgIAAICAACAgAAgKAgACAgAAgIAAICAACAoCAAICAACAgAAgIAAICgIAAgIAAICAACAgAAgKAgACAgAAgIAAICAACAoCAAICAACAgAAgIAAICgIAAgIAAICAACAgAAgKAgACAgAAgIAAICAACAgACAoCAACAgAAgIAAICAAICgIAAICAACAgAAgIAAgKAgAAgIAAICAACAgACAoCAACAgAAgIAAICAAICgIAAICAACAgAAgIAAgKAgAAgIAAICAACAgACAoCAANBWTjvgiDj6glWVXy1gAgFAQAAQEAAQEAAEBAABAUBAuOb0x5CBPdrtAzl9n4PAACYQAAQEAAQEAAEBQEAAEBAABAQA/tBuH8j2fRC+5wGYQAAQEAAQEAAEBAABAUBAAEBAAHhTTjvg7vsofM8DMIEAgIAAICAACAgAAgKAgACAgABwk9y2oLv3YfieB4AJBAABAUBAABAQAAQEAAQEAAEBQEAAEBAABAQABAQAAQFAQAAQEAAEBAAEBAABAUBAABAQAAQEAAQEAAEBQEAAGC+3LaiqXFUAEwgAAgKAgACAgAAgIAAICAACAsBG4/aBRMTRF+z09QMmEAAEBAABAQABAUBAABAQAAQEgINF+YAGACYQAAQEAAEBQEAAQEAAEBAABAQAAQFAQABAQAAQEAAEBAABAUBAAEBAABAQAAQEAAEBQEAAQEAAEBAABAQAAQFAQABAQAAQEAAEBAABAUBAAEBAABAQAAQEAAEBQEAAQEAA+IYf8fZKNX0RrMQAAAAASUVORK5CYII="
|
||||
alt="Kod QR" title="Kod QR" height="400" width="400"/>
|
||||
<span class="blockElement">Token: 3S1A1B2C</span>
|
||||
<span class="blockElement">Symbol: Default</span>
|
||||
<span class="blockElement">PIN: 1234567</span>
|
||||
</article>
|
||||
</main>
|
||||
<footer>wersja: 18.01.0001.27311</footer>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user