Categorygithub.com/minchao/go-every8d
modulepackage
0.0.0-20200106155519-95d0ca9c97bf
Repository: https://github.com/minchao/go-every8d.git
Documentation: pkg.go.dev

# README

go-every8d

Build Status GoDoc Go Report Card codecov

A Go client library for accessing the EVERY8D SMS API.

Installation

Use go get to install.

go get -u github.com/minchao/go-every8d

Usage

Import the go-every8d package.

import "github.com/minchao/go-every8d"

Construct a new API client, then use to access the EVERY8D API. For example:

client := every8d.NewClient("UID", "PWD", nil)

Send an SMS

message := every8d.Message{
    Subject:         "Note",
    Content:         "Hello, 世界",
    Destination:     "+886987654321",
}

result, err := client.Send(context.Background(), message)

Query to retrieve the delivery status

resp, err := client.GetDeliveryStatus(context.Background(), batchID, pageNo)

Query credit

Retrieve your account balance.

credit, err := client.GetCredit(context.Background())

Use webhook to receive the sending report and reply message

func main() {
	http.HandleFunc("/callback", func(w http.ResponseWriter, r *http.Request) {
		report, err := every8d.ParseReportMessage(r)
		if err != nil {
			// Handle error...
			return
		}
		// Process report message...
	})
	if err := http.ListenAndServe(":8080", nil); err != nil {
		log.Printf("ListenAndServe error: %v", err)
	}
}

Develop

Command-line Tool

Change directory to cmd/every8d, and build the tool:

$ cd cmd/every8d
$ go build

Run:

$ ./every8d
EVERY8D SMS CLI tool

Usage:
  every8d [command]

Available Commands:
  credit          Query credit
  delivery-status Query to retrieve the delivery status
  help            Help about any command
  send            Send an SMS
  send-mms        Send an MMS
  webhook         Webhook to receive the sending report and reply message

Flags:
  -h, --help              help for every8d
      --password string   EVERY8D Password
      --username string   EVERY8D Username

Use "every8d [command] --help" for more information about a command.

Example to send SMS:

$ ./every8d send --username=0987654321 --password=password --dest=0987654321 --msg="Hello, 世界"
Credit: 79.00
Sent: 1
Cost: 1.00
Unsent: 0
BatchID: 00000000-00000-0000-0000-000000000000

Run all tests

$ go test -v -race .

License

This library is distributed under the BSD-style license found in the LICENSE file.

# Packages

No description provided by the author

# Functions

CheckResponse checks the API response for errors.
NewClient returns a new EVERY8D API client.
ParseReportMessage parses an incoming EVERY8D callback request and return the ReportMessage.

# Constants

List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.
List of EVERY8D API status codes.

# Structs

A Client manages communication with the EVERY8D API.
DeliveryStatus represents delivery status.
DeliveryStatusResponse represents the response of get delivery status.
ErrorResponse reports error caused by an API request.
Message represents an SMS object.
MMS represents an MMS object.
ReportMessage represents sending report or reply message.
SendResponse represents the response of send an SMS.

# Type aliases

Parser parses the response body into a object v.
StatusCode of EVERY8D API.