1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
//! # Threema Gateway SDK for Rust //! //! [![CircleCI](https://circleci.com/gh/dbrgn/threema-gateway-rs/tree/master.svg?style=shield)](https://circleci.com/gh/dbrgn/threema-gateway-rs/tree/master) //! [![Crates.io](https://img.shields.io/crates/v/threema-gateway.svg?maxAge=3600)](https://crates.io/crates/threema-gateway) //! [![Rust](https://img.shields.io/badge/rust-1.31%2B-blue.svg?maxAge=3600)](https://github.com/dbrgn/threema-gateway-rs) //! //! This library makes it easy to use the [Threema //! Gateway](https://gateway.threema.ch/) from Rust programs. //! //! Documentation of the HTTP API can be found at //! [gateway.threema.ch](https://gateway.threema.ch/de/developer/api). //! //! ## Example: Send simple (transport encrypted) message //! //! ```no_run //! use threema_gateway::{ApiBuilder, Recipient}; //! //! let from = "*YOUR_ID"; //! let to = Recipient::new_email("user@example.com"); //! let secret = "your-gateway-secret"; //! let text = "Very secret message!"; //! //! // Send //! let api = ApiBuilder::new(from, secret).into_simple(); //! match api.send(&to, &text) { //! Ok(msg_id) => println!("Sent. Message id is {}.", msg_id), //! Err(e) => println!("Could not send message: {:?}", e), //! } //! ``` //! //! ## Example: Send end-to-end encrypted message //! //! ```no_run //! use threema_gateway::{ApiBuilder, RecipientKey}; //! //! let from = "*YOUR_ID"; //! let to = "ECHOECHO"; //! let secret = "your-gateway-secret"; //! let private_key = "your-private-key"; //! let text = "Very secret message!"; //! //! // Create E2eApi instance //! let api = ApiBuilder::new(from, secret) //! .with_private_key_str(private_key) //! .and_then(|builder| builder.into_e2e()) //! .unwrap(); //! //! // Fetch public key //! // Note: In a real application, you should cache the public key //! let public_key = api.lookup_pubkey(to).unwrap(); //! //! // Encrypt //! let recipient_key = RecipientKey::from_str(&public_key).unwrap(); //! let encrypted = api.encrypt_text_msg(text, &recipient_key); //! //! // Send //! match api.send(&to, &encrypted) { //! Ok(msg_id) => println!("Sent. Message id is {}.", msg_id), //! Err(e) => println!("Could not send message: {:?}", e), //! } //! ``` //! //! For more examples, see the //! [`examples/`](https://github.com/dbrgn/threema-gateway-rs/tree/master/examples) directory. #[macro_use] extern crate log; mod api; mod connection; mod crypto; mod lookup; mod types; pub mod errors; pub use crate::api::{ApiBuilder, E2eApi, SimpleApi}; pub use crate::connection::{Recipient}; pub use crate::crypto::{EncryptedMessage, RecipientKey}; pub use crate::lookup::{LookupCriterion, Capabilities}; pub use crate::types::{MessageType, BlobId}; const MSGAPI_URL: &'static str = "https://msgapi.threema.ch"; #[cfg(test)] mod tests { #[test] fn it_works() { } }