wavecell

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2023 License: MIT Imports: 15 Imported by: 0

README

wavecell

Go Reference Go Report Card

Wavecell API client library in Go.

How to Use

package main

import (
	"context"
	"log"
	"net/http"
	"time"
)

func main() {
	c, err := New(
		WithAPIKey("YOUR_API_KEY"),
		WithTimeout(1*time.Minute),
		WithSubAccountID("SUB_ACCOUNT_ID"),
		WithClient(http.DefaultClient),
	)
	if err != nil {
		log.Fatal(err)
	}

	resp, err := c.SendSMSV1(context.Background(), &RequestSendSMS{
		Destination: "+62101010101",
		Text:        "Hello!",
	})
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("Response: %+v", resp)
}

Documentation

Overview

Package wavecell is an API client library for Golang.

Index

Examples

Constants

View Source
const (
	StatusCallbackUnknown     = `unknown`
	StatusCallbackQueued      = `queued`
	StatusCallbackFailed      = `failed`
	StatusCallbackSent        = `sent`
	StatusCallbackDelivered   = `delivered`
	StatusCallbackUndelivered = `undelivered`
	StatusCallbackRead        = `read`
	StatusCallbackOk          = `ok`
	StatusCallbackError       = `error`
	StatusCallbackRejected    = `rejected`
)

List of Status Callback

View Source
const (
	DetailCallbackDeliveredToOperator    = `delivered_to_operator`
	DetailCallbackDeliveredToRecipient   = `delivered_to_recipient`
	DetailCallbackRejectedByOperator     = `rejected_by_operator`
	DetailCallbackUndeliveredToRecipient = `undelivered_to_recipient`
)

List of Detail Callback

View Source
const BaseURL = "https://sms.8x8.com"

BaseURL is the base URL of the Wavecell API.

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout is the default timeout of the Wavecell API.

View Source
const (
	HeaderAuthBearerValue = "Bearer "
)

List of Header for HTTPs.

View Source
const (
	// URLSendSMS is the URL for SendSMSV1.
	URLSendSMS = `/api/v1/subaccounts/%s/messages`
)

List of all URLs for Wavecell package.

Variables

View Source
var (
	// ErrEmptyAPIKEY is the error for empty API key.
	ErrEmptyAPIKEY = errors.New("API key is empty")
	// ErrEmptySubAccountID is the error for empty sub account ID.
	ErrEmptySubAccountID = errors.New("Sub account ID is empty")
)

Functions

This section is empty.

Types

type CallbackData added in v1.0.2

type CallbackData struct {
	Namespace   string              `json:"namespace"`
	EventType   string              `json:"eventType"`
	Description string              `json:"description"`
	Payload     CallbackDataPayload `json:"payload"`
}

CallbackData specifies the callback data submitted by the vendor.

type CallbackDataPayload added in v1.0.2

type CallbackDataPayload struct {
	UMID            string        `json:"umid"`
	BatchID         string        `json:"batchId"`
	ClientMessageID string        `json:"clientMessageId"`
	ClientBatchID   string        `json:"clientBatchId"`
	SubAccountID    string        `json:"subAccountId"`
	Source          string        `json:"source"`
	Destination     string        `json:"destination"`
	Status          MessageStatus `json:"status"`
	Price           MessagePrice  `json:"price"`
	SmsCount        int           `json:"smsCount"`
}

CallbackDataPayload specifies the message payload of callback data submitted by the vendor.

type Client

type Client interface {
	// SendSMSV1 sends one message to one recipient.
	// The resp here can be either *ResponseError, *ResponseSendSMS, or nil.
	// This method is based on the documentation at: https://developer.8x8.com/connect/reference/send-sms-single.
	SendSMSV1(ctx context.Context, req *RequestSendSMS) (resp *ResponseSendSMS, err error)
}

Client is the contract for the Wavecell client.

func New

func New(opts ...FnOption) (c Client, err error)

New returns a new Sender struct.

Example
c, err := New(
	WithAPIKey("YOUR_API_KEY"),
	WithTimeout(1*time.Minute),
	WithSubAccountID("SUB_ACCOUNT_ID"),
	WithClient(http.DefaultClient),
)
if err != nil {
	log.Fatal(err)
}

resp, err := c.SendSMSV1(context.Background(), &RequestSendSMS{
	Destination: "+62101010101",
	Text:        "Hello!",
})
if err != nil {
	log.Fatal(err)
}

log.Printf("Response: %+v", resp)
Output:

type FnOption

type FnOption func(o *Option)

FnOption is the functional option to set the Option.

func WithAPIKey

func WithAPIKey(key string) FnOption

WithAPIKey sets the API key of the Wavecell API.

func WithBaseURL

func WithBaseURL(u string) FnOption

WithBaseURL sets the base URL of the Wavecell API.

func WithClient

func WithClient(c heimdall.Doer) FnOption

WithClient sets the client of the Wavecell API.

func WithHystrixOptions added in v0.0.4

func WithHystrixOptions(opts ...hystrix.Option) FnOption

WithHystrixOptions sets the hystrix options of the Wavecell API.

func WithSubAccountID

func WithSubAccountID(id string) FnOption

WithSubAccountID sets the sub account ID of the Wavecell API.

func WithTimeout

func WithTimeout(t time.Duration) FnOption

WithTimeout sets the timeout of the Wavecell API.

type MessagePrice added in v1.0.2

type MessagePrice struct {
	Total    *decimal.Decimal `json:"total"`
	PerSMS   decimal.Decimal  `json:"perSms"`
	Currency *string          `json:"currency"`
}

MessagePrice specifies the message price.

type MessageStatus added in v1.0.2

type MessageStatus struct {
	State        string `json:"state"`
	Detail       string `json:"detail"`
	Timestamp    string `json:"timestamp"`
	ErrorCode    int    `json:"errorCode"`
	ErrorMessage string `json:"errorMessage"`
}

MessageStatus specifies the message status.

type Option

type Option struct {
	BaseURL        string
	APIKey         string
	SubAccountID   string
	Client         heimdall.Doer
	Timeout        time.Duration
	HystrixOptions []hystrix.Option
	// contains filtered or unexported fields
}

Option is the option for the client.

func (*Option) Assign

func (o *Option) Assign(opts ...FnOption) *Option

func (*Option) Clone

func (o *Option) Clone() *Option

Clone returns a clone of the option.

func (*Option) Default

func (o *Option) Default() *Option

Default is the default option for the client.

func (*Option) Validate

func (o *Option) Validate() (err error)

Validate validates the option.

type RequestSendSMS

type RequestSendSMS struct {
	Destination     string        `json:"destination,omitempty" validate:"required"`
	Country         string        `json:"country,omitempty"`
	Source          string        `json:"source,omitempty"`
	ClientMessageID string        `json:"clientMessageId,omitempty"`
	Text            string        `json:"text,omitempty" validate:"required"`
	Encoding        string        `json:"encoding,omitempty"`
	Scheduled       *iso8601.Time `json:"scheduled,omitempty"`
	Expiry          *iso8601.Time `json:"expiry,omitempty"`
	DlrCallbackURL  string        `json:"dlrCallbackUrl,omitempty"`
	ClientIP        string        `json:"clientIp,omitempty"`
	Track           string        `json:"track,omitempty"`
}

RequestSendSMS is the request struct for SendSMSV1.

func (*RequestSendSMS) Normalize added in v1.0.1

func (r *RequestSendSMS) Normalize() *RequestSendSMS

Normalize normalizes the request.

type ResponseError

type ResponseError struct {
	Code      int          `json:"code"`
	Message   string       `json:"message,omitempty"`
	ErrorID   string       `json:"errorId"`
	Timestamp iso8601.Time `json:"timestamp"`
}

ResponseError is the standard response struct for error.

func (*ResponseError) Error added in v0.0.4

func (r *ResponseError) Error() (res string)

Error returns the error message.

type ResponseSendSMS

type ResponseSendSMS struct {
	UmID            string                `json:"umid"`
	Destination     string                `json:"destination"`
	Status          ResponseSendSMSStatus `json:"status"`
	Encoding        string                `json:"encoding"`
	ClientMessageID string                `json:"clientMessageId,omitempty"`
}

ResponseSendSMS is the response struct for SendSMSV1.

type ResponseSendSMSStatus

type ResponseSendSMSStatus struct {
	Code        string `json:"code"`
	Description string `json:"description"`
}

ResponseSendSMSStatus is the response struct for SendSMSV1.

Jump to

Keyboard shortcuts

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