ainoio_agent/lib.rs
1//! [`Aino.io`](https://aino.io) agent for the Rust programming language.
2//!
3//! [`Aino.io`](http://aino.io) is an analytics and monitoring tool for integrated enterprise applications and digital
4//! business processes. Aino.io can help organizations manage, develop, and run the digital parts of their day-to-day
5//! business. Read more from our [web pages](http://aino.io).
6//!
7//! Aino.io works by analyzing transactions between enterprise applications and other pieces of software.
8//! This Agent helps to store data about the transactions to Aino.io platform using Aino.io Data API (version 2.0).
9//! See [API documentation](http://www.aino.io/api) for detailed information about the API.
10//!
11//! #### Example
12//! ```no_run
13//! use std::time::SystemTime;
14//!
15//! // Load the configuration
16//! let config = ainoio_agent::AinoConfig::new()?;
17//!
18//! // Start the Aino agent
19//! // This must be called exactly once before any transactions are sent
20//! ainoio_agent::start(config)?;
21//!
22//! let timestamp = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();
23//!
24//! // Create transaction object
25//! let mut transaction = ainoio_agent::Transaction::new("SAP".to_string(),
26//! "Card Management".to_string(), "Payment".to_string(), ainoio_agent::Status::Success,
27//! timestamp.as_millis(), "flow id".to_string());
28//! transaction.message = Some("Data transfer successful.".to_string());
29//! transaction.payload_type = Some("Product Update".to_string());
30//!
31//! let metadata = ainoio_agent::TransactionMetadata::new("Card API".to_string(), "https://somecardsystem.com".to_string());
32//! transaction.add_metadata(metadata);
33//!
34//! let id = ainoio_agent::TransactionId::new("OrderId".to_string(), vec!["123456".to_string(), "xxasd".to_string()]);
35//! transaction.add_id(id);
36//!
37//! // Add the transaction into the queue, it will be sent after `send_interval' has elapsed at the latests
38//! ainoio_agent::add_transaction(transaction).expect("Failed to add transaction to the send queue.");
39//!
40//! # Ok::<(), ainoio_agent::AinoError>(())
41//! ```
42
43#![warn(missing_docs)]
44#![warn(missing_doc_code_examples)]
45
46#[macro_use]
47extern crate serde_derive;
48#[macro_use]
49extern crate lazy_static;
50
51mod aino_agent;
52mod aino_config;
53mod status;
54mod transaction;
55
56pub use aino_agent::*;
57pub use aino_config::*;
58pub use status::*;
59pub use transaction::*;
60
61use std::error::Error;
62use std::fmt;
63
64/// Error object for [`Aino.io`](https://aino.io) agent
65#[derive(Debug)]
66pub struct AinoError {
67 msg: String,
68}
69
70impl fmt::Display for AinoError {
71 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
72 fmt.write_str(&self.msg)
73 }
74}
75
76impl AinoError {
77 /// Construct a new `AinoError`
78 pub fn new(msg: String) -> Self {
79 AinoError { msg }
80 }
81}
82
83impl Error for AinoError {}