Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HeaderMap>,
) -> ClientResult<node::Metadata> {
self.request(&format!("api/v1/metadata/{id}"), headers, None)
.await
}

pub async fn table_full(
&self,
path: &str,
Expand Down
14 changes: 13 additions & 1 deletion src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Option<Run>> {
let auth = ctx.data::<Option<AuthHeader>>()?;
let headers = auth.as_ref().map(AuthHeader::as_header_map);
match ctx.data::<TiledClient>()?.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 {
Expand Down
13 changes: 11 additions & 2 deletions src/model/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ use serde_json::Value;

use crate::model::{array, container, table};

pub type Root = Response<Vec<DataOption>>;
pub type Metadata = Response<Data>;

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Root {
data: Vec<DataOption>,
pub struct Response<D> {
data: D,
pub error: Value,
pub links: Option<Links>,
pub meta: Value,
Expand All @@ -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 {
Expand Down
Loading