strm_privacy_driver/
lib.rs

1//! # STRMPrivacy rust driver
2//!
3//! this crate provides a convenient driver to authenticate and send events to the
4//! STRMPrivacy api.
5//!
6//! The driver consists out of 2 main components
7//! - `StrmPrivacyClient`: Client to connect to the STRMPrivacy backend
8//! - `StrmPrivacyValue`: Trait to convert structs and schemas into values that the client can send
9//!
10//! ## Generating structure based on a STRMPrivacy schema
11//! When using our `cli` we can generate Rust code based on a `schema` we have created using the following command:
12//! `strm get schema-code <*handle*/*schema_name*/*version*> --language=rust`
13//!
14//! This will generate a rust project with the necessary scripts to generate a new package to be used in your project
15//!
16//! ## Example usage
17//! Using and initializing the STRMPrivacy client to send event data to our api.
18//! ```
19//!     use strm_privacy_driver::{StrmPrivacyClient, StrmStatusCode};
20//! #   use dotenv::dotenv;
21//!     use std::env;
22//!     use strm_privacy_driver::test::demo::{DemoEvent, StrmMeta};
23//!     use strm_privacy_driver::error::Error;
24//!
25//!     #[tokio::main]
26//!     async fn main() -> Result<(), Error> {
27//! #       dotenv().ok();
28//!
29//!         // initialize the env variables
30//!         let client_id = env::var("CLIENT_ID").expect("no CLIENT_ID found in environment");
31//!         let client_secret = env::var("CLIENT_SECRET").expect("no CLIENT_SECRET found in environment");
32//!
33//!         let mut strm_privacy_client = StrmPrivacyClient::default(client_id, client_secret).await?;
34//!
35//!         let event = create_event();
36//!
37//!         // catch specific status_codes and decide what to do
38//!         match strm_privacy_client.send_event(event).await? {
39//!             (StrmStatusCode::NO_CONTENT, _) => {}
40//!             (status_code, message) => {assert!(false)}
41//!         }
42//!
43//!         Ok(())
44//!     }
45//!
46//!     // create new event based on the example schema
47//!     fn create_event() -> DemoEvent {
48//!         DemoEvent {
49//!             strm_meta: StrmMeta {
50//!                 event_contract_ref: "strmprivacy/example/1.3.0".to_string(),
51//!                 nonce: None,
52//!                 timestamp: None,
53//!                 key_link: None,
54//!                 billing_id: None,
55//!                 consent_levels: vec![0],
56//!             },
57//!             unique_identifier: Some("unique".to_string()),
58//!             consistent_value: "consistent".to_string(),
59//!             some_sensitive_value: Some("sensitive".to_string()),
60//!             not_sensitive_value: Some("not sensitive".to_string()),
61//!         }
62//!     }
63//! ```
64
65#[macro_use]
66extern crate serde;
67
68mod auth;
69mod client;
70pub mod error;
71pub(crate) mod strm_privacy_client;
72pub(crate) mod strm_privacy_value;
73pub mod test;
74
75pub use strm_privacy_client::StrmPrivacyClient;
76pub use strm_privacy_client::StrmPrivacyResponse;
77pub use strm_privacy_client::StrmStatusCode;
78pub use strm_privacy_value::StrmPrivacyValue;