feat: add Rust code examples and support for Rust syntax highlighting
- Added Rust syntax highlighting to the Fence component. - Updated Markdoc functions to clone React elements with unique keys for copy and example sections. - Included Rust code examples for various API endpoints in documentation: - `get_app_by_id` - `get_apps` - `get_apps_by_ids` - `connectivity` - `get_field_by_id` - `get_fields_by_app` - `get_fields_by_ids` - `add_file` - `delete_file_by_id` - `get_file_by_id` - `get_file_info_by_id` - `delete_list_value_by_id` - `save_list_value` - `delete_record_by_id` - `delete_records_by_ids` - `get_record_by_id` - `get_records_by_app` - `get_records_by_ids` - `get_records_by_query` - `save_record` - `get_report_by_id` - `get_reports_by_app`
This commit is contained in:
@@ -56,6 +56,23 @@ print(f'Name: {response.data.app.name}')
|
||||
print(f'href: {response.data.app.href}')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::OnspringClient;
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
let app = client.get_app(195).await?;
|
||||
|
||||
println!(
|
||||
"{}, {}",
|
||||
app.id,
|
||||
app.name.unwrap_or_default()
|
||||
);
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
{% code heading="RESPONSE" defaultLanguage="json" %}
|
||||
|
||||
@@ -66,6 +66,30 @@ for app in response.data.apps:
|
||||
print(f'href: {app.href}')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::{OnspringClient, PagingRequest};
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
let paging = PagingRequest {
|
||||
page_number: 1,
|
||||
page_size: 10,
|
||||
};
|
||||
|
||||
let response = client.list_apps(Some(paging)).await?;
|
||||
|
||||
for app in response.items.unwrap_or_default() {
|
||||
println!(
|
||||
"{}, {}",
|
||||
app.id,
|
||||
app.name.unwrap_or_default()
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
{% code heading="RESPONSE" defaultLanguage="json" %}
|
||||
|
||||
@@ -67,6 +67,26 @@ for app in response.data.apps:
|
||||
print(f'href: {app.href}')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::OnspringClient;
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
let ids = vec![8, 79, 137, 193, 183];
|
||||
let response = client.batch_get_apps(&ids).await?;
|
||||
|
||||
for app in response.items.unwrap_or_default() {
|
||||
println!(
|
||||
"{}, {}",
|
||||
app.id,
|
||||
app.name.unwrap_or_default()
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
{% code heading="RESPONSE" defaultLanguage="json" %}
|
||||
|
||||
@@ -56,4 +56,16 @@ else:
|
||||
print('Attempt to connect failed')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::OnspringClient;
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
client.ping().await?;
|
||||
println!("Connected to the Onspring API successfully.");
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
@@ -54,6 +54,19 @@ print(f'Status Code: {response.statusCode}')
|
||||
print(f'Field Id: {response.data.id}')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::OnspringClient;
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
let field = client.get_field(6986).await?;
|
||||
|
||||
println!("Field Id: {}", field.id);
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
{% code heading="RESPONSE" defaultLanguage="json" %}
|
||||
|
||||
@@ -64,6 +64,26 @@ for field in response.data.fields:
|
||||
print(f'Field Id: {field.id}')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::{OnspringClient, PagingRequest};
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
let paging = PagingRequest {
|
||||
page_number: 1,
|
||||
page_size: 10,
|
||||
};
|
||||
|
||||
let response = client.list_fields(195, Some(paging)).await?;
|
||||
|
||||
for field in response.items.unwrap_or_default() {
|
||||
println!("Field Id: {}", field.id);
|
||||
}
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
{% code heading="RESPONSE" defaultLanguage="json" %}
|
||||
|
||||
@@ -63,6 +63,22 @@ for field in response.data.fields:
|
||||
print(f'Field Id: {field.id}')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::OnspringClient;
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
let ids = vec![6983, 6986, 6987, 6985, 6984];
|
||||
let response = client.batch_get_fields(&ids).await?;
|
||||
|
||||
for field in response.items.unwrap_or_default() {
|
||||
println!("Field Id: {}", field.id);
|
||||
}
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
{% code heading="RESPONSE" defaultLanguage="json" %}
|
||||
|
||||
@@ -96,6 +96,31 @@ print(f'Status Code: {response.statusCode}')
|
||||
print(f'File Id: {response.data.id}')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::{OnspringClient, SaveFileRequest};
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
let request = SaveFileRequest {
|
||||
record_id: 140,
|
||||
field_id: 6989,
|
||||
notes: Some(
|
||||
"Updating record with attachment.".to_string()
|
||||
),
|
||||
modified_date: Some(chrono::Utc::now()),
|
||||
file_name: "test-attachment.txt".to_string(),
|
||||
file_data: std::fs::read("test-attachment.txt")?,
|
||||
content_type: "text/plain".to_string(),
|
||||
};
|
||||
|
||||
let response = client.upload_file(request).await?;
|
||||
|
||||
println!("New File Id is: {}", response.id);
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
{% code heading="RESPONSE" defaultLanguage="json" %}
|
||||
|
||||
@@ -60,4 +60,17 @@ else:
|
||||
print('Error deleting file')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::OnspringClient;
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
client.delete_file(140, 6989, 1904).await?;
|
||||
|
||||
println!("File deleted successfully");
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
@@ -76,6 +76,25 @@ with open(filePath, "wb") as file:
|
||||
print(f'File Location: {filePath}')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::OnspringClient;
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
let file = client
|
||||
.get_file(1, 6989, 89)
|
||||
.await?;
|
||||
|
||||
println!("File Name: {:?}", file.file_name);
|
||||
println!("Content Type: {:?}", file.content_type);
|
||||
println!("Size: {} bytes", file.data.len());
|
||||
|
||||
std::fs::write(&file.file_name, &file.data)?;
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
{% code heading="RESPONSE" defaultLanguage="text" %}
|
||||
|
||||
@@ -53,6 +53,22 @@ print(f'Name: {response.data.fileInfo.name}')
|
||||
print(f'Content Type: {response.data.fileInfo.contentType}')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::OnspringClient;
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
let info = client
|
||||
.get_file_info(1, 6989, 89)
|
||||
.await?;
|
||||
|
||||
println!("Name: {:?}", info.name);
|
||||
println!("Content Type: {:?}", info.content_type);
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
{% code heading="RESPONSE" defaultLanguage="json" %}
|
||||
|
||||
@@ -67,4 +67,22 @@ print(f'Status Code: {response.statusCode}')
|
||||
print(f'Message: {response.message}')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::OnspringClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
let item_id = Uuid::parse_str(
|
||||
"e3371dbf-b557-4a31-b32f-33c0265d2a59"
|
||||
)?;
|
||||
|
||||
client.delete_list_item(906, item_id).await?;
|
||||
|
||||
println!("List item deleted");
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
@@ -89,6 +89,28 @@ print(f'Status Code: {response.statusCode}')
|
||||
print(f'Id: {response.data.id}')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::{OnspringClient, SaveListItemRequest};
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
let request = SaveListItemRequest {
|
||||
id: None,
|
||||
name: "Not Started".to_string(),
|
||||
numeric_value: Some(0.0),
|
||||
color: Some("#ffffff".to_string()),
|
||||
};
|
||||
|
||||
let response = client
|
||||
.save_list_item(906, request)
|
||||
.await?;
|
||||
|
||||
println!("Id: {}", response.id);
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
{% code heading="RESPONSE" defaultLanguage="json" %}
|
||||
|
||||
@@ -58,4 +58,17 @@ print(f'Status Code: {response.statusCode}')
|
||||
print(f'Message: {response.message}')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::OnspringClient;
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
client.delete_record(195, 140).await?;
|
||||
|
||||
println!("Record deleted");
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
@@ -73,4 +73,22 @@ print(f'Status Code: {response.statusCode}')
|
||||
print(f'Message: {response.message}')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::{OnspringClient, BatchDeleteRecordsRequest};
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
let request = BatchDeleteRecordsRequest {
|
||||
app_id: 195,
|
||||
record_ids: vec![138, 139],
|
||||
};
|
||||
|
||||
client.batch_delete_records(request).await?;
|
||||
|
||||
println!("Records deleted successfully");
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
@@ -70,6 +70,36 @@ for field in response.data.fields:
|
||||
print(f'Value: {field.GetResultValueString()}')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::OnspringClient;
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
let record = client
|
||||
.get_record(195, 1, None, None)
|
||||
.await?;
|
||||
|
||||
println!(
|
||||
"AppId: {}, RecordId: {}",
|
||||
record.app_id,
|
||||
record.record_id
|
||||
);
|
||||
|
||||
if let Some(field_data) = record.field_data {
|
||||
for field in field_data {
|
||||
println!(
|
||||
"FieldId: {}, Type: {:?}, Value: {}",
|
||||
field.field_id,
|
||||
field.value_type,
|
||||
field.value
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
{% code heading="RESPONSE" defaultLanguage="json" %}
|
||||
|
||||
@@ -71,6 +71,32 @@ for record in response.data.records:
|
||||
print(f'Value: {field.GetResultValueString()}')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::{OnspringClient, PagingRequest};
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
let paging = PagingRequest {
|
||||
page_number: 1,
|
||||
page_size: 10,
|
||||
};
|
||||
|
||||
let response = client
|
||||
.list_records(195, Some(paging), None, None)
|
||||
.await?;
|
||||
|
||||
for record in response.items.unwrap_or_default() {
|
||||
println!(
|
||||
"AppId: {}, RecordId: {}",
|
||||
record.app_id,
|
||||
record.record_id
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
{% code heading="RESPONSE" defaultLanguage="json" %}
|
||||
|
||||
@@ -100,6 +100,34 @@ for record in response.data.records:
|
||||
print(f'Value: {field.GetResultValueString()}')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::{OnspringClient, BatchGetRecordsRequest, DataFormat};
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
let request = BatchGetRecordsRequest {
|
||||
app_id: 195,
|
||||
record_ids: vec![1],
|
||||
field_ids: Some(vec![6983, 6986, 6987, 6985, 6984]),
|
||||
data_format: Some(DataFormat::Raw),
|
||||
};
|
||||
|
||||
let response = client
|
||||
.batch_get_records(request)
|
||||
.await?;
|
||||
|
||||
for record in response.items.unwrap_or_default() {
|
||||
println!(
|
||||
"AppId: {}, RecordId: {}",
|
||||
record.app_id,
|
||||
record.record_id
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
{% code heading="RESPONSE" defaultLanguage="json" %}
|
||||
|
||||
@@ -126,6 +126,34 @@ for record in response.data.records:
|
||||
print(f'Value: {field.GetResultValueString()}')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::{OnspringClient, QueryRecordsRequest, DataFormat};
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
let query = QueryRecordsRequest {
|
||||
app_id: 195,
|
||||
filter: "6983 eq 'Test Task 5'".to_string(),
|
||||
field_ids: Some(vec![6983, 6986, 6987, 6985, 6984]),
|
||||
data_format: Some(DataFormat::Formatted),
|
||||
};
|
||||
|
||||
let response = client
|
||||
.query_records(query, None)
|
||||
.await?;
|
||||
|
||||
for record in response.items.unwrap_or_default() {
|
||||
println!(
|
||||
"AppId: {}, RecordId: {}",
|
||||
record.app_id,
|
||||
record.record_id
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
{% code heading="RESPONSE" defaultLanguage="json" %}
|
||||
|
||||
@@ -123,6 +123,48 @@ for warning in response.data.warnings:
|
||||
print(f'Warning: {warning}')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::{OnspringClient, SaveRecordRequest};
|
||||
use std::collections::HashMap;
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
let mut fields = HashMap::new();
|
||||
fields.insert(
|
||||
"6983".to_string(),
|
||||
serde_json::json!("A New Test Task"),
|
||||
);
|
||||
fields.insert(
|
||||
"6984".to_string(),
|
||||
serde_json::json!("This is a test task."),
|
||||
);
|
||||
fields.insert(
|
||||
"6985".to_string(),
|
||||
serde_json::json!("12/25/2021"),
|
||||
);
|
||||
fields.insert(
|
||||
"6986".to_string(),
|
||||
serde_json::json!("4118d53a-9121-4345-8682-07f23d606daa"),
|
||||
);
|
||||
fields.insert(
|
||||
"6987".to_string(),
|
||||
serde_json::json!([4]),
|
||||
);
|
||||
|
||||
let request = SaveRecordRequest {
|
||||
app_id: 195,
|
||||
record_id: None,
|
||||
fields,
|
||||
};
|
||||
|
||||
let response = client.save_record(request).await?;
|
||||
|
||||
println!("New Record Id is: {}", response.id);
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
{% code heading="Response" defaultLanguage="json" %}
|
||||
|
||||
@@ -64,6 +64,31 @@ for row in response.data.rows:
|
||||
print(f'Record Id {row.recordId}: {", ".join([str(cell) for cell in row.cells])}')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::OnspringClient;
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
let data = client
|
||||
.get_report(613, None, None)
|
||||
.await?;
|
||||
|
||||
println!("Columns: {:?}", data.columns);
|
||||
|
||||
if let Some(rows) = data.rows {
|
||||
for row in rows {
|
||||
println!(
|
||||
"Record Id {:?}: {:?}",
|
||||
row.record_id,
|
||||
row.cells
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
{% code heading="RESPONSE" defaultLanguage="json" %}
|
||||
|
||||
@@ -64,6 +64,33 @@ for report in response.data.reports:
|
||||
print(f' Description: {report.description}')
|
||||
```
|
||||
|
||||
```rust
|
||||
use onspring::{OnspringClient, PagingRequest};
|
||||
|
||||
let client = OnspringClient::builder(
|
||||
"000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
|
||||
)
|
||||
.build();
|
||||
|
||||
let paging = PagingRequest {
|
||||
page_number: 1,
|
||||
page_size: 10,
|
||||
};
|
||||
|
||||
let response = client
|
||||
.list_reports(195, Some(paging))
|
||||
.await?;
|
||||
|
||||
for report in response.items.unwrap_or_default() {
|
||||
println!(
|
||||
"{}, {}, {}",
|
||||
report.id,
|
||||
report.app_id,
|
||||
report.name.unwrap_or_default()
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
{% /code %}
|
||||
|
||||
{% code heading="RESPONSE" defaultLanguage="json" %}
|
||||
|
||||
Reference in New Issue
Block a user