Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/deg4uss3r/twrs-sms
A Small Rust library for the Twilio API
https://github.com/deg4uss3r/twrs-sms
Last synced: about 1 month ago
JSON representation
A Small Rust library for the Twilio API
- Host: GitHub
- URL: https://github.com/deg4uss3r/twrs-sms
- Owner: deg4uss3r
- License: apache-2.0
- Created: 2020-01-29T10:42:33.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-29T10:53:49.000Z (almost 5 years ago)
- Last Synced: 2024-11-18T23:59:06.168Z (about 2 months ago)
- Language: Rust
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# twrs_sms
Twilio Rust: a very simple Twilio SMS API library written in Rust
Example:
```rust
use std::env::var;use reqwest::StatusCode;
use twrs_sms;fn main() -> Result<(), twrs_sms::TWRSError> {
let tw_to = var("TW_TO").expect("Error getting $TW_TO from the environment");
let tw_from = var("TW_FROM").expect("Error getting $TW_FROM from the environment");
let tw_sid = var("TW_SID").expect("Error getting $TW_SID from the environment");
let tw_token = var("TW_TOKEN").expect("Error getting $TW_TOKEN from the environment");// Create the request body and encode the message for the API
let t: twrs_sms::TwilioSend = twrs_sms::TwilioSend{To: &tw_to, From: &tw_from, Body: "Hiya"};
let t_s = t.encode().expect("Error converting to url encoded string");// Send the message to the API endpoint
let mut response = twrs_sms::send_message(&tw_sid, &tw_token, t_s)
.expect("Error with HTTP request");
// Server responds with 201 (Created) on the initial response
assert_eq!(StatusCode::from_u16(201).unwrap(), response.status());// Run the loop to make sure the message was delivered
let delivered = twrs_sms::is_delivered(&mut response, &tw_sid, &tw_token).expect("Error SMS not delivered");
// Checking the delivered state, and fail on an error
assert_eq!(delivered, "delivered");Ok(())
}
```