Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup client and gen #135

Merged
merged 3 commits into from
Jan 31, 2023
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
2 changes: 1 addition & 1 deletion assets/in_step.stp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ISO-10303-21;
HEADER;
FILE_DESCRIPTION (( 'STEP AP203' ),
'1' );
FILE_NAME ('in_test_step_needs_workaround.step'),
FILE_NAME ('in_test_step_needs_workaround.step',
'2021-12-30T05:12:11',
( 'Administrator' ),
( 'Managed by Terraform' ),
Expand Down
140 changes: 102 additions & 38 deletions kittycad.rs.patch.json

Large diffs are not rendered by default.

90 changes: 90 additions & 0 deletions kittycad/src/ai.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use anyhow::Result;

use crate::Client;
#[derive(Clone, Debug)]
pub struct Ai {
pub client: Client,
}

impl Ai {
#[doc(hidden)]
pub fn new(client: Client) -> Self {
Self { client }
}

#[doc = "Generate a 3D model from an image.\n\n**Parameters:**\n\n- `input_format: crate::types::ImageType`: The format of the image being converted. (required)\n- `output_format: crate::types::FileExportFormat`: The format the output file should be converted to. (required)\n\n```rust,no_run\nasync fn example_ai_create_image_to_3d() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::Mesh = client\n .ai()\n .create_image_to_3d(\n kittycad::types::ImageType::Jpg,\n kittycad::types::FileExportFormat::ObjNomtl,\n &bytes::Bytes::from(\"some-string\"),\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn create_image_to_3d<'a>(
&'a self,
input_format: crate::types::ImageType,
output_format: crate::types::FileExportFormat,
body: &bytes::Bytes,
) -> Result<crate::types::Mesh, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
&format!(
"{}/{}",
self.client.base_url,
"ai/image-to-3d/{input_format}/{output_format}"
.replace("{input_format}", &format!("{}", input_format))
.replace("{output_format}", &format!("{}", output_format))
),
);
req = req.bearer_auth(&self.client.token);
req = req.body(body.clone());
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 {
Err(crate::types::error::Error::UnexpectedResponse(resp))
}
}

#[doc = "Generate a 3D model from text.\n\n**Parameters:**\n\n- `output_format: \
crate::types::FileExportFormat`: The format the output file should be converted to. \
(required)\n- `prompt: &'astr`: The prompt for the model. \
(required)\n\n```rust,no_run\nasync fn example_ai_create_text_to_3d() -> \
anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let \
result: kittycad::types::Mesh = client\n .ai()\n \
.create_text_to_3d(kittycad::types::FileExportFormat::Ply, \"some-string\")\n \
.await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn create_text_to_3d<'a>(
&'a self,
output_format: crate::types::FileExportFormat,
prompt: &'a str,
) -> Result<crate::types::Mesh, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
&format!(
"{}/{}",
self.client.base_url,
"ai/text-to-3d/{output_format}"
.replace("{output_format}", &format!("{}", output_format))
),
);
req = req.bearer_auth(&self.client.token);
let query_params = vec![("prompt", prompt.to_string())];
req = req.query(&query_params);
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 {
Err(crate::types::error::Error::UnexpectedResponse(resp))
}
}
}
23 changes: 11 additions & 12 deletions kittycad/src/api_calls.rs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions kittycad/src/api_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl ApiTokens {
Self { client }
}

#[doc = "List API tokens for your user.\n\nThis endpoint requires authentication by any KittyCAD user. It returns the API tokens for the authenticated user.\nThe API tokens are returned in order of creation, with the most recently created API tokens first.\n\n**Parameters:**\n\n- `limit: Option<u32>`: Maximum number of items returned by a single call\n- `page_token: Option<String>`: Token returned by previous call to retrieve the subsequent page\n- `sort_by: Option<crate::types::CreatedAtSortMode>`\n\n```rust,no_run\nuse futures_util::TryStreamExt;\nasync fn example_api_tokens_list_for_user_stream() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let mut api_tokens = client.api_tokens();\n let mut stream = api_tokens.list_for_user_stream(\n Some(4 as u32),\n Some(kittycad::types::CreatedAtSortMode::CreatedAtAscending),\n );\n loop {\n match stream.try_next().await {\n Ok(Some(item)) => {\n println!(\"{:?}\", item);\n }\n Ok(None) => {\n break;\n }\n Err(err) => {\n return Err(err.into());\n }\n }\n }\n\n Ok(())\n}\n```"]
#[doc = "List API tokens for your user.\n\nThis endpoint requires authentication by any KittyCAD user. It returns the API tokens for the authenticated user.\nThe API tokens are returned in order of creation, with the most recently created API tokens first.\n\n**Parameters:**\n\n- `limit: Option<u32>`: Maximum number of items returned by a single call\n- `page_token: Option<String>`: Token returned by previous call to retrieve the subsequent page\n- `sort_by: Option<crate::types::CreatedAtSortMode>`\n\n```rust,no_run\nuse futures_util::TryStreamExt;\nasync fn example_api_tokens_list_for_user_stream() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let mut api_tokens = client.api_tokens();\n let mut stream = api_tokens.list_for_user_stream(\n Some(4 as u32),\n Some(kittycad::types::CreatedAtSortMode::CreatedAtDescending),\n );\n loop {\n match stream.try_next().await {\n Ok(Some(item)) => {\n println!(\"{:?}\", item);\n }\n Ok(None) => {\n break;\n }\n Err(err) => {\n return Err(err.into());\n }\n }\n }\n\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn list_for_user<'a>(
&'a self,
Expand All @@ -25,7 +25,7 @@ impl ApiTokens {
&format!("{}/{}", self.client.base_url, "user/api-tokens"),
);
req = req.bearer_auth(&self.client.token);
let mut query_params = Vec::new();
let mut query_params = vec![];
if let Some(p) = limit {
query_params.push(("limit", format!("{}", p)));
}
Expand Down Expand Up @@ -54,7 +54,7 @@ impl ApiTokens {
}
}

#[doc = "List API tokens for your user.\n\nThis endpoint requires authentication by any KittyCAD user. It returns the API tokens for the authenticated user.\nThe API tokens are returned in order of creation, with the most recently created API tokens first.\n\n**Parameters:**\n\n- `limit: Option<u32>`: Maximum number of items returned by a single call\n- `page_token: Option<String>`: Token returned by previous call to retrieve the subsequent page\n- `sort_by: Option<crate::types::CreatedAtSortMode>`\n\n```rust,no_run\nuse futures_util::TryStreamExt;\nasync fn example_api_tokens_list_for_user_stream() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let mut api_tokens = client.api_tokens();\n let mut stream = api_tokens.list_for_user_stream(\n Some(4 as u32),\n Some(kittycad::types::CreatedAtSortMode::CreatedAtAscending),\n );\n loop {\n match stream.try_next().await {\n Ok(Some(item)) => {\n println!(\"{:?}\", item);\n }\n Ok(None) => {\n break;\n }\n Err(err) => {\n return Err(err.into());\n }\n }\n }\n\n Ok(())\n}\n```"]
#[doc = "List API tokens for your user.\n\nThis endpoint requires authentication by any KittyCAD user. It returns the API tokens for the authenticated user.\nThe API tokens are returned in order of creation, with the most recently created API tokens first.\n\n**Parameters:**\n\n- `limit: Option<u32>`: Maximum number of items returned by a single call\n- `page_token: Option<String>`: Token returned by previous call to retrieve the subsequent page\n- `sort_by: Option<crate::types::CreatedAtSortMode>`\n\n```rust,no_run\nuse futures_util::TryStreamExt;\nasync fn example_api_tokens_list_for_user_stream() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let mut api_tokens = client.api_tokens();\n let mut stream = api_tokens.list_for_user_stream(\n Some(4 as u32),\n Some(kittycad::types::CreatedAtSortMode::CreatedAtDescending),\n );\n loop {\n match stream.try_next().await {\n Ok(Some(item)) => {\n println!(\"{:?}\", item);\n }\n Ok(None) => {\n break;\n }\n Err(err) => {\n return Err(err.into());\n }\n }\n }\n\n Ok(())\n}\n```"]
#[tracing::instrument]
pub fn list_for_user_stream<'a>(
&'a self,
Expand Down
8 changes: 7 additions & 1 deletion kittycad/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ impl Constant {
Self { client }
}

#[doc = "Get a physics constant.\n\n**Parameters:**\n\n- `constant: crate::types::PhysicsConstantName`: The constant to get. (required)\n\n```rust,no_run\nasync fn example_constant_get_physics() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::PhysicsConstant = client\n .constant()\n .get_physics(kittycad::types::PhysicsConstantName::MolarGasConst)\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[doc = "Get a physics constant.\n\n**Parameters:**\n\n- `constant: \
crate::types::PhysicsConstantName`: The constant to get. \
(required)\n\n```rust,no_run\nasync fn example_constant_get_physics() -> \
anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let \
result: kittycad::types::PhysicsConstant = client\n .constant()\n \
.get_physics(kittycad::types::PhysicsConstantName::ME)\n .await?;\n \
println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn get_physics<'a>(
&'a self,
Expand Down
Loading