Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

AfricasTalkingLtd/africastalking-rust

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

africastalking-rust

Build Status

A Rust library for communicating with the Africa's Talking REST API.

installation

cargo install --git https://github.com/rust-nairobi/africastalking-rust

sending a message

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()
    );
}

fetching messages

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());
}

making a voice call

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));
}

sending airtime

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));
}

license

This project is license used the MIT license. See LICENSE for more details.

About

[WIP] AfricasTalking Rust API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%