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