Support new spaceping API
This commit is contained in:
parent
d0df39ef11
commit
e1bd5b3593
3 changed files with 15 additions and 8 deletions
|
@ -2,6 +2,7 @@
|
|||
command_prefix = "!"
|
||||
|
||||
[space]
|
||||
base_url = "https://spaceapi.it-syndikat.org/api/"
|
||||
spaceapi_url = "https://spaceapi.it-syndikat.org/api/status.php"
|
||||
spaceping_url = "https://homeassistant.asozial.it-syndikat.org/api/webhook/spaceping"
|
||||
spaceping_token = "foo"
|
||||
announce_rooms = ["#lobby:it-syndik.at"]
|
||||
|
|
|
@ -40,7 +40,8 @@ pub struct AppConfig {
|
|||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub struct SpaceConfig {
|
||||
base_url: Url,
|
||||
spaceapi_url: Url,
|
||||
spaceping_url: Url,
|
||||
spaceping_token: String,
|
||||
announce_rooms: Vec<OwnedRoomOrAliasId>,
|
||||
}
|
||||
|
@ -118,7 +119,8 @@ impl Bot {
|
|||
client.restore_login(session_data.session).await?;
|
||||
|
||||
let api = ItsApi::new(
|
||||
config.space.base_url.clone(),
|
||||
config.space.spaceapi_url.clone(),
|
||||
config.space.spaceping_url.clone(),
|
||||
config.space.spaceping_token.clone(),
|
||||
);
|
||||
let open_state = get_open_state(&api).await?;
|
||||
|
|
|
@ -18,8 +18,11 @@ pub enum Error {
|
|||
/// Handler for the IT-Syndikat API.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ItsApi {
|
||||
base_url: Url,
|
||||
spaceapi_url: Url,
|
||||
|
||||
spaceping_url: Url,
|
||||
spaceping_token: String,
|
||||
|
||||
client: Client,
|
||||
}
|
||||
|
||||
|
@ -61,9 +64,10 @@ fn patch_response(value: &mut serde_json::Value) {
|
|||
impl ItsApi {
|
||||
/// Constructs a new IT-Syndikat API handler.
|
||||
#[instrument]
|
||||
pub fn new(base_url: Url, spaceping_token: String) -> Self {
|
||||
pub fn new(spaceapi_url: Url, spaceping_url: Url, spaceping_token: String) -> Self {
|
||||
Self {
|
||||
base_url,
|
||||
spaceapi_url,
|
||||
spaceping_url,
|
||||
spaceping_token,
|
||||
client: Client::new(),
|
||||
}
|
||||
|
@ -80,7 +84,7 @@ impl ItsApi {
|
|||
event!(Level::DEBUG, "requesting spaceapi status");
|
||||
let response = self
|
||||
.client
|
||||
.get(self.base_url.join("status.php")?)
|
||||
.get(self.spaceapi_url.clone())
|
||||
.send()
|
||||
.await
|
||||
.map_err(Error::Network)?
|
||||
|
@ -107,7 +111,7 @@ impl ItsApi {
|
|||
event!(Level::INFO, "sending spaceping");
|
||||
|
||||
self.client
|
||||
.post(self.base_url.join("ping.php")?)
|
||||
.post(self.spaceping_url.clone())
|
||||
.query(&[("apikey", &self.spaceping_token)])
|
||||
.send()
|
||||
.await
|
||||
|
|
Loading…
Reference in a new issue