kittycad 0.5.6

A fully generated & opinionated API client for the KittyCAD API.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
use anyhow::Result;

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

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

    #[doc = "Get CAD file bounding box.\n\nImport the CAD file into the modeling engine and \
             calculate its bounding box.\n\nThis endpoint returns the axis-aligned bounding box as \
             a center and dimensions in the output units, using KittyCAD coordinates (+Z up, -Y \
             forward).\n\nThis operation is always performed asynchronously, regardless of file \
             size. The request returns the `id` of the operation. Use this `id` to get the status \
             and bounding box from the `/async/operations/{id}` endpoint.\n\n**Parameters:**\n\n- \
             `output_unit: Option<crate::types::UnitLength>`: The output unit for the bounding \
             box.\n- `src_format: crate::types::FileImportFormat`: The format of the file. \
             (required)\n\n```rust,no_run\nasync fn example_file_create_bounding_box() -> \
             anyhow::Result<()> {\n    let client = kittycad::Client::new_from_env();\n    let \
             result: kittycad::types::FileBoundingBox = client\n        .file()\n        \
             .create_bounding_box(\n            Some(kittycad::types::UnitLength::M),\n            \
             kittycad::types::FileImportFormat::Parasolid,\n            \
             &bytes::Bytes::from(\"some-string\"),\n        )\n        .await?;\n    \
             println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
    #[tracing::instrument]
    pub async fn create_bounding_box<'a>(
        &'a self,
        output_unit: Option<crate::types::UnitLength>,
        src_format: crate::types::FileImportFormat,
        body: &bytes::Bytes,
    ) -> Result<crate::types::FileBoundingBox, crate::types::error::Error> {
        let mut req = self.client.client.request(
            http::Method::POST,
            format!("{}/{}", self.client.base_url, "file/bounding-box"),
        );
        req = req.bearer_auth(&self.client.token);
        let mut query_params = vec![("src_format", format!("{}", src_format))];
        if let Some(p) = output_unit {
            query_params.push(("output_unit", format!("{}", p)));
        }

        req = req.query(&query_params);
        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 {
            let text = resp.text().await.unwrap_or_default();
            Err(crate::types::error::Error::Server {
                body: text.to_string(),
                status,
            })
        }
    }

    #[doc = "Get CAD file center of mass.\n\nWe assume any file given to us has one consistent unit throughout. We also assume the file is at the proper scale.\n\nThis endpoint returns the cartesian coordinate in the KittyCAD coordinate system (+Z up, -Y forward) using the requested measure units.\n\nIn the future, we will use the units inside the file if they are given and do any conversions if necessary for the calculation. But currently, that is not supported.\n\nGet the center of mass of an object in a CAD file. If the file is larger than 25MB, it will be performed asynchronously.\n\nIf the operation is performed asynchronously, the `id` of the operation will be returned. You can use the `id` returned from the request to get status information about the async operation from the `/async/operations/{id}` endpoint.\n\n**Parameters:**\n\n- `output_unit: Option<crate::types::UnitLength>`: The output unit for the center of mass.\n- `src_format: crate::types::FileImportFormat`: The format of the file. (required)\n\n```rust,no_run\nasync fn example_file_create_center_of_mass() -> anyhow::Result<()> {\n    let client = kittycad::Client::new_from_env();\n    let result: kittycad::types::FileCenterOfMass = client\n        .file()\n        .create_center_of_mass(\n            Some(kittycad::types::UnitLength::M),\n            kittycad::types::FileImportFormat::Parasolid,\n            &bytes::Bytes::from(\"some-string\"),\n        )\n        .await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
    #[tracing::instrument]
    pub async fn create_center_of_mass<'a>(
        &'a self,
        output_unit: Option<crate::types::UnitLength>,
        src_format: crate::types::FileImportFormat,
        body: &bytes::Bytes,
    ) -> Result<crate::types::FileCenterOfMass, crate::types::error::Error> {
        let mut req = self.client.client.request(
            http::Method::POST,
            format!("{}/{}", self.client.base_url, "file/center-of-mass"),
        );
        req = req.bearer_auth(&self.client.token);
        let mut query_params = vec![("src_format", format!("{}", src_format))];
        if let Some(p) = output_unit {
            query_params.push(("output_unit", format!("{}", p)));
        }

        req = req.query(&query_params);
        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 {
            let text = resp.text().await.unwrap_or_default();
            Err(crate::types::error::Error::Server {
                body: text.to_string(),
                status,
            })
        }
    }

    #[doc = "Convert CAD file from one format to another.\n\nThis takes a HTTP multipart body with these fields in any order:\n\n- The input and output format options (as JSON), name is 'body'.  - The files to convert, in raw binary. Must supply filenames.\n\nThis starts a conversion job and returns the `id` of the operation. You can use the `id` returned from the request to get status information about the async operation from the `/async/operations/{id}` endpoint.\n\n```rust,no_run\nasync fn example_file_create_conversion_options() -> anyhow::Result<()> {\n    let client = kittycad::Client::new_from_env();\n    let result: kittycad::types::FileConversion = client\n        .file()\n        .create_conversion_options(\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            &kittycad::types::ConversionParams {\n                output_format: kittycad::types::OutputFormat3D::Fbx {\n                    created: Some(chrono::Utc::now()),\n                    storage: kittycad::types::FbxStorage::Binary,\n                },\n                src_format: kittycad::types::InputFormat3D::Acis {\n                    coords: Some(kittycad::types::System {\n                        forward: kittycad::types::AxisDirectionPair {\n                            axis: kittycad::types::Axis::Z,\n                            direction: kittycad::types::Direction::Negative,\n                        },\n                        up: kittycad::types::AxisDirectionPair {\n                            axis: kittycad::types::Axis::Z,\n                            direction: kittycad::types::Direction::Negative,\n                        },\n                    }),\n                    split_closed_faces: true,\n                },\n            },\n        )\n        .await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
    #[tracing::instrument]
    pub async fn create_conversion_options<'a>(
        &'a self,
        attachments: Vec<crate::types::multipart::Attachment>,
        body: &crate::types::ConversionParams,
    ) -> Result<crate::types::FileConversion, crate::types::error::Error> {
        let mut req = self.client.client.request(
            http::Method::POST,
            format!("{}/{}", self.client.base_url, "file/conversion"),
        );
        req = req.bearer_auth(&self.client.token);
        use std::convert::TryInto;
        let mut form = reqwest::multipart::Form::new();
        let mut json_part = reqwest::multipart::Part::text(serde_json::to_string(&body)?);
        json_part = json_part.file_name(format!("{}.json", "body"));
        json_part = json_part.mime_str("application/json")?;
        form = form.part("body", json_part);
        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 = "Convert CAD file with defaults.\n\nIf you wish to specify the conversion options, use \
             the `/file/conversion` endpoint instead.\n\nConvert a CAD file from one format to \
             another. If the file being converted is larger than 25MB, it will be performed \
             asynchronously.\n\nIf the conversion is performed synchronously, the contents of the \
             converted file (`output`) will be returned as a base64 encoded string.\n\nIf the \
             operation is performed asynchronously, the `id` of the operation will be returned. \
             You can use the `id` returned from the request to get status information about the \
             async operation from the `/async/operations/{id}` endpoint.\n\n**Parameters:**\n\n- \
             `output_format: crate::types::FileExportFormat`: The format the file should be \
             converted to. (required)\n- `src_format: crate::types::FileImportFormat`: The format \
             of the file to convert. (required)\n\n```rust,no_run\nasync fn \
             example_file_create_conversion() -> anyhow::Result<()> {\n    let client = \
             kittycad::Client::new_from_env();\n    let result: kittycad::types::FileConversion = \
             client\n        .file()\n        .create_conversion(\n            \
             kittycad::types::FileExportFormat::Ply,\n            \
             kittycad::types::FileImportFormat::Parasolid,\n            \
             &bytes::Bytes::from(\"some-string\"),\n        )\n        .await?;\n    \
             println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
    #[tracing::instrument]
    pub async fn create_conversion<'a>(
        &'a self,
        output_format: crate::types::FileExportFormat,
        src_format: crate::types::FileImportFormat,
        body: &bytes::Bytes,
    ) -> Result<crate::types::FileConversion, crate::types::error::Error> {
        let mut req = self.client.client.request(
            http::Method::POST,
            format!(
                "{}/{}",
                self.client.base_url,
                "file/conversion/{src_format}/{output_format}"
                    .replace("{output_format}", &format!("{}", output_format))
                    .replace("{src_format}", &format!("{}", src_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 {
            let text = resp.text().await.unwrap_or_default();
            Err(crate::types::error::Error::Server {
                body: text.to_string(),
                status,
            })
        }
    }

    #[doc = "Get CAD file density.\n\nWe assume any file given to us has one consistent unit \
             throughout. We also assume the file is at the proper scale.\n\nThis endpoint assumes \
             if you are giving a material mass in a specific mass units, we return a density in \
             mass unit per cubic measure unit.\n\nIn the future, we will use the units inside the \
             file if they are given and do any conversions if necessary for the calculation. But \
             currently, that is not supported.\n\nGet the density of an object in a CAD file. If \
             the file is larger than 25MB, it will be performed asynchronously.\n\nIf the \
             operation is performed asynchronously, the `id` of the operation will be returned. \
             You can use the `id` returned from the request to get status information about the \
             async operation from the `/async/operations/{id}` endpoint.\n\n**Parameters:**\n\n- \
             `material_mass: f64`: The material mass. (required)\n- `material_mass_unit: \
             Option<crate::types::UnitMass>`: The unit of the material mass.\n- `output_unit: \
             Option<crate::types::UnitDensity>`: The output unit for the density.\n- `src_format: \
             crate::types::FileImportFormat`: The format of the file. \
             (required)\n\n```rust,no_run\nasync fn example_file_create_density() -> \
             anyhow::Result<()> {\n    let client = kittycad::Client::new_from_env();\n    let \
             result: kittycad::types::FileDensity = client\n        .file()\n        \
             .create_density(\n            3.14 as f64,\n            \
             Some(kittycad::types::UnitMass::Kg),\n            \
             Some(kittycad::types::UnitDensity::KgM3),\n            \
             kittycad::types::FileImportFormat::Parasolid,\n            \
             &bytes::Bytes::from(\"some-string\"),\n        )\n        .await?;\n    \
             println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
    #[tracing::instrument]
    pub async fn create_density<'a>(
        &'a self,
        material_mass: f64,
        material_mass_unit: Option<crate::types::UnitMass>,
        output_unit: Option<crate::types::UnitDensity>,
        src_format: crate::types::FileImportFormat,
        body: &bytes::Bytes,
    ) -> Result<crate::types::FileDensity, crate::types::error::Error> {
        let mut req = self.client.client.request(
            http::Method::POST,
            format!("{}/{}", self.client.base_url, "file/density"),
        );
        req = req.bearer_auth(&self.client.token);
        let mut query_params = vec![
            ("material_mass", format!("{}", material_mass)),
            ("src_format", format!("{}", src_format)),
        ];
        if let Some(p) = material_mass_unit {
            query_params.push(("material_mass_unit", format!("{}", p)));
        }

        if let Some(p) = output_unit {
            query_params.push(("output_unit", format!("{}", p)));
        }

        req = req.query(&query_params);
        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 {
            let text = resp.text().await.unwrap_or_default();
            Err(crate::types::error::Error::Server {
                body: text.to_string(),
                status,
            })
        }
    }

    #[doc = "Get CAD file mass.\n\nWe assume any file given to us has one consistent unit throughout. We also assume the file is at the proper scale.\n\nThis endpoint assumes if you are giving a material density in a specific mass unit per cubic measure unit, we return a mass in mass units. The same mass units as passed in the material density.\n\nIn the future, we will use the units inside the file if they are given and do any conversions if necessary for the calculation. But currently, that is not supported.\n\nGet the mass of an object in a CAD file. If the file is larger than 25MB, it will be performed asynchronously.\n\nIf the operation is performed asynchronously, the `id` of the operation will be returned. You can use the `id` returned from the request to get status information about the async operation from the `/async/operations/{id}` endpoint.\n\n**Parameters:**\n\n- `material_density: f64`: The material density. (required)\n- `material_density_unit: Option<crate::types::UnitDensity>`: The unit of the material density.\n- `output_unit: Option<crate::types::UnitMass>`: The output unit for the mass.\n- `src_format: crate::types::FileImportFormat`: The format of the file. (required)\n\n```rust,no_run\nasync fn example_file_create_mass() -> anyhow::Result<()> {\n    let client = kittycad::Client::new_from_env();\n    let result: kittycad::types::FileMass = client\n        .file()\n        .create_mass(\n            3.14 as f64,\n            Some(kittycad::types::UnitDensity::KgM3),\n            Some(kittycad::types::UnitMass::Kg),\n            kittycad::types::FileImportFormat::Parasolid,\n            &bytes::Bytes::from(\"some-string\"),\n        )\n        .await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
    #[tracing::instrument]
    pub async fn create_mass<'a>(
        &'a self,
        material_density: f64,
        material_density_unit: Option<crate::types::UnitDensity>,
        output_unit: Option<crate::types::UnitMass>,
        src_format: crate::types::FileImportFormat,
        body: &bytes::Bytes,
    ) -> Result<crate::types::FileMass, crate::types::error::Error> {
        let mut req = self.client.client.request(
            http::Method::POST,
            format!("{}/{}", self.client.base_url, "file/mass"),
        );
        req = req.bearer_auth(&self.client.token);
        let mut query_params = vec![
            ("material_density", format!("{}", material_density)),
            ("src_format", format!("{}", src_format)),
        ];
        if let Some(p) = material_density_unit {
            query_params.push(("material_density_unit", format!("{}", p)));
        }

        if let Some(p) = output_unit {
            query_params.push(("output_unit", format!("{}", p)));
        }

        req = req.query(&query_params);
        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 {
            let text = resp.text().await.unwrap_or_default();
            Err(crate::types::error::Error::Server {
                body: text.to_string(),
                status,
            })
        }
    }

    #[doc = "Get CAD file surface area.\n\nWe assume any file given to us has one consistent unit \
             throughout. We also assume the file is at the proper scale.\n\nThis endpoint returns \
             the square measure units.\n\nIn the future, we will use the units inside the file if \
             they are given and do any conversions if necessary for the calculation. But \
             currently, that is not supported.\n\nGet the surface area of an object in a CAD file. \
             If the file is larger than 25MB, it will be performed asynchronously.\n\nIf the \
             operation is performed asynchronously, the `id` of the operation will be returned. \
             You can use the `id` returned from the request to get status information about the \
             async operation from the `/async/operations/{id}` endpoint.\n\n**Parameters:**\n\n- \
             `output_unit: Option<crate::types::UnitArea>`: The output unit for the surface \
             area.\n- `src_format: crate::types::FileImportFormat`: The format of the file. \
             (required)\n\n```rust,no_run\nasync fn example_file_create_surface_area() -> \
             anyhow::Result<()> {\n    let client = kittycad::Client::new_from_env();\n    let \
             result: kittycad::types::FileSurfaceArea = client\n        .file()\n        \
             .create_surface_area(\n            Some(kittycad::types::UnitArea::Km2),\n            \
             kittycad::types::FileImportFormat::Parasolid,\n            \
             &bytes::Bytes::from(\"some-string\"),\n        )\n        .await?;\n    \
             println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
    #[tracing::instrument]
    pub async fn create_surface_area<'a>(
        &'a self,
        output_unit: Option<crate::types::UnitArea>,
        src_format: crate::types::FileImportFormat,
        body: &bytes::Bytes,
    ) -> Result<crate::types::FileSurfaceArea, crate::types::error::Error> {
        let mut req = self.client.client.request(
            http::Method::POST,
            format!("{}/{}", self.client.base_url, "file/surface-area"),
        );
        req = req.bearer_auth(&self.client.token);
        let mut query_params = vec![("src_format", format!("{}", src_format))];
        if let Some(p) = output_unit {
            query_params.push(("output_unit", format!("{}", p)));
        }

        req = req.query(&query_params);
        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 {
            let text = resp.text().await.unwrap_or_default();
            Err(crate::types::error::Error::Server {
                body: text.to_string(),
                status,
            })
        }
    }

    #[doc = "Get CAD file volume.\n\nWe assume any file given to us has one consistent unit \
             throughout. We also assume the file is at the proper scale.\n\nThis endpoint returns \
             the cubic measure units.\n\nIn the future, we will use the units inside the file if \
             they are given and do any conversions if necessary for the calculation. But \
             currently, that is not supported.\n\nGet the volume of an object in a CAD file. If \
             the file is larger than 25MB, it will be performed asynchronously.\n\nIf the \
             operation is performed asynchronously, the `id` of the operation will be returned. \
             You can use the `id` returned from the request to get status information about the \
             async operation from the `/async/operations/{id}` endpoint.\n\n**Parameters:**\n\n- \
             `output_unit: Option<crate::types::UnitVolume>`: The output unit for the volume.\n- \
             `src_format: crate::types::FileImportFormat`: The format of the file. \
             (required)\n\n```rust,no_run\nasync fn example_file_create_volume() -> \
             anyhow::Result<()> {\n    let client = kittycad::Client::new_from_env();\n    let \
             result: kittycad::types::FileVolume = client\n        .file()\n        \
             .create_volume(\n            Some(kittycad::types::UnitVolume::Usfloz),\n            \
             kittycad::types::FileImportFormat::Parasolid,\n            \
             &bytes::Bytes::from(\"some-string\"),\n        )\n        .await?;\n    \
             println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
    #[tracing::instrument]
    pub async fn create_volume<'a>(
        &'a self,
        output_unit: Option<crate::types::UnitVolume>,
        src_format: crate::types::FileImportFormat,
        body: &bytes::Bytes,
    ) -> Result<crate::types::FileVolume, crate::types::error::Error> {
        let mut req = self.client.client.request(
            http::Method::POST,
            format!("{}/{}", self.client.base_url, "file/volume"),
        );
        req = req.bearer_auth(&self.client.token);
        let mut query_params = vec![("src_format", format!("{}", src_format))];
        if let Some(p) = output_unit {
            query_params.push(("output_unit", format!("{}", p)));
        }

        req = req.query(&query_params);
        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 {
            let text = resp.text().await.unwrap_or_default();
            Err(crate::types::error::Error::Server {
                body: text.to_string(),
                status,
            })
        }
    }
}