beemafrica

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 8, 2023 License: MIT Imports: 6 Imported by: 0

README

go-client

Go libary to ease the integration with the Beem Africa (SMS, AIRTIME, OTP, 2WAY-SMS, BPAY, USSD)

Installation

To start using this in your project

go get -u github.com/Jkarage/beemafrica

Authentication

To authenticate and usage of the package add your credentials to your environment.

For Unix Based

export BEEM_API_KEY=<your beem api key>
export BEEM_SECRET_KEY=<your beem secret key>

For Windows

set BEEM_API_KEY=<your beem api key>
set BEEM_SECRET_KEY=<your beem secret key>

Run Tests with one command

    go test ./... -v

Sending SMS with beemAfrica

You can now send sms to multiple recipients with this package by just adding your credentials to the environment.

Usage Example
package main

import (
 "io"
 "log"
 "os"

 "github.com/Jkarage/beemafrica"
)

func main() {
 sms := beemafrica.NewSMS()
 resp, err := sms.SendSMS("Sample text message", []string{"2557135070XX"}, "")
 if err != nil {
  log.Fatal(err)
 }
 io.Copy(os.Stdout, resp.Body)
}

Requesting the sms Ballance from beemAfrica

The package provides an api for requesting the sms ballance in a specific account.

SMS Usage Example
package main

import (
 "io"
 "log"
 "os"

 "github.com/Jkarage/beemafrica"
)

func main() {
 client := beemafrica.NewSMS()
 resp, err := client.GetBallance()
 if err != nil {
  log.Fatal(err)
 }
 io.Copy(os.Stdout, resp.Body)

 io.Copy(os.Stdout, resp.Body)
}

AIRTIME

Sending airtime to a friend
    client := beemafrica.NewAirtime()
    resp, err := client.Transfer("2557135070XX", 2000, 1234)
    if err != nil {
    log.Fatal(err)
    }
    io.Copy(os.Stdout, resp.Body)
Getting airtime ballance
    client := beemafrica.NewAirtime()
    resp, err := client.GetBallance()
    if err != nil {
    log.Fatal(err)
    }
    io.Copy(os.Stdout, resp.Body)

OTP

Requesting an OTP PIN
    client := beemafrica.NewOTP()
    resp, err := client.Request("2557135070XX", 12XX)
    if err != nil {
    log.Fatal(err)
    }

    io.Copy(os.Stdout, resp.Body)
Verifying an OTP PIN
client := beemafrica.NewOTP()
 resp, err := client.Verify("44bcae75-15ff-4885-915c-6eeba6xxxxx", "57XXXX")
 if err != nil {
  log.Fatal(err)
 }

 io.Copy(os.Stdout, resp.Body)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AirtimeClient

type AirtimeClient struct {
	// contains filtered or unexported fields
}

func NewAirtime

func NewAirtime() *AirtimeClient

func (*AirtimeClient) GetBallance

func (a *AirtimeClient) GetBallance() (*http.Response, error)

GetBallance retrieves the ballance in your beemafrica account.

func (*AirtimeClient) Transfer

func (a *AirtimeClient) Transfer(address string, amount, reference int) (*http.Response, error)

Transfer attempts to transfer amount from your account to another account. address is the phone number in format 2557135070XX,followed by the amount reference is a random number for reference

type OTPClient

type OTPClient struct {
	// contains filtered or unexported fields
}

func NewOTP

func NewOTP() *OTPClient

func (*OTPClient) Request

func (o *OTPClient) Request(number string, appId int) (*http.Response, error)

Request generates a random OTP and sends it to the provided phone number,application id. Requires Mobile number in valid international number format with country code. No leading + sign. Example 255713507067. appid is found in beem dashboard.

func (*OTPClient) Verify

func (o *OTPClient) Verify(pinId string, otp string) (*http.Response, error)

Verify checks to see if the provided OTP matches the pinId provided. Returns a Valid 200 OK Response, In Both cases. Look into data for Valid or Invalid OTP

type SMSClient

type SMSClient struct {
	// contains filtered or unexported fields
}

func NewSMS

func NewSMS() *SMSClient

func (*SMSClient) GetBallance

func (s *SMSClient) GetBallance() (*http.Response, error)

GetBallance request for the sms ballance for a particular account If the error is nil, the response of type *http.Response will be returned

func (*SMSClient) GetSenderNames

func (s *SMSClient) GetSenderNames() (*http.Response, error)

GetSenderNames retrieves sendernames available in your account.

func (*SMSClient) RequestSenderID

func (s *SMSClient) RequestSenderID(id, idContent string) (*http.Response, error)

RequestSenderID queues a request to beem for a specific senderid. Response will be obtained, later through mail.

func (*SMSClient) SendSMS

func (s *SMSClient) SendSMS(message string, recipients []string, schedule_time string) (*http.Response, error)

SendSMS sends request to beemafrica to send a message, with given details. the message, a slice of recipients, and a scheduled time value. time format is GMT+0 timezone,(yyyy-mm-dd hh:mm). send now scheduled_time is ""

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL