sms_jatis

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2022 License: MIT Imports: 16 Imported by: 0

README

sms-jatis

Go Reference Go Report Card

This is SMS Jatis Library. It is written in Go to integrate with the SMS Jatis platform.

How to Test

To run the integration tests, we need to do the following:

  1. Make a new copy of .env.example to .env by running this command below:
cat .env.example > .env
  1. Fill the new .env with the parameter that we already prepared.
  2. Run the tests by running this command:
go test -v -race -tags=integration -covermode=atomic ./...

Documentation

Index

Constants

View Source
const (
	FormKeyUserID    = "userid"
	FormKeyPassword  = "password"
	FormKeySender    = "sender"
	FormKeyMSISDN    = "msisdn"
	FormKeyMessage   = "message"
	FormKeyDivision  = "division"
	FormKeyBatchName = "batchname"
	FormKeyUploadBy  = "uploadby"
	FormKeyChannel   = "channel"
)

List of form keys used for request in Jatis.

View Source
const (
	// DefaultBaseURL is the default base URL for the Jatis API.
	DefaultBaseURL = "https://sms-api.jatismobile.com/index.ashx"
	// DefaultTimeout is the default timeout for the Jatis API.
	DefaultTimeout = 30 * time.Second
)
View Source
const (
	// DefaultBatchOTP is the default batch name for OTP.
	DefaultBatchOTP = "otp"
	// DefaultBaseDecimal is the default base 10 for decimal.
	DefaultBaseDecimal = 10
)
View Source
const (
	KeyURLDecodedStatus    = "Status"
	KeyURLDecodedMessageID = "MessageId"
)

List of key used to access the value of URL decoded values.

Variables

View Source
var ErrNilArgs = errors.New("nil arguments")

ErrNilArgs is returned when the argument is nil.

Functions

This section is empty.

Types

type ChannelType added in v0.2.0

type ChannelType uint64

ChannelType specifies the channel type used in this package.

const (
	ChannelRegular ChannelType = iota
	ChannelAlert
	ChannelOTP
)

List of channel used in Jatis.

type Client added in v0.1.0

type Client interface {
	// SendSMS sends message to the Jatis platform.
	SendSMS(ctx context.Context, request *RequestMessage) (respBody *ResponseMessage, err error)
}

Client is the interface of Jatis SMS client.

func NewClient added in v0.1.0

func NewClient(opts ...FnOption) (c Client)

NewClient initializes a new client with the given option.

type FnOption added in v0.1.0

type FnOption func(o *Option)

FnOption is a function that modifies Option.

func WithBaseURL added in v0.1.0

func WithBaseURL(baseURL string) FnOption

WithBaseURL sets the base URL for the Jatis API.

func WithChannel added in v0.1.0

func WithChannel(channel ChannelType) FnOption

WithChannel sets the channel for the Jatis API.

func WithClient added in v0.1.0

func WithClient(client heimdall.Doer) FnOption

WithClient sets the client for the Jatis API.

func WithCustomIPs added in v0.1.0

func WithCustomIPs(customIPs ...string) FnOption

WithCustomIPs sets the custom IPs for the Jatis API.

func WithDivision added in v0.1.0

func WithDivision(division string) FnOption

WithDivision sets the division for the Jatis API.

func WithHystrixOptions added in v0.1.0

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

WithHystrixOptions sets the hystrix options for the Jatis API.

func WithPassword added in v0.1.0

func WithPassword(password string) FnOption

WithPassword sets the password for the Jatis API.

func WithSender added in v0.1.0

func WithSender(sender string) FnOption

WithSender sets the sender for the Jatis API.

func WithTimeout added in v0.1.0

func WithTimeout(timeout time.Duration) FnOption

WithTimeout sets the timeout for the Jatis API.

func WithUploadBy added in v0.1.0

func WithUploadBy(uploadBy string) FnOption

WithUploadBy sets the upload by for the Jatis API.

func WithUserID added in v0.1.0

func WithUserID(userID string) FnOption

WithUserID sets the user ID for the Jatis API.

type Option added in v0.1.0

type Option struct {
	BaseURL        string
	UserID         string
	Password       string
	Sender         string
	Division       string
	UploadBy       string
	Channel        *ChannelType
	CustomIPs      []string
	Timeout        time.Duration
	Client         heimdall.Doer
	HystrixOptions []hystrix.Option
	// contains filtered or unexported fields
}

Option is a struct containing all configurations for Jatis.

func (*Option) Assign added in v0.1.0

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

Assign assigns the Option to the given FnOption.

func (*Option) Clone added in v0.1.0

func (o *Option) Clone() *Option

Clone returns a shallow clone of the Option.

func (*Option) Default added in v0.1.0

func (o *Option) Default() *Option

Default returns a default Option.

type RequestMessage added in v0.1.0

type RequestMessage struct {
	PhoneNumber string
	Text        string
	BatchName   string
	Channel     *ChannelType
}

RequestMessage defines the request message to Jatis.

func (*RequestMessage) Default added in v0.1.0

func (r *RequestMessage) Default(o *Option) *RequestMessage

Default returns the default request message for Jatis.

type ResponseMessage added in v0.1.0

type ResponseMessage struct {
	MessageID    string
	Status       string
	StatusNumber StatusParam
}

ResponseMessage defines the response message from Jatis.

func (*ResponseMessage) Error added in v0.1.0

func (r *ResponseMessage) Error() string

ResponseMessage implements the error interface.

type StatusParam added in v0.2.0

type StatusParam uint64

StatusParam is the status parameter in the response message.

const (
	StatusSuccess StatusParam = iota + 1
	StatusMissingParameter
	StatusInvalidUserIDOrPassword
	StatusInvalidMessage
	StatusInvalidMSISDN
	StatusInvalidSender
	StatusDeniedIPAddress
	StatusInternalServerError
	StatusInvalidDivision
)

List of all status parameters used in Jatis.

const (
	StatusInvalidChannel StatusParam = iota + 20
	StatusTokenNotEnough
	StatusTokenNotAvailable
)

List of all status parameters used in Jatis.

func (StatusParam) String added in v0.2.0

func (s StatusParam) String() string

String returns the string representation of the status param.

func (StatusParam) Uint64String added in v0.2.2

func (s StatusParam) Uint64String() string

Uint64String converts the uint64 to the string version.

type UnknownError added in v0.1.0

type UnknownError struct {
	StatusCode int    `json:"status_code"`
	Message    []byte `json:"message"`
}

UnknownError is an error that is not defined by the documentation from the SMS Jatis.

func (UnknownError) Error added in v0.1.0

func (e UnknownError) Error() string

Error implements the error interface.

Jump to

Keyboard shortcuts

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