mirror of
https://github.com/dathere/ckanaction.git
synced 2025-11-09 14:19:49 +00:00
feat: ckanaction crate implementation with GET actions
This commit is contained in:
commit
d0c36b55c6
6 changed files with 3081 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
/target
|
||||||
|
.env
|
||||||
1743
Cargo.lock
generated
Normal file
1743
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
12
Cargo.toml
Normal file
12
Cargo.toml
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
[package]
|
||||||
|
name = "ckanaction"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bon = "3.6.3"
|
||||||
|
dotenvy = "0.15.7"
|
||||||
|
reqwest = { version = "0.12.15", features = ["json"] }
|
||||||
|
serde = "1.0.219"
|
||||||
|
serde_json = "1.0.140"
|
||||||
|
tokio = { version = "1.44.2", features = ["full"] }
|
||||||
32
README.md
Normal file
32
README.md
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
# ckanaction
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
```rust
|
||||||
|
use dotenvy::dotenv;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
// Load environment variables from .env file
|
||||||
|
dotenv()?;
|
||||||
|
|
||||||
|
// Initialize and build CKAN struct
|
||||||
|
let ckan = ckan_dh_rs::CKAN::builder()
|
||||||
|
.url("http://localhost:5000")
|
||||||
|
.token(dotenvy::var("CKAN_API_TOKEN")?)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// Send request to /status_show and print output
|
||||||
|
let status_show = ckan.status_show().await?;
|
||||||
|
println!("{status_show:#?}");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
- If you use a `maybe_fn()` then if you provide `None` it will be ignored and that parameter will not be added to the JSON body. This library assumes `None` would not be provided as a value (since the cases where it is a value is often the default value that the CKAN API already has set for that parameter).
|
||||||
1273
src/lib.rs
Normal file
1273
src/lib.rs
Normal file
File diff suppressed because it is too large
Load diff
19
src/main.rs
Normal file
19
src/main.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
use dotenvy::dotenv;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
// Load environment variables from .env file
|
||||||
|
dotenv()?;
|
||||||
|
|
||||||
|
// Initialize and build CKAN struct
|
||||||
|
let ckan = ckanaction::CKAN::builder()
|
||||||
|
.url("http://localhost:5000")
|
||||||
|
.token(dotenvy::var("CKAN_API_TOKEN")?)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// Send request to /status_show and print output
|
||||||
|
let status_show = ckan.status_show().await?;
|
||||||
|
println!("{status_show:#?}");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue