use anyhow::Result;
use crate::Client;
#[derive(Clone, Debug)]
pub struct Projects {
pub client: Client,
}
impl Projects {
#[doc(hidden)]
pub fn new(client: Client) -> Self {
Self { client }
}
#[doc = "List the active categories available for project \
submissions.\n\n```rust,no_run\nasync fn example_projects_list_categories() -> \
anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let \
result: Vec<kittycad::types::ProjectCategoryResponse> =\n \
client.projects().list_categories().await?;\n println!(\"{:?}\", result);\n \
Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn list_categories<'a>(
&'a self,
) -> Result<Vec<crate::types::ProjectCategoryResponse>, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!("{}/{}", self.client.base_url, "projects/categories"),
);
req = req.bearer_auth(&self.client.token);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "List publicly visible community projects for the \
website/gallery.\n\n```rust,no_run\nasync fn example_projects_list_public() -> \
anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let \
result: Vec<kittycad::types::PublicProjectResponse> = \
client.projects().list_public().await?;\n println!(\"{:?}\", result);\n \
Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn list_public<'a>(
&'a self,
) -> Result<Vec<crate::types::PublicProjectResponse>, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!("{}/{}", self.client.base_url, "projects/public"),
);
req = req.bearer_auth(&self.client.token);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Fetch the public thumbnail for a published project.\n\n**Parameters:**\n\n- `id: uuid::Uuid`: The identifier. (required)\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn example_projects_get_public_thumbnail() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n client\n .projects()\n .get_public_thumbnail(uuid::Uuid::from_str(\n \"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\",\n )?)\n .await?;\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn get_public_thumbnail<'a>(
&'a self,
id: uuid::Uuid,
) -> Result<(), crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!(
"{}/{}",
self.client.base_url,
"projects/public/{id}/thumbnail".replace("{id}", &format!("{}", id))
),
);
req = req.bearer_auth(&self.client.token);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Ok(())
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Add the authenticated user's upvote to a published community \
project.\n\n**Parameters:**\n\n- `id: uuid::Uuid`: The identifier. \
(required)\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn \
example_projects_create_public_vote() -> anyhow::Result<()> {\n let client = \
kittycad::Client::new_from_env();\n let result: \
kittycad::types::PublicProjectVoteResponse = client\n .projects()\n \
.create_public_vote(uuid::Uuid::from_str(\n \
\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\",\n )?)\n .await?;\n \
println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn create_public_vote<'a>(
&'a self,
id: uuid::Uuid,
) -> Result<crate::types::PublicProjectVoteResponse, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!(
"{}/{}",
self.client.base_url,
"projects/public/{id}/vote".replace("{id}", &format!("{}", id))
),
);
req = req.bearer_auth(&self.client.token);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Remove the authenticated user's upvote from a published community \
project.\n\n**Parameters:**\n\n- `id: uuid::Uuid`: The identifier. \
(required)\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn \
example_projects_delete_public_vote() -> anyhow::Result<()> {\n let client = \
kittycad::Client::new_from_env();\n let result: \
kittycad::types::PublicProjectVoteResponse = client\n .projects()\n \
.delete_public_vote(uuid::Uuid::from_str(\n \
\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\",\n )?)\n .await?;\n \
println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn delete_public_vote<'a>(
&'a self,
id: uuid::Uuid,
) -> Result<crate::types::PublicProjectVoteResponse, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::DELETE,
format!(
"{}/{}",
self.client.base_url,
"projects/public/{id}/vote".replace("{id}", &format!("{}", id))
),
);
req = req.bearer_auth(&self.client.token);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "List the authenticated user's projects.\n\n```rust,no_run\nasync fn \
example_projects_list() -> anyhow::Result<()> {\n let client = \
kittycad::Client::new_from_env();\n let result: \
Vec<kittycad::types::ProjectSummaryResponse> = client.projects().list().await?;\n \
println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn list<'a>(
&'a self,
) -> Result<Vec<crate::types::ProjectSummaryResponse>, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!("{}/{}", self.client.base_url, "user/projects"),
);
req = req.bearer_auth(&self.client.token);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Create a draft project for the authenticated user.\n\n```rust,no_run\nasync fn example_projects_create() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::ProjectResponse = client\n .projects()\n .create(vec![kittycad::types::multipart::Attachment {\n name: \"thing\".to_string(),\n filepath: Some(\"myfile.json\".into()),\n content_type: Some(\"application/json\".to_string()),\n data: std::fs::read(\"myfile.json\").unwrap(),\n }])\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn create<'a>(
&'a self,
attachments: Vec<crate::types::multipart::Attachment>,
) -> Result<crate::types::ProjectResponse, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!("{}/{}", self.client.base_url, "user/projects"),
);
req = req.bearer_auth(&self.client.token);
use std::convert::TryInto;
let mut form = reqwest::multipart::Form::new();
for attachment in attachments {
form = form.part(attachment.name.clone(), attachment.try_into()?);
}
req = req.multipart(form);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Get one of the authenticated user's projects.\n\n**Parameters:**\n\n- `id: uuid::Uuid`: The identifier. (required)\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn example_projects_get() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::ProjectResponse = client\n .projects()\n .get(uuid::Uuid::from_str(\n \"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\",\n )?)\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn get<'a>(
&'a self,
id: uuid::Uuid,
) -> Result<crate::types::ProjectResponse, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!(
"{}/{}",
self.client.base_url,
"user/projects/{id}".replace("{id}", &format!("{}", id))
),
);
req = req.bearer_auth(&self.client.token);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Replace one of the authenticated user's projects.\n\n**Parameters:**\n\n- `id: uuid::Uuid`: The identifier. (required)\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn example_projects_update() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::ProjectResponse = client\n .projects()\n .update(\n vec![kittycad::types::multipart::Attachment {\n name: \"thing\".to_string(),\n filepath: Some(\"myfile.json\".into()),\n content_type: Some(\"application/json\".to_string()),\n data: std::fs::read(\"myfile.json\").unwrap(),\n }],\n uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn update<'a>(
&'a self,
attachments: Vec<crate::types::multipart::Attachment>,
id: uuid::Uuid,
) -> Result<crate::types::ProjectResponse, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::PUT,
format!(
"{}/{}",
self.client.base_url,
"user/projects/{id}".replace("{id}", &format!("{}", id))
),
);
req = req.bearer_auth(&self.client.token);
use std::convert::TryInto;
let mut form = reqwest::multipart::Form::new();
for attachment in attachments {
form = form.part(attachment.name.clone(), attachment.try_into()?);
}
req = req.multipart(form);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Delete one of the authenticated user's projects.\n\n**Parameters:**\n\n- `id: uuid::Uuid`: The identifier. (required)\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn example_projects_delete() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n client\n .projects()\n .delete(uuid::Uuid::from_str(\n \"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\",\n )?)\n .await?;\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn delete<'a>(&'a self, id: uuid::Uuid) -> Result<(), crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::DELETE,
format!(
"{}/{}",
self.client.base_url,
"user/projects/{id}".replace("{id}", &format!("{}", id))
),
);
req = req.bearer_auth(&self.client.token);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Ok(())
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Download one of the authenticated user's projects as a tar \
archive.\n\n**Parameters:**\n\n- `id: uuid::Uuid`: The identifier. \
(required)\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn \
example_projects_download() -> anyhow::Result<()> {\n let client = \
kittycad::Client::new_from_env();\n client\n .projects()\n \
.download(uuid::Uuid::from_str(\n \
\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\",\n )?)\n .await?;\n \
Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn download<'a>(&'a self, id: uuid::Uuid) -> Result<(), crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!(
"{}/{}",
self.client.base_url,
"user/projects/{id}/download".replace("{id}", &format!("{}", id))
),
);
req = req.bearer_auth(&self.client.token);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Ok(())
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Submit one of the authenticated user's projects for public \
review.\n\n**Parameters:**\n\n- `id: uuid::Uuid`: The identifier. \
(required)\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn \
example_projects_publish() -> anyhow::Result<()> {\n let client = \
kittycad::Client::new_from_env();\n let result: kittycad::types::ProjectResponse = \
client\n .projects()\n .publish(uuid::Uuid::from_str(\n \
\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\",\n )?)\n .await?;\n \
println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn publish<'a>(
&'a self,
id: uuid::Uuid,
) -> Result<crate::types::ProjectResponse, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!(
"{}/{}",
self.client.base_url,
"user/projects/{id}/publish".replace("{id}", &format!("{}", id))
),
);
req = req.bearer_auth(&self.client.token);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "List share links for one of the authenticated user's \
projects.\n\n**Parameters:**\n\n- `id: uuid::Uuid`: The identifier. \
(required)\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn \
example_projects_list_share_links() -> anyhow::Result<()> {\n let client = \
kittycad::Client::new_from_env();\n let result: \
Vec<kittycad::types::ProjectShareLinkResponse> = client\n .projects()\n \
.list_share_links(uuid::Uuid::from_str(\n \
\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\",\n )?)\n .await?;\n \
println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn list_share_links<'a>(
&'a self,
id: uuid::Uuid,
) -> Result<Vec<crate::types::ProjectShareLinkResponse>, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!(
"{}/{}",
self.client.base_url,
"user/projects/{id}/share-links".replace("{id}", &format!("{}", id))
),
);
req = req.bearer_auth(&self.client.token);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Create a share link for one of the authenticated user's \
projects.\n\n**Parameters:**\n\n- `id: uuid::Uuid`: The identifier. \
(required)\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn \
example_projects_create_share_link() -> anyhow::Result<()> {\n let client = \
kittycad::Client::new_from_env();\n let result: \
kittycad::types::ProjectShareLinkResponse = client\n .projects()\n \
.create_share_link(\n \
uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n \
&kittycad::types::CreateProjectShareLinkRequest {\n access_mode: \
Some(kittycad::types::KclProjectShareLinkAccessMode::OrganizationOnly),\n \
},\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn create_share_link<'a>(
&'a self,
id: uuid::Uuid,
body: &crate::types::CreateProjectShareLinkRequest,
) -> Result<crate::types::ProjectShareLinkResponse, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!(
"{}/{}",
self.client.base_url,
"user/projects/{id}/share-links".replace("{id}", &format!("{}", id))
),
);
req = req.bearer_auth(&self.client.token);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Delete one share link for one of the authenticated user's \
projects.\n\n**Parameters:**\n\n- `id: uuid::Uuid`: Project identifier. (required)\n- \
`key: &'astr`: Share-link key. (required)\n\n```rust,no_run\nuse \
std::str::FromStr;\nasync fn example_projects_delete_share_link() -> \
anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n \
client\n .projects()\n .delete_share_link(\n \
uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n \
\"some-string\",\n )\n .await?;\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn delete_share_link<'a>(
&'a self,
id: uuid::Uuid,
key: &'a str,
) -> Result<(), crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::DELETE,
format!(
"{}/{}",
self.client.base_url,
"user/projects/{id}/share-links/{key}"
.replace("{id}", &format!("{}", id))
.replace("{key}", key)
),
);
req = req.bearer_auth(&self.client.token);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Ok(())
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
}