Documentation
¶
Index ¶
- Constants
- func CheckResponse(r *http.Response) error
- type Client
- func (c *Client) Do(ctx context.Context, req *http.Request, fn Parser, v interface{}) (*http.Response, error)
- func (c *Client) GetCredit(ctx context.Context) (float64, error)
- func (c *Client) GetDeliveryStatus(ctx context.Context, batchID, pageNo string) (*DeliveryStatusResponse, error)
- func (c *Client) GetMMSDeliveryStatus(ctx context.Context, batchID, pageNo string) (*DeliveryStatusResponse, error)
- func (c *Client) NewFormRequest(urlStr string, form url.Values) (*http.Request, error)
- func (c *Client) NewRequest(method, urlStr string, body io.Reader) (*http.Request, error)
- func (c *Client) Send(ctx context.Context, message Message) (*SendResponse, error)
- func (c *Client) SendMMS(ctx context.Context, message MMS) (*SendResponse, error)
- type DeliveryStatus
- type DeliveryStatusResponse
- type ErrorResponse
- type MMS
- type Message
- type Parser
- type ReportMessage
- type SendResponse
- type StatusCode
Constants ¶
const ( StatusInvalidMobileNumber = StatusCode(-3) StatusDTFormatErrorOrPassedMoreThan24Hours = StatusCode(-4) StatusTheContentIsEmpty = StatusCode(-24) StatusNoMobile = StatusCode(-41) StatusServerSiteError = StatusCode(-99) StatusWrongUsername = StatusCode(-100) StatusWrongPassword = StatusCode(-101) StatusUsernameAndPasswordAreRequired = StatusCode(-300) StatusSubjectRequired = StatusCode(-303) StatusImageRequired = StatusCode(-304) StatusImageTypeRequired = StatusCode(-305) StatusImageTooLarge = StatusCode(-314) StatusSent = StatusCode(0) StatusMessageReceived = StatusCode(100) StatusDeliveryFailureDueMobile = StatusCode(101) StatusDeliveryFailureDueTelecom102 = StatusCode(102) StatusMobileNumberNotExist = StatusCode(103) StatusDeliveryFailureDueTelecom104 = StatusCode(104) StatusDeliveryFailureDueTelecom105 = StatusCode(105) StatusDeliveryFailureDueTelecom106 = StatusCode(106) StatusReceivedAfterDeadline = StatusCode(107) StatusReservationSMS = StatusCode(300) StatusNoCredit = StatusCode(301) StatusCanceled = StatusCode(303) StatusInternationalSMSNotConfigured = StatusCode(500) StatusSMSSent = StatusCode(700) StatusTestingMode = StatusCode(888) StatusReplayContent = StatusCode(999) )
List of EVERY8D API status codes.
Variables ¶
This section is empty.
Functions ¶
func CheckResponse ¶
CheckResponse checks the API response for errors.
Types ¶
type Client ¶
type Client struct {
// Base URL for API requests, should always be specified with a trailing slash.
BaseURL *url.URL
// User agent used when communicating with the EVERY8D API.
UserAgent string
// contains filtered or unexported fields
}
A Client manages communication with the EVERY8D API.
func (*Client) Do ¶
func (c *Client) Do(ctx context.Context, req *http.Request, fn Parser, v interface{}) (*http.Response, error)
Do sends an API request and returns the API response.
The provided ctx must be non-nil. If it is canceled or time out, ctx.Err() will be returned.
func (*Client) GetDeliveryStatus ¶
func (c *Client) GetDeliveryStatus(ctx context.Context, batchID, pageNo string) (*DeliveryStatusResponse, error)
GetDeliveryStatus retrieves the delivery status.
func (*Client) GetMMSDeliveryStatus ¶
func (c *Client) GetMMSDeliveryStatus(ctx context.Context, batchID, pageNo string) (*DeliveryStatusResponse, error)
GetMMSDeliveryStatus retrieves the MMS delivery status.
func (*Client) NewFormRequest ¶
NewFormRequest creates an API POST request.
func (*Client) NewRequest ¶
NewRequest creates an API request.
type DeliveryStatus ¶
type DeliveryStatus struct {
Name string
Mobile string
SendTime string
Cost float64
Status StatusCode
}
DeliveryStatus represents delivery status.
type DeliveryStatusResponse ¶
type DeliveryStatusResponse struct {
Count int
Records []DeliveryStatus
}
DeliveryStatusResponse represents the response of get delivery status.
type ErrorResponse ¶
type ErrorResponse struct {
Response *http.Response
ErrorCode StatusCode
Message string
}
ErrorResponse reports error caused by an API request.
func (*ErrorResponse) Error ¶
func (r *ErrorResponse) Error() string
type MMS ¶
type MMS struct {
// Message title.
Subject string `form:"SB"`
// Message content.
Content string `form:"MSG"`
// Receiver's mobile number.
// Format: +88612345678 or 0912345678, Separator: (,) e.g. 0912345678,0922333444
Destination string `form:"DEST"`
// Reservation time
// Format: yyyyMMddHHmnss, e.g. 20090131153000
// Send immediately: No input (empty).
ReservationTime string `form:"ST,omitempty"`
// MMS validity period of unit: minutes.
// If not specified, then the platform default validity period is 1440 minutes.
RetryTime int `form:"RETRYTIME,omitempty"`
// Message record no.
MessageNo string `form:"MR,omitempty"`
// Image file, binary base64 encoded.
Attachment string `form:"ATTACHMENT"`
// Image file extension, support jpg/jpeg/png/git.
Type string `form:"TYPE"`
}
MMS represents an MMS object.
type Message ¶
type Message struct {
// Message title.
// Empty titles are accepted.
// The title will not be sent with the SMS; it is just a note.
Subject string `form:"SB,omitempty"`
// Message content.
Content string `form:"MSG"`
// Receiver's mobile number.
// Format: +88612345678 or 0912345678, Separator: (,) e.g. 0912345678,0922333444
Destination string `form:"DEST"`
// Reservation time
// Format: yyyyMMddHHmnss, e.g. 20090131153000
// Send immediately: No input (empty).
ReservationTime string `form:"ST,omitempty"`
// SMS validity period of unit: minutes.
// If not specified, then the platform default validity period is 1440 minutes.
RetryTime int `form:"RETRYTIME,omitempty"`
// Message record no.
MessageNo string `form:"MR,omitempty"`
}
Message represents an SMS object.
type ReportMessage ¶
type ReportMessage struct {
// Batch ID.
BatchID string `url:"BatchID"`
// Receive's mobile number.
// Format: +88612345678
Destination string `url:"RM"`
// Report time.
ReportTime string `url:"RT"`
// Sending status.
StatusCode StatusCode `url:"STATUS"`
// Reply message.
ReplyMessage string `url:"SM,omitempty"`
// Message record no.
MessageNo string `url:"MR,omitempty"`
}
ReportMessage represents sending report or reply message.
func ParseReportMessage ¶
func ParseReportMessage(r *http.Request) (*ReportMessage, error)
ParseReportMessage parses an incoming EVERY8D callback request and return the ReportMessage.
type SendResponse ¶
type SendResponse struct {
// Balance credit.
// Negative means there was a delivery failure and the system can't process this command.
Credit float64
// Sent messages.
Sent int
// This shows spent points.
Cost float64
// Unsent messages with no credit charged.
Unsent int
// Batch ID. e.g. 220478cc-8506-49b2-93b7-2505f651c12e
BatchID string
}
SendResponse represents the response of send an SMS.