wavecell

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2022 License: MIT Imports: 10 Imported by: 0

README

wavecell

Go Reference Go Report Card

Wavecell API client library in Go.

How to Use

package main

import (
	"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(&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 (
	HeaderAuthorization   = "Authorization"
	HeaderAuthBearerValue = "Bearer "
)

List of Header for HTTPs.

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 (
	// 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 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(req *RequestSendSMS) (resp interface{}, 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(&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 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.

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