Event system
- App events, can be polled by apps using the HTTP API - Node events, can be processed by a node implementation by registering a callback in the `Ubisync` object - Some further additions, like adding pot members etc. to test these new event functions
This commit is contained in:
parent
76f6a6b67b
commit
d258060769
24 changed files with 479 additions and 96 deletions
|
@ -1,7 +1,7 @@
|
|||
use reqwest::Method;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::{PotId, Pot};
|
||||
use crate::types::{AppId, Pot, PotId};
|
||||
|
||||
use super::UbisyncRequest;
|
||||
|
||||
|
@ -15,6 +15,7 @@ pub struct AppRegisterRequest {
|
|||
#[derive(Serialize, Deserialize)]
|
||||
pub struct AppRegisterResponse {
|
||||
pub token: String,
|
||||
pub app_id: AppId,
|
||||
}
|
||||
|
||||
impl UbisyncRequest for AppRegisterRequest {
|
||||
|
|
42
ubisync-lib/src/api/events.rs
Normal file
42
ubisync-lib/src/api/events.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use reqwest::Method;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use crate::types::{ElementId, PotId};
|
||||
|
||||
use super::UbisyncRequest;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub enum AppEvent {
|
||||
NewPot {
|
||||
id: PotId,
|
||||
app_type: String,
|
||||
},
|
||||
ElementUpdate {
|
||||
id: ElementId,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct PollEventsRequest {
|
||||
pub timeout: u16,
|
||||
pub accumulate: u16,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct PollEventsResponse {
|
||||
pub events: Vec<AppEvent>,
|
||||
}
|
||||
|
||||
|
||||
impl UbisyncRequest for PollEventsRequest {
|
||||
type PathParameters = ();
|
||||
type Response = PollEventsResponse;
|
||||
|
||||
fn method(&self) -> reqwest::Method {
|
||||
Method::GET
|
||||
}
|
||||
|
||||
fn path(&self, _: Self::PathParameters) -> String {
|
||||
"/events".to_string()
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
pub mod app;
|
||||
pub mod element;
|
||||
pub mod events;
|
||||
|
||||
/// Any struct defining a request body for the ubisync API must implement this trait
|
||||
/// It is used both by the client in the SDK and by the API logic in the ubisync node
|
||||
|
|
11
ubisync-lib/src/types/app_id.rs
Normal file
11
ubisync-lib/src/types/app_id.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct AppId(Uuid);
|
||||
|
||||
impl AppId {
|
||||
pub fn new() -> Self {
|
||||
AppId { 0: Uuid::new_v4() }
|
||||
}
|
||||
}
|
|
@ -43,4 +43,7 @@ impl Element {
|
|||
pub fn content(&self) -> &ElementContent {
|
||||
&self.content
|
||||
}
|
||||
pub fn pot(&self) -> &Option<PotId> {
|
||||
&self.pot
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
mod app_id;
|
||||
pub use app_id::AppId;
|
||||
|
||||
mod element_content;
|
||||
pub use element_content::ElementContent;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
pub struct PotId(Uuid);
|
||||
impl PotId {
|
||||
pub fn new() -> Self {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue