Compare commits
7 Commits
0f48c24009
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
021e030ded
|
|||
|
bb0b31e84d
|
|||
|
549968dbf3
|
|||
|
9c9fbfeede
|
|||
|
5d21a8ad9e
|
|||
|
7738043a80
|
|||
|
7090595505
|
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -357,7 +357,7 @@ checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jecna_supl_client"
|
name = "jecna_supl_client"
|
||||||
version = "0.2.1"
|
version = "0.2.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"minreq",
|
"minreq",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "jecna_supl_client"
|
name = "jecna_supl_client"
|
||||||
version = "0.2.1"
|
version = "0.2.3"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "cz.jzitnik"
|
group = "cz.jzitnik"
|
||||||
version = "0.2.1"
|
version = "0.2.3"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>cz.jzitnik</groupId>
|
<groupId>cz.jzitnik</groupId>
|
||||||
<artifactId>jecna-supl-client</artifactId>
|
<artifactId>jecna-supl-client</artifactId>
|
||||||
<version>0.2.1</version>
|
<version>0.2.3</version>
|
||||||
<name>Jecna Supl Client</name>
|
<name>Jecna Supl Client</name>
|
||||||
<description>Kotlin bindings for the Jecna Supl Rust library</description>
|
<description>Kotlin bindings for the Jecna Supl Rust library</description>
|
||||||
<url>https://gitea.jzitnik.dev/jzitnik/jecna-supl-client</url>
|
<url>https://gitea.jzitnik.dev/jzitnik/jecna-supl-client</url>
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
export ANDROID_NDK_HOME=/home/kuba/.Android/Sdk/ndk/29.0.14206865/
|
#export ANDROID_NDK_HOME=/home/kuba/.Android/Sdk/ndk/29.0.14206865/
|
||||||
|
export ANDROID_NDK_HOME=/home/kuba/.Android/Sdk/ndk/27.0.12077973/
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
PROJECT_NAME="jecna_supl_client"
|
PROJECT_NAME="jecna_supl_client"
|
||||||
|
|||||||
33
src/api.rs
33
src/api.rs
@@ -1,3 +1,5 @@
|
|||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::models::{ApiResponse, SuplError};
|
use crate::models::{ApiResponse, SuplError};
|
||||||
|
|
||||||
pub fn fetch_api(provider_url: &str) -> Result<ApiResponse, SuplError> {
|
pub fn fetch_api(provider_url: &str) -> Result<ApiResponse, SuplError> {
|
||||||
@@ -14,3 +16,34 @@ pub fn fetch_api(provider_url: &str) -> Result<ApiResponse, SuplError> {
|
|||||||
reason: e.to_string(),
|
reason: e.to_string(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct StatusResponse {
|
||||||
|
working: bool,
|
||||||
|
message: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn test_api(provider_url: &str) -> Result<(), SuplError> {
|
||||||
|
let trimmed = provider_url.trim_end_matches('/');
|
||||||
|
let url = format!("{}/status", trimmed);
|
||||||
|
|
||||||
|
let status: StatusResponse = minreq::get(&url)
|
||||||
|
.send()
|
||||||
|
.map_err(|e| SuplError::NetworkError {
|
||||||
|
reason: e.to_string(),
|
||||||
|
})?
|
||||||
|
.json()
|
||||||
|
.map_err(|e| SuplError::ParseError {
|
||||||
|
reason: e.to_string(),
|
||||||
|
})?;
|
||||||
|
|
||||||
|
if status.working {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(SuplError::ParseError {
|
||||||
|
reason: status
|
||||||
|
.message
|
||||||
|
.unwrap_or_else(|| "Provider reported not working".to_string()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
17
src/lib.rs
17
src/lib.rs
@@ -3,10 +3,14 @@ mod models;
|
|||||||
mod schedule;
|
mod schedule;
|
||||||
mod teacher_absence;
|
mod teacher_absence;
|
||||||
mod all;
|
mod all;
|
||||||
|
mod report;
|
||||||
|
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
|
|
||||||
pub use models::*;
|
pub use models::*;
|
||||||
|
pub use report::ReportLocation;
|
||||||
|
|
||||||
|
use crate::report::{report_impl, ReportLocation};
|
||||||
|
|
||||||
uniffi::setup_scaffolding!();
|
uniffi::setup_scaffolding!();
|
||||||
|
|
||||||
@@ -31,16 +35,29 @@ impl JecnaSuplClient {
|
|||||||
|
|
||||||
pub fn get_schedule(&self, class_name: String) -> Result<SuplResult, SuplError> {
|
pub fn get_schedule(&self, class_name: String) -> Result<SuplResult, SuplError> {
|
||||||
let provider = self.provider_url.read().unwrap();
|
let provider = self.provider_url.read().unwrap();
|
||||||
|
|
||||||
|
api::test_api(&provider)?;
|
||||||
schedule::get_schedule_impl(&provider, class_name)
|
schedule::get_schedule_impl(&provider, class_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_teacher_absence(&self) -> Result<TeacherAbsenceResult, SuplError> {
|
pub fn get_teacher_absence(&self) -> Result<TeacherAbsenceResult, SuplError> {
|
||||||
let provider = self.provider_url.read().unwrap();
|
let provider = self.provider_url.read().unwrap();
|
||||||
|
|
||||||
|
api::test_api(&provider)?;
|
||||||
teacher_absence::get_teacher_absence_impl(&provider)
|
teacher_absence::get_teacher_absence_impl(&provider)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_all(&self) -> Result<ApiResponse, SuplError> {
|
pub fn get_all(&self) -> Result<ApiResponse, SuplError> {
|
||||||
let provider = self.provider_url.read().unwrap();
|
let provider = self.provider_url.read().unwrap();
|
||||||
|
|
||||||
|
api::test_api(&provider)?;
|
||||||
all::get_all_impl(&provider)
|
all::get_all_impl(&provider)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn report(&self, content: String, class: String, report_location: ReportLocation) -> Result<(), SuplError> {
|
||||||
|
let provider = self.provider_url.read().unwrap();
|
||||||
|
|
||||||
|
api::test_api(&provider)?;
|
||||||
|
report_impl(&provider, content, class, report_location)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,33 +18,33 @@ pub enum SuplError {
|
|||||||
pub enum AbsenceEntry {
|
pub enum AbsenceEntry {
|
||||||
#[serde(rename = "wholeDay")]
|
#[serde(rename = "wholeDay")]
|
||||||
WholeDay {
|
WholeDay {
|
||||||
teacher: String,
|
teacher: Option<String>,
|
||||||
#[serde(rename = "teacherCode")]
|
#[serde(rename = "teacherCode")]
|
||||||
teacher_code: String,
|
teacher_code: String,
|
||||||
},
|
},
|
||||||
#[serde(rename = "single")]
|
#[serde(rename = "single")]
|
||||||
Single {
|
Single {
|
||||||
teacher: String,
|
teacher: Option<String>,
|
||||||
#[serde(rename = "teacherCode")]
|
#[serde(rename = "teacherCode")]
|
||||||
teacher_code: String,
|
teacher_code: String,
|
||||||
hours: u16,
|
hours: u16,
|
||||||
},
|
},
|
||||||
#[serde(rename = "range")]
|
#[serde(rename = "range")]
|
||||||
Range {
|
Range {
|
||||||
teacher: String,
|
teacher: Option<String>,
|
||||||
#[serde(rename = "teacherCode")]
|
#[serde(rename = "teacherCode")]
|
||||||
teacher_code: String,
|
teacher_code: String,
|
||||||
hours: AbsenceRange,
|
hours: AbsenceRange,
|
||||||
},
|
},
|
||||||
#[serde(rename = "exkurze")]
|
#[serde(rename = "exkurze")]
|
||||||
Exkurze {
|
Exkurze {
|
||||||
teacher: String,
|
teacher: Option<String>,
|
||||||
#[serde(rename = "teacherCode")]
|
#[serde(rename = "teacherCode")]
|
||||||
teacher_code: String,
|
teacher_code: String,
|
||||||
},
|
},
|
||||||
#[serde(rename = "zastoupen")]
|
#[serde(rename = "zastoupen")]
|
||||||
Zastoupen {
|
Zastoupen {
|
||||||
teacher: String,
|
teacher: Option<String>,
|
||||||
#[serde(rename = "teacherCode")]
|
#[serde(rename = "teacherCode")]
|
||||||
teacher_code: String,
|
teacher_code: String,
|
||||||
zastupuje: SubstituteInfo,
|
zastupuje: SubstituteInfo,
|
||||||
@@ -61,7 +61,7 @@ pub struct AbsenceRange {
|
|||||||
|
|
||||||
#[derive(Deserialize, Debug, uniffi::Record, Clone)]
|
#[derive(Deserialize, Debug, uniffi::Record, Clone)]
|
||||||
pub struct SubstituteInfo {
|
pub struct SubstituteInfo {
|
||||||
pub teacher: String,
|
pub teacher: Option<String>,
|
||||||
#[serde(rename = "teacherCode")]
|
#[serde(rename = "teacherCode")]
|
||||||
pub teacher_code: String,
|
pub teacher_code: String,
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ pub struct DailyData {
|
|||||||
#[serde(rename = "takesPlace")]
|
#[serde(rename = "takesPlace")]
|
||||||
pub takes_place: String,
|
pub takes_place: String,
|
||||||
#[serde(rename = "reservedRooms")]
|
#[serde(rename = "reservedRooms")]
|
||||||
pub reserved_rooms: Vec<String>,
|
pub reserved_rooms: Vec<Option<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, uniffi::Record, Clone)]
|
#[derive(Deserialize, Debug, uniffi::Record, Clone)]
|
||||||
|
|||||||
61
src/report.rs
Normal file
61
src/report.rs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use crate::SuplError;
|
||||||
|
|
||||||
|
#[derive(uniffi::Enum)]
|
||||||
|
pub enum ReportLocation {
|
||||||
|
Timetable,
|
||||||
|
TeacherAbsence,
|
||||||
|
TakesPlace
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ReportLocation {
|
||||||
|
fn to_str(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
ReportLocation::Timetable => "TIMETABLE",
|
||||||
|
ReportLocation::TeacherAbsence => "ABSENCE",
|
||||||
|
ReportLocation::TakesPlace => "TAKES_PLACE"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct ReportRequest {
|
||||||
|
content: String,
|
||||||
|
class: String,
|
||||||
|
location: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn report_impl(
|
||||||
|
provider: &str,
|
||||||
|
content: String,
|
||||||
|
class: String,
|
||||||
|
report_location: ReportLocation,
|
||||||
|
) -> Result<(), SuplError> {
|
||||||
|
let trimmed = provider.trim_end_matches('/');
|
||||||
|
let url = format!("{}/report", trimmed);
|
||||||
|
|
||||||
|
let body = ReportRequest {
|
||||||
|
content,
|
||||||
|
class,
|
||||||
|
location: report_location.to_str().to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let json = serde_json::to_string(&body)
|
||||||
|
.map_err(|e| SuplError::ParseError { reason: e.to_string() })?;
|
||||||
|
|
||||||
|
let response = minreq::post(url)
|
||||||
|
.with_header("Content-Type", "application/json")
|
||||||
|
.with_body(json)
|
||||||
|
.send()
|
||||||
|
.map_err(|e| SuplError::NetworkError { reason: e.to_string() })?;
|
||||||
|
|
||||||
|
if response.status_code >= 400 {
|
||||||
|
return Err(SuplError::RuntimeError {
|
||||||
|
reason: format!("Server returned HTTP {}", response.status_code),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user