valuefirst

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2022 License: MIT Imports: 17 Imported by: 0

README

valuefirst

Go Reference Go Report Card

Valuefirst is a library written in Golang to connect to the ValueFirst API.

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 (
	URLToken               = "/api/messages/token"
	URLActionGenerateToken = URLToken + "?action=generate"
	URLActionEnableToken   = URLToken + "?action=enable"
	URLActionDisableToken  = URLToken + "?action=disable"
	URLActionDeleteToken   = URLToken + "?action=delete"
	URLActionSendSMS       = "/servlet/psms.JsonEservice"
)

List of URLs used in this package.

View Source
const (
	// QueryParamToken is the key for adding the token to the query params of URL.
	QueryParamToken = "token"

	// DefaultPayloadVersion is the default version of Payload.
	DefaultPayloadVersion = "1.2"

	// DefaultUDHText is the default UDH used for the text message.
	// UDH is used for sending binary messages.
	// For text message the value should be 0.
	DefaultUDHText = "0"

	// DefaultCodingText is the default coding used for the text message.
	// Extended type of messages.
	// For text message the value should be 1.
	DefaultCodingText = "1"

	// DefaultPropertyText is the default property used for the text message.
	// Unique property of message.
	// Default value is 0.
	// For sending Flash SMS the value should be 1.
	DefaultPropertyText = "0"
	// DefaultPropertyFlash is the default property used for the flash message.
	DefaultPropertyFlash = "1"
)
View Source
const (
	// DefaultTimeout sets the default timeout of the HTTP client.
	DefaultTimeout = 30 * time.Second

	// BaseURL sets the base URL of the API.
	BaseURL = "https://api.myvfirst.com/psms"
)

Variables

View Source
var (
	ErrEmptyUsername     = errors.New("empty username")
	ErrEmptyPassword     = errors.New("empty password")
	ErrDecodeVarIsNotPtr = errors.New("the decode variable is not a pointer")
	ErrNilRequest        = errors.New("nil request")
)

List of errors in the valuefirst package.

Functions

This section is empty.

Types

type Client

type Client interface {
	manager.TokenClient
	// SendSMS sends SMS messages to a list of addresses.
	SendSMS(ctx context.Context, req *RequestSendSMS) (resp *ResponseMessage, err error)
}

Client is the interface for the ValueFirst API client.

func New

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

New initialize the ValueFirst API client.

type ErrorList

type ErrorList []error

ErrorList is a list of errors.

func (*ErrorList) Append

func (e *ErrorList) Append(err error)

Append appends error to the ErrorList.

func (ErrorList) Error

func (e ErrorList) Error() (res string)

Error implements the error interface.

type FnOption

type FnOption func(o *Option)

FnOption is a function that sets the option.

func WithBaseURL

func WithBaseURL(s string) FnOption

WithBaseURL sets the base URL of the API.

func WithBasicAuth

func WithBasicAuth(user string, password string) FnOption

WithBasicAuth sets the basic auth credentials.

func WithClient

func WithClient(c heimdall.Doer) FnOption

WithClient sets the HTTP client.

func WithCustomIPs

func WithCustomIPs(ips ...string) FnOption

WithCustomIPs sets the custom IPs used for hitting the API.

func WithHystrixOptions

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

WithHystrixOptions sets the hystrix options.

func WithTimeout

func WithTimeout(t time.Duration) FnOption

WithTimeout sets the timeout of the HTTP client.

func WithTokenManager

func WithTokenManager(tm manager.TokenManager) FnOption

WithTokenManager sets the token manager.

func WithTokenStorage

func WithTokenStorage(s storage.Hub) FnOption

WithTokenStorage sets the token storage.

type Option

type Option struct {
	BaseURL        string
	BasicAuth      OptionBasicAuth
	Timeout        time.Duration
	Client         heimdall.Doer
	HystrixOptions []hystrix.Option
	CustomIPs      []string
	TokenStorage   storage.Hub
	TokenManager   manager.TokenManager
	// contains filtered or unexported fields
}

Option is a config for Value.

func (*Option) Assign

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

Assign assigns the Option using the functional options.

func (*Option) Clone

func (o *Option) Clone() *Option

Clone clones the Option. Clone only makes a shallow copy of the Option struct.

func (*Option) Default

func (o *Option) Default() *Option

Default sets the config default value.

func (*Option) Validate

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

Validate validates the config variables to ensure smooth integration.

type OptionBasicAuth

type OptionBasicAuth struct {
	User     string
	Password string
}

OptionBasicAuth is a config for basic authorization.

type RequestSendSMS

type RequestSendSMS struct {
	Version string                 `json:"@VER"`
	User    struct{}               `json:"USER"`
	DLR     RequestSendSMSDLR      `json:"DLR"`
	SMS     RequestSendSMSMessages `json:"SMS"`
}

RequestSendSMS is the request of SendSMS.

func (*RequestSendSMS) Default

func (r *RequestSendSMS) Default() *RequestSendSMS

Default sets the default values for the RequestSendSMS.

type RequestSendSMSDLR

type RequestSendSMSDLR struct {
	URL string `json:"@URL"`
}

RequestSendSMSDLR is the DLR part of the RequestSendSMS.

type RequestSendSMSMessage

type RequestSendSMSMessage struct {
	// UDH is used for sending binary messages. For text message the value should be 0.
	UDH string `json:"@UDH"`

	// Extended type of messages. For text message the value should be 1.
	Coding string `json:"@CODING"`

	// This field describe the message text to be sent to receiver.
	// SMS can contain up to 160 characters in Message Text.
	// API allows user to send Message text of more than 160 characters.
	// Credits will be deducted in the multiple of 160 characters according to the length of SMS.
	Text string `json:"@TEXT"`

	// New Parameter TEMPLATEINFO has been added for above functionality
	// which will contain the template id and variables value to be replaced in template text.
	// Template info parameter will have ~ separated values.
	//
	// If both TEXT and TEMPLATEINFO is given then priority will be given to Text.
	//
	// New error code i.e. INVALID_TEMPLATEINFO = 28694; has been created for error if occurred any,
	// related to TEMPLATEINFO parameter, which include like invalid templateid is provided,
	// variables count mismatch than the template Text variables count,
	// template text not found for the given template id.
	TemplateInfo string `json:"@TEMPLATEINFO"`

	// Unique property of message. Default value is 0. For sending Flash SMS the value should be 1.
	Property string `json:"@PROPERTY"`

	// Unique ID of message. The client sends this value.
	// In future communication, server sends this value back to the client.
	// This value is used in future to check status of the message.
	ID string `json:"@ID"`

	// It is now possible to schedule a message.
	// To schedule message to go at a later time,
	// user can specify “SEND_ON” date as attribute of SMS tag.
	// Only absolute date is supported.
	// The value should be given in “YYYY-MM-DD HH:MM:SS TIMEZONE” format.
	// Time zone is difference w.r.t. to GMT.
	// Please refer Scheduling Support for more information on this feature.
	SendOn string `json:"@SEND_ON"`

	// Describe the Sender as well as Receiver address.
	Address RequestSendSMSMessageAddresses `json:"ADDRESS"`
}

RequestSendSMSMessage is the message part of the RequestSendSMS.

func (*RequestSendSMSMessage) Default

Default sets the default values for the RequestSendSMSMessage.

type RequestSendSMSMessageAddress

type RequestSendSMSMessageAddress struct {
	// The Sender of the message.
	// This field should conform to Sender Phone Number guidelines.
	From string `json:"@FROM"`

	// Person receiving the SMS, should confirm to Receiver Phone Number guidelines.
	To string `json:"@TO"`

	// Unique Sequence ID.
	// Must be an integer and must be unique to each SMS.
	// While checking message status, you must send this value.
	Sequence string `json:"@SEQ"`

	// A text that identify message.
	// This is an optional parameter.
	Tag string `json:"@TAG"`
}

RequestSendSMSMessageAddress is the address part of the RequestSendSMSMessage.

func (*RequestSendSMSMessageAddress) Default

Default sets the default values for the RequestSendSMSMessageAddress.

type RequestSendSMSMessageAddresses

type RequestSendSMSMessageAddresses []RequestSendSMSMessageAddress

RequestSendSMSMessageAddresses is a collection of RequestSendSMSMessageAddress.

func (RequestSendSMSMessageAddresses) Default

Default sets the default values for each RequestSendSMSMessageAddress.

type RequestSendSMSMessages

type RequestSendSMSMessages []RequestSendSMSMessage

RequestSendSMSMessages is a collection of RequestSendSMSMessage.

func (RequestSendSMSMessages) Default

Default sets the default values for each RequestSendSMSMessage.

type ResponseMessage

type ResponseMessage struct {
	MessageAck ResponseMessageAck `json:"MESSAGEACK"`
}

ResponseMessage is the message response of SendSMS.

func (*ResponseMessage) GetError

func (r *ResponseMessage) GetError() (err error)

GetError returns the error if any.

type ResponseMessageAck

type ResponseMessageAck struct {
	GUID interface{} `json:"GUID"`

	// "Err": {
	//            "Desc": "The Specified message does not conform to DTD",
	//            "Code": 65535
	//        }
	Error *ResponseMessageAckError `json:"Err,omitempty"`
}

ResponseMessageAck is the message part of the ResponseMessage.

func (*ResponseMessageAck) GetError

func (r *ResponseMessageAck) GetError() (err error)

GetError returns the error if any.

func (*ResponseMessageAck) GetMessageGUID

func (r *ResponseMessageAck) GetMessageGUID() (res *ResponseMessageAckGUID, ok bool)

GetMessageGUID return the GUID of the ResponseMessageAck.

func (*ResponseMessageAck) GetMessageGUIDs

func (r *ResponseMessageAck) GetMessageGUIDs() (res *ResponseMessageAckGUIDs, ok bool)

GetMessageGUIDs return the GUIDs of the ResponseMessageAck.

func (*ResponseMessageAck) UnmarshalJSON

func (r *ResponseMessageAck) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface.

type ResponseMessageAckError

type ResponseMessageAckError struct {
	Description string `json:"Desc"`
	Code        int    `json:"Code"`
}

ResponseMessageAckError is the error part of the ResponseMessageAck.

func (*ResponseMessageAckError) Error

func (r *ResponseMessageAckError) Error() string

Error implements the error interface.

type ResponseMessageAckGUID

type ResponseMessageAckGUID struct {
	// A globally unique message ID that is generated for each <SMS> tag.
	// Note that, in future to check the status of the message you must save this code.
	GUID string `json:"GUID"`

	// The date and time when the transaction was completed.
	SubmitDate string `json:"SUBMITDATE"`

	// (In case of any error)
	// To conserve bandwidth utilization ValueFirst JSON API only sends
	// Sequence information of messages that has either some error or were rejected
	// because of some error. If there are no errors in a particular message,
	// you shall not receive any confirmation of each address SEQ.
	// For instance, in the above example in message ID 1 (of client)
	// the TO number "My company" was rejected as non-numeric.
	// The second message does not have any error,
	// and hence there was no error information for the second part.
	// SEQ: The Sequence ID (provided by client) that has error.
	// CODE: Reason why the message wasn’t accepted.
	// The table shown next describes these error conditions.
	Error interface{} `json:"ERROR,omitempty"`

	// Unique SMS ID sent by the customer. For each message a unique GUID is generated.
	// The Server sends the SMS ID so that
	// the client application can map the GUID to the SMS ID provided by them.
	ID int `json:"ID"`
}

ResponseMessageAckGUID is the GUID part of the ResponseMessageAck.

func (*ResponseMessageAckGUID) GetError

func (r *ResponseMessageAckGUID) GetError() (err error)

GetError returns the Error of the ResponseMessageAckGUID.

func (*ResponseMessageAckGUID) GetMessageError

func (r *ResponseMessageAckGUID) GetMessageError() (res *ResponseMessageAckGUIDError, ok bool)

GetMessageError return the Error of the ResponseMessageAckGUID.

func (*ResponseMessageAckGUID) GetMessageErrors

func (r *ResponseMessageAckGUID) GetMessageErrors() (res *ResponseMessageAckGUIDErrors, ok bool)

GetMessageErrors return the Errors of the ResponseMessageAckGUID.

func (*ResponseMessageAckGUID) UnmarshalJSON

func (r *ResponseMessageAckGUID) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface.

type ResponseMessageAckGUIDError

type ResponseMessageAckGUIDError struct {
	Code     int `json:"CODE"`
	Sequence int `json:"SEQ"`
}

ResponseMessageAckGUIDError is the error part of the ResponseMessageAckGUID.

"ERROR": {
		"CODE": 28675,
		"SEQ": 1
},

func (*ResponseMessageAckGUIDError) Error

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

Error implements the error interface.

type ResponseMessageAckGUIDErrors

type ResponseMessageAckGUIDErrors []ResponseMessageAckGUIDError

ResponseMessageAckGUIDErrors is the collection of the ResponseMessageAckGUIDError.

func (ResponseMessageAckGUIDErrors) Error

func (r ResponseMessageAckGUIDErrors) Error() (res string)

Error implements the error interface.

type ResponseMessageAckGUIDs

type ResponseMessageAckGUIDs []ResponseMessageAckGUID

ResponseMessageAckGUIDs is a collection of ResponseMessageAckGUID.

func (ResponseMessageAckGUIDs) GetError

func (r ResponseMessageAckGUIDs) GetError() (err error)

GetError returns the error if any.

type UnknownError

type UnknownError struct {
	Message interface{} `json:"message"`
}

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

func (UnknownError) Error

func (e UnknownError) Error() string

Error implements the error interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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