1 个不稳定版本
使用旧的 Rust 2015
0.1.0 | 2018年4月5日 |
---|
#28 in #语音
23KB
438 代码行,不包括注释
africastalking-rust
A Rust 库,用于与非洲通信 REST API 通信。
安装
cargo install --git https://github.com/rust-nairobi/africastalking-rust
发送消息
extern crate africastalking_gateway;
use std::env;
use africastalking_gateway::AfricasTalkingGateway;
pub fn main() {
let username = "your-account-username";
let apikey = "your-api-key";
let env = "sandbox";
let gway = AfricasTalkingGateway::new(&username, &apikey, env);
println!(
"{}",
gway.send_message(
"+254702xxxxxx",
"hello Rustacean",
None, // these are optional parameters
None,
None,
None,
None,
None
).unwrap()
);
}
获取消息
extern crate africastalking_gateway;
use std::env;
use africastalking_gateway::AfricasTalkingGateway;
pub fn main() {
let username = "your-account-username";
let apikey = "your-api-key";
let env = "sandbox";
let gway = AfricasTalkingGateway::new(&username, &apikey, &env);
println!("{}", gway.fetch_messages(0).unwrap());
}
进行语音通话
extern crate africastalking_gateway;
extern crate serde_json;
use std::env;
use africastalking_gateway::AfricasTalkingGateway;
pub fn main() {
let username = "your-account-username";
let apikey = "your-api-key";
let env = "sandbox";
let gway = AfricasTalkingGateway::new(&username, &apikey, &env);
println!("{:?}", gateway.call("+254702xxxxxx", "+254702xxxxxx"));
// check queue status
println!("{:?}", gateway.get_queued_calls("+254702xxxxxx", None));
}
发送话费
extern crate africastalking_gateway;
#[macro_use]
extern crate serde_json;
use std::env;
use africastalking_gateway::AfricasTalkingGateway;
pub fn main() {
let username = "your-account-username";
let apikey = "your-api-key";
let env = "sandbox";
let gway = AfricasTalkingGateway::new(&username, &apikey, &env);
let recipients = json!([
{
"phoneNumber": "+254702xxxxxx",
"amount": "KES 500"
}
]);
println!("{:?}", gateway.send_airtime(recipients));
}
许可证
本项目使用 MIT 许可证。有关详细信息,请参阅LICENSE。
依赖
~17–28MB
~497K SLoC