mirror of
https://github.com/dathere/ckanaction.git
synced 2025-11-09 14:19:49 +00:00
feat: add create actions and more examples in README
This commit is contained in:
parent
d3217aad28
commit
933c050c98
4 changed files with 667 additions and 5 deletions
45
README.md
45
README.md
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
Rust library crate to access CKAN Action API endpoints through Rust builders. Based on the CKAN Action API v3. Endpoints are expected to return with an output of type `serde_json::Value`.
|
||||
|
||||
## Example
|
||||
## Examples
|
||||
|
||||
Run `/status_show` endpoint for a CKAN instance and print the output:
|
||||
|
||||
```rust
|
||||
use dotenvy::dotenv;
|
||||
|
|
@ -26,6 +28,47 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
}
|
||||
```
|
||||
|
||||
> The following examples won't include the boilerplate code.
|
||||
|
||||
List packages:
|
||||
|
||||
```rust
|
||||
let result = ckan.package_list().call().await?;
|
||||
println!("{result:#?}");
|
||||
```
|
||||
|
||||
Create a new package (dataset) with custom fields:
|
||||
|
||||
```rust
|
||||
let custom_fields = serde_json::json!({
|
||||
"data_contact_email": "support@dathere.com",
|
||||
"update_frequency": "daily",
|
||||
"related_resources": [],
|
||||
});
|
||||
let result = ckan.package_create()
|
||||
.name("my-new-package".to_string())
|
||||
.custom_fields(custom_fields)
|
||||
.private(false)
|
||||
.call()
|
||||
.await?;
|
||||
println!("{result:#?}");
|
||||
```
|
||||
|
||||
Create a new resource with a new file from a file path:
|
||||
|
||||
```rust
|
||||
let path_buf = current_dir()?.join("data.csv");
|
||||
let result = ckan
|
||||
.resource_create()
|
||||
.package_id("3mz0qhbb-cdb0-ewst-x7c0-casnkwv0edub".to_string())
|
||||
.name("My new resource".to_string())
|
||||
.format("CSV".to_string())
|
||||
.upload(path_buf)
|
||||
.call()
|
||||
.await?;
|
||||
println!("{result:#?}");
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- Add the `CKAN_API_TOKEN` environment variable to a `.env` file where the program runs to include the token when making requests to the CKAN API.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue