Documentation ¶
Overview ¶
The clickatell package provides integration with the Clickatell SMS gateway.
Index ¶
- func Concat(args ...string) string
- func CreateRequest(url string) (*http.Request, error)
- func GetContent(r *http.Response) string
- func MakeQueryString(c *HttpClient, v url.Values) url.Values
- type ClickatellError
- type ErrorResponse
- type GetBalanceResponse
- type HttpClient
- type LegacyUnwrap
- type Message
- type RestClient
- type SendResponse
- type SendResponseMessage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateRequest ¶
CreateRequest() function creates a new HTTP get request based on the URL passed to it. It will attach the user agent defined by the "userAgent" constant variable.
func GetContent ¶
GetContent() function will return the http.Response content as a string.
func MakeQueryString ¶
func MakeQueryString(c *HttpClient, v url.Values) url.Values
MakeQueryString() function will create a usable query string prepopulated with the HTTP API credentials.
Types ¶
type ClickatellError ¶
type ClickatellError struct { Code string // contains filtered or unexported fields }
The ClickatellError struct is an extension of normal golang errors that allows us to add a Clickatell API error code to error objects
func MakeError ¶
func MakeError(err ErrorResponse) *ClickatellError
MakeError takes an ErrorResponse object from the API and turns it into a golang error
func (*ClickatellError) Error ¶
func (e *ClickatellError) Error() string
Error() function formats the error object to include the API error code as part of the error string
type ErrorResponse ¶
The Clickatell API can return certain errors and these errors are represented by an ErrorResponse object.
func (*ErrorResponse) GetError ¶
func (e *ErrorResponse) GetError() *ClickatellError
GetError() function will return a golang error if the ErrorResponse object has been populated.
func (*ErrorResponse) HasError ¶
func (e *ErrorResponse) HasError() bool
HasError() function will check if an error response has been populated or not.
type GetBalanceResponse ¶
type GetBalanceResponse struct { Error ErrorResponse `json:"error"` Data struct { Balance float64 `json:"balance,string"` } `json:"data"` }
GetBalanceResponse struct represents the response of a "getbalance" API call.
type HttpClient ¶
type HttpClient struct {
// contains filtered or unexported fields
}
HttpClient represents the Clickatell HTTP API and the credentials required to connect to it.
func Http ¶
Http() function will create a new HttpClient based on the authentication credentials and HTTP connection provided. The http.Client is optional and will use a default client if not defined.
func (*HttpClient) GetBalance ¶
func (c *HttpClient) GetBalance() (*GetBalanceResponse, error)
GetBalance() function returns the users balance as per Clickatell account status.
func (*HttpClient) Send ¶
func (c *HttpClient) Send(m Message) (*SendResponse, error)
Send() function allows a user to send a message as defined by the Message object passed to it.
type LegacyUnwrap ¶
LegacyUnwrap struct represents the result that was parsed from the Clickatell HTTP API. The API is older and does not always return consistent results.
func UnwrapLegacyLine ¶
func UnwrapLegacyLine(line string) *LegacyUnwrap
Since the HTTP API contains some inconsistent results, the UnwrapLegacyLine() function will parse these responses and return them as a struct with "known" properties. This function is used to create a bridge between the legacy response and a predictable response object.
func (*LegacyUnwrap) GetError ¶
func (l *LegacyUnwrap) GetError() *ClickatellError
GetError() function will return a golang error object (ClickatellError) if the response was unsuccessful.
func (*LegacyUnwrap) HasError ¶
func (l *LegacyUnwrap) HasError() bool
HasError() function will check if the unwrapped response was successful or not.
type Message ¶
type Message struct { Binary bool `url:"binary,omitempty" json:"binary,omitempty"` ClientMsgId string `url:"cliMsgId,omitempty" json:"clientMessageId,omitempty"` Concat int `url:"concat,omitempty" json:"maxMessageParts,omitempty"` DeliveryTime int `url:"deliv_time,omitempty" json:"-,omitempty"` DeliveryQueue int `url:"queue,omitempty" json: "userPriorityQueue,omitempty"` Destination []string `url:"-" json:"to"` Callback int `url:"callback,omitempty" json:"callback,omitempty"` Escalate bool `url:"escalate,omitempty" json:"escalate,omitempty"` MaxCredits int `url:"max_credits,omitempty" json:"maxCredits,omitempty"` Body string `url:"text" json:"text"` Mo bool `url:"mo,omitempty" json:"mo,omitempty"` ScheduledTime int `url:"scheduled_time,omitempty" json:"scheduledDeliveryTime,omitempty"` From string `url:"from,omitempty" json:"from,omitempty"` Unicode bool `url:"unicode,omitempty" json:"unicode,omitempty"` ValidityPeriod int `url:"validity,omitempty" json:"validityPeriod,omitempty"` }
The Message struct is a representation of a Clickatell SMS message. The properties of the message can be altered before using it to submit to the Send() method.
type RestClient ¶
type RestClient struct {
// contains filtered or unexported fields
}
RestClient struct represents an instance of a REST API connection based on the API token provided.
func Rest ¶
func Rest(apiToken string, client *http.Client) *RestClient
Rest() funciton creates a new REST connection instance based on the token and http.Client. The http.Client is optional and will use a default implementation if nil.
func (*RestClient) GetBalance ¶
func (c *RestClient) GetBalance() (*GetBalanceResponse, error)
GetBalance() function returns the users balance as per Clickatell account status.
func (*RestClient) Send ¶
func (c *RestClient) Send(in Message) (*SendResponse, error)
Send() function allows a user to send a message as defined by the Message object passed to it.
type SendResponse ¶
type SendResponse struct { Error ErrorResponse `json:"error"` Data struct { Message []SendResponseMessage `json:"message"` } `json:"data"` }
SendReponse struct represents the response of a "send" API call.
type SendResponseMessage ¶
type SendResponseMessage struct { To string `json:"to"` MessageId string `json:"apiMessageId"` Error ErrorResponse `json:"error"` }
SendResponseMessage struct represents the response of a message contained withing a "send" API call.