Giter Site home page Giter Site logo

africastalking-swift's Introduction

Africa's Talking

This SDK simplifies the integration of Africa's Talking APIs into your iOS apps. For better security, the SDK is split into two components: A server module that stores API keys, SIP credentials and other secrets. And a client module that runs in your app. This client module gets secrets from the server component (via RPC), and uses them to interact with the various APIs.

For instance, to send an SMS, the client with request a token from the server; The server will use it's API key to request a token from Africa's Talking on behalf of the client. It will then forward the token to the client which will use it to request the SMS API to send a text. All in a split second!

Usage

Your server application could be something like this:

/* On The Server (Node.js, Java, and all languages supported by gRPC.) */

const options = {
    apiKey: 'YOUR_API_KEY',         // Use sandbox API key for sandbox development
    username: 'YOUR_USERNAME',      // Use "sandbox" for sandbox development
};
const Server = require('africastalking/server');
const srv = new Server(options);
srv.start({
    privateKeyFile: fs.readFileSync('path/to/pk'),
    certChainFile: fs.readFileSync('path/to/cert/chain'),
    rootCertFile: fs.readFileSync('path/to/root/cert'),
    port: 35897,
    insecure: false,
});

And your iOS app:

/* On The Client (iOS) */

// Init SDK
AfricasTalking.initialize(SERVER_HOSTNAME)

// Get Service
let airtime = AfricasTalking.getAirtimeService()

// Use Service
let recipients = [
  ["phoneNumber": "+254718769882", "currencyCode": "KES", "amount": 332],
  ["phoneNumber": "0718769881", "currencyCode": "KES", "amount": 324 ]
]
airtime.send(to: recipients) {error, data in
  //...
}

Download

Server

Node

npm install --save africastalking

Java

repositories {
  maven {
    url  "http://dl.bintray.com/africastalking/java"
  }
}
dependencies{
  compile 'com.africastalking:server:VERSION'
}

Or Maven (from http://dl.bintray.com/africastalking/java)

<dependency>
  <groupId>com.africastalking</groupId>
  <artifactId>server</artifactId>
  <version>VERSION</version>
</dependency>

Client (iOS)

With Swift Package Manager

import PackageDescription

let package = Package(
    name: "YourApp"
    //...
    dependencies: [
        .package(url: "https://github.com/AfricastalkingLtd/africastalking-swift.git", from: "1.0.0"),
    ],
    targets: [
        .target(
            name: "YourApp",
            dependencies: ["AfricasTalking",]
        )
    ]
    //...
)

Initialization

The following static methods are available in the africasTalking package to initialize the library:

  • initialize(host: String, port: Int, disableTls: Bool): Initialize the library.
  • getXXXService(): Get an instance to a given XXX service. e.g. .getSmsService(), .getPaymentService(), etc.

Services

All methods take a Africastalking.Callback: (error: String?, data: JSON?) -> Void as the last parameter.

Account

  • getUser(): Get user information.

Airtime

  • send(to: String, amount: String): Send airtime to a phone number. Amount with currency code, e.g. USD 10

  • send(recipients: [[String: Any]]): Send airtime to a bunch of phone numbers. The keys in the recipients map are phone numbers while the values are airtime amounts ( e.g. KES 678).

For more information about status notification, please read http://docs.africastalking.com/airtime/callback

Token

  • createCheckoutToken(phoneNumber: String): Create a checkout token.

SMS

  • send(message: String, to: [String], from: String?): Send a message

  • sendBulk(message: String, to: [String], from: String?): Send a message in bulk

  • sendPremium(message: String, keyword: String, linkId: String, to: [String], from: String?): Send a premium SMS

  • fetchMessages(lastReceivedId: Int?): Fetch your messages

  • fetchSubscriptions(lastReceivedId:Int?, shortCode: String, keyword: String): Fetch your premium subscription data

  • createSubscription(shortCode: String, keyword: String, phoneNumber: String): Create a premium subscription

For more information on:

Payment

  • checkout(request: CheckoutRequest): Initiate checkout(mobile, card or bank).

  • validateCheckout(request: CheckoutValidateRequest): Validate checkout (card or bank).

  • mobileB2C(productName: String, recipients: [Consumer]): Send money to consumer.

  • mobileB2B(productName: String, recipient: Business): Send money to business.

Voice

  • makeCall(from: String, to: [String]): Initiate an outbound call from your virtual number to some number(s)

  • queueStatus(phoneNumbers: String): Query call queue status

  • mediaUpload(url: String, phoneNumber: String): Upload media file

Credit

For more info, please visit https://www.africastalking.com

africastalking-swift's People

Contributors

aksalj avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.