diff --git a/src/clients.rs b/src/clients.rs index 61dc2c3..b659ff7 100644 --- a/src/clients.rs +++ b/src/clients.rs @@ -69,6 +69,16 @@ impl TiledClient { self.request(&format!("api/v1/search/{}", path), headers, Some(query)) .await } + + pub async fn metadata( + &self, + id: String, + headers: Option, + ) -> ClientResult { + self.request(&format!("api/v1/metadata/{id}"), headers, None) + .await + } + pub async fn table_full( &self, path: &str, diff --git a/src/model.rs b/src/model.rs index 1e0af1d..0acabf8 100644 --- a/src/model.rs +++ b/src/model.rs @@ -13,7 +13,7 @@ use serde_json::Value; use tracing::{info, instrument}; use crate::RootAddress; -use crate::clients::TiledClient; +use crate::clients::{ClientError, TiledClient}; use crate::handlers::AuthHeader; use crate::model::node::NodeAttributes; @@ -29,6 +29,18 @@ impl TiledQuery { async fn instrument_session(&self, name: String) -> InstrumentSession { InstrumentSession { name } } + + async fn run(&self, ctx: &Context<'_>, id: String) -> Result> { + let auth = ctx.data::>()?; + let headers = auth.as_ref().map(AuthHeader::as_header_map); + match ctx.data::()?.metadata(id, headers).await { + Ok(run) => Ok(Some(Run { + data: run.into_data(), + })), + Err(ClientError::TiledRequest(404, _)) => Ok(None), + Err(other) => Err(other.into()), + } + } } struct InstrumentSession { diff --git a/src/model/node.rs b/src/model/node.rs index 0b5be61..6a2ce6d 100644 --- a/src/model/node.rs +++ b/src/model/node.rs @@ -6,9 +6,12 @@ use serde_json::Value; use crate::model::{array, container, table}; +pub type Root = Response>; +pub type Metadata = Response; + #[derive(Debug, PartialEq, Serialize, Deserialize)] -pub struct Root { - data: Vec, +pub struct Response { + data: D, pub error: Value, pub links: Option, pub meta: Value, @@ -23,6 +26,12 @@ impl Root { } } +impl Metadata { + pub fn into_data(self) -> Data { + self.data + } +} + #[derive(Debug, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum DataOption {