mitake

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusServiceError                  = StatusCode("*")
	StatusSMSTemporarilyUnavailable     = StatusCode("a")
	StatusSMSTemporarilyUnavailableB    = StatusCode("b")
	StatusUsernameRequired              = StatusCode("c")
	StatusPasswordRequired              = StatusCode("d")
	StatusUsernameOrPasswordError       = StatusCode("e")
	StatusAccountExpired                = StatusCode("f")
	StatusAccountDisabled               = StatusCode("h")
	StatusInvalidConnectionAddress      = StatusCode("k")
	StatusReachConnectUserLimit         = StatusCode("l")
	StatusChangePasswordRequired        = StatusCode("m")
	StatusPasswordExpired               = StatusCode("n")
	StatusPermissionDenied              = StatusCode("p")
	StatusServiceTemporarilyUnavailable = StatusCode("r")
	StatusAccountingFailure             = StatusCode("s")
	StatusSMSExpired                    = StatusCode("t")
	StatusSMSBodyEmpty                  = StatusCode("u")
	StatusInvalidPhoneNumber            = StatusCode("v")
	StatusQueryRecordExceededLimit      = StatusCode("w")
	StatusSMSSizeTooLarge               = StatusCode("x")
	StatusParameterError                = StatusCode("y")
	StatusNoRecord                      = StatusCode("z")
	StatusReservationForDelivery        = StatusCode("0")
	StatusCarrierAccepted               = StatusCode("1")
	StatusCarrierAccepted2              = StatusCode("2")
	StatusCarrierAccepted3              = StatusCode("3")
	StatusDelivered                     = StatusCode("4")
	StatusContentError                  = StatusCode("5")
	StatusPhoneNumberError              = StatusCode("6")
	StatusSMSDisable                    = StatusCode("7")
	StatusDeliveryTimeout               = StatusCode("8")
	StatusReservationCanceled           = StatusCode("9")
)

List of Mitake API status codes.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL   *url.URL
	UserAgent string
	// contains filtered or unexported fields
}

A Client manages communication with the Mitake API.

func NewClient

func NewClient(username, password string, httpClient *http.Client) *Client

NewClient returns a new Mitake API client. The username and password are required for authentication. If a nil httpClient is provided, http.DefaultClient will be used.

func (*Client) CancelMessageStatus

func (c *Client) CancelMessageStatus(messageIds []string) (*MessageStatusResponse, error)

CancelMessageStatus cancel the specific messages.

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do sends an API request, and returns the API response. If the returned error is nil, the Response will contain a non-nil Body which the user is expected to close.

func (*Client) Get

func (c *Client) Get(url string) (*http.Response, error)

Get method make a GET HTTP request.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body io.Reader) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash.

func (*Client) Post

func (c *Client) Post(url string, bodyType string, body io.Reader) (*http.Response, error)

Post method make a POST HTTP request.

func (*Client) QueryAccountPoint

func (c *Client) QueryAccountPoint() (int, error)

QueryAccountPoint retrieves your account balance.

func (*Client) QueryMessageStatus

func (c *Client) QueryMessageStatus(messageIds []string) (*MessageStatusResponse, error)

QueryMessageStatus fetch the status of specific messages.

func (*Client) Send

func (c *Client) Send(message Message) (*MessageResponse, error)

Send an SMS.

func (*Client) SendBatch

func (c *Client) SendBatch(messages []Message) (*MessageResponse, error)

SendBatch sends multiple SMS.

type Message

type Message struct {
	Dstaddr  string `json:"dstaddr"`  // Destination phone number
	Destname string `json:"destname"` // Destination receiver name
	Dlvtime  string `json:"dlvtime"`  // Optional, Delivery time
	Vldtime  string `json:"vldtime"`  // Optional
	Smbody   string `json:"smbody"`   // The text of the message you want to send
	Response string `json:"response"` // Optional, Callback URL to receive the delivery receipt of the message
	ClientID string `json:"clientid"` // Optional (required when bulk send), an unique identifier from client to identify SMS message

}

Message represents an SMS object.

func (Message) ToBatchMessage

func (m Message) ToBatchMessage() string

ToBatchMessage returns the format string for multiple SMS.

func (Message) ToINI

func (m Message) ToINI() string

ToINI returns the INI format string from the message fields.

type MessageReceipt

type MessageReceipt struct {
	Msgid        string     `json:"msgid"`
	Dstaddr      string     `json:"dstaddr"`
	Dlvtime      string     `json:"dlvtime"`
	Donetime     string     `json:"donetime"`
	Statuscode   string     `json:"statuscode"`
	Statusstring StatusCode `json:"statusstring"`
	Statusstr    string     `json:"statusstr"`
	StatusFlag   string     `json:"StatusFlag"`
}

MessageReceipt represents a message delivery receipt.

func ParseMessageReceipt

func ParseMessageReceipt(r *http.Request) (*MessageReceipt, error)

ParseMessageReceipt parse an incoming Mitake callback request and return the MessageReceipt.

Example usage:

func Callback(w http.ResponseWriter, r *http.Request) {
	receipt, err := mitake.ParseMessageReceipt(r)
	if err != nil { ... }
	// Process message receipt
}

type MessageResponse

type MessageResponse struct {
	Results      []*MessageResult
	AccountPoint int
	INI          string `json:"-"`
}

MessageResponse represents response of send SMS.

type MessageResult

type MessageResult struct {
	ClientID     string     `json:"clientid"`
	Msgid        string     `json:"msgid"`
	Statuscode   string     `json:"statuscode"`
	Statusstring StatusCode `json:"statusstring"`
	Duplicate    string     `json:"Duplicate"`
}

MessageResult represents result of send SMS.

type MessageStatus

type MessageStatus struct {
	MessageResult
	StatusTime string `json:"statustime"`
}

MessageStatus represents status of message.

type MessageStatusResponse

type MessageStatusResponse struct {
	Statuses []*MessageStatus
	INI      string `json:"-"`
}

MessageStatusResponse represents response of query message status.

type StatusCode

type StatusCode string

StatusCode of Mitake API.

func (StatusCode) String

func (c StatusCode) String() string

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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