inforusms

package module
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

README

inforu_sms

Sending and getting SMS from Israeli SMS operator - Shamir (InforU Mobile) using Golang

Documentation

Index

Constants

View Source
const (
	HTTPSAPIAddress = `https://api.inforu.co.il/SendMessageXml.ashx`
	HTTPArg         = `InforuXML`
	HTTPMethod      = `POST`
	HTTPContentType = `application/x-www-form-urlencoded`
	TimeFormat      = `01/02/2006 15:04`
)

HTTP(s) address to send the API

Variables

This section is empty.

Functions

func Callback

func Callback(h smshandler.HTTPHandler, path string, mux *http.ServeMux,
	onCallback func(http.ResponseWriter, *http.Request, *DeliveryInfo, error))

Callback for having callback function

Types

type Content

type Content struct {
	XMLName xml.Name `xml:"Content"`
	Type    string   `xml:"Type,attr"`
	Message string   `xml:"Message"`
}

Content holds message information

type DeliveryInfo

type DeliveryInfo struct {
	XMLName           xml.Name       `xml:"IncomingData"`
	ActionType        string         `xml:"ActionType"`
	OriginalMessage   string         `xml:"OriginalMessage"`
	Price             string         `xml:"Price"`
	CustomerParam     string         `xml:"CustomerParam"`
	SenderNumber      string         `xml:"SenderNumber"`
	PhoneNumber       string         `xml:"PhoneNumber"`
	Network           string         `xml:"Network"`
	Status            DeliveryStatus `xml:"Status"`
	StatusDescription string         `xml:"StatusDescription"`
	CustomerMessageID int64          `xml:"CustomerMessageId"`
	SegmentsNumber    int            `xml:"SegmentsNumber"`
	RetriesNumber     uint           `xml:"RetriesNumber"`
	ID                string         `xml:"id"`
	NotificationDate  time.Time      `xml:"NotificationDate"`
	ProjectID         string         `xml:"ProjectId"`
	BillingCodeID     string         `xml:"BillingCodeId"`
}

DeliveryInfo holds information regarding delivery status arrived back as callback

func FormToDeliveryInfo

func FormToDeliveryInfo(form url.Values) *DeliveryInfo

FormToDeliveryInfo takes form fields and place converts them into DeliveryInfo

type DeliveryStatus

type DeliveryStatus int

DeliveryStatus holds callback delivery status that returned by the server

const (
	DeliveryStatusDelivered             DeliveryStatus = 2
	DeliveryStatusNotDelivered          DeliveryStatus = -2
	DeliveryStatusBlockedByInforuMobile DeliveryStatus = -4
)

DeliveryStatus statuses

func DeliveryStatusFromString

func DeliveryStatusFromString(str string) DeliveryStatus

DeliveryStatusFromString initialize DeliveryStatus based on string parsing. If failed it returns 0

func (DeliveryStatus) IsDelivered

func (ds DeliveryStatus) IsDelivered() bool

IsDelivered check to see if given DeliveryStatus delivered

func (DeliveryStatus) MarshalXML

func (ds DeliveryStatus) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements XML marshaling for DeliveryStatus

func (*DeliveryStatus) Scan

func (ds *DeliveryStatus) Scan(src interface{}) error

Scan implements the database interface for Scan

func (DeliveryStatus) String

func (ds DeliveryStatus) String() string

func (*DeliveryStatus) UnmarshalXML

func (ds *DeliveryStatus) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implement unmarshaling for DeliveryStatus

func (DeliveryStatus) Value

func (ds DeliveryStatus) Value() (driver.Value, error)

Value implements the database interface of Value

type HTTPHandler

type HTTPHandler struct {
	Client *http.Client
}

HTTPHandler perform HTTP actions, and implement

func (HTTPHandler) DoHTTP

func (h HTTPHandler) DoHTTP(
	method, contentType, address string, fields url.Values, body []byte) (resp *http.Response, err error)

DoHTTP sends an HTTP Request for sending an SMS

func (HTTPHandler) OnGettingSMS

func (h HTTPHandler) OnGettingSMS(path string, mux *http.ServeMux, httpHandler http.HandlerFunc)

OnGettingSMS is an HTTP server handler when incoming SMS arrives. If mux exists, it will use it for a server, otherwise it will use http.HandleFunc.

type InforuMultiXML

type InforuMultiXML struct {
	XMLName   xml.Name    `xml:"InforuRoot"`
	InforuXML []InforuXML `xml:"Inforu"`
}

InforuMultiXML generate multiple messages in one XML message

func (InforuMultiXML) SendSMS

func (x InforuMultiXML) SendSMS(h HTTPHandler) (*http.Response, error)

SendSMS sends the given SMS to InforU based on HTTP client

type InforuXML

type InforuXML struct {
	XMLName    xml.Name   `xml:"Inforu"`
	Auth       UserAuth   `xml:"User"`
	Content    Content    `xml:"Content"`
	Recipients Recipients `xml:"Recipients"`
	Settings   Settings   `xml:"Settings"`
}

InforuXML holds XML information for simple message to be sent, can support multiple phone numbers separated by semi-colon.

Simple XML:

<Inforu>
   <User>
     <Username>MyUsername</Username>
     <Password>MyPassword</Password>
   </User>
   <Content Type="sms">
     <Message>This is a test SMS Message</Message>
   </Content>
   <Recipients>
     <PhoneNumber>0501111111;0502222222</PhoneNumber>
   </Recipients>
   <Settings>
     <Sender>0501111111</Sender>
   </Settings>
 </Inforu>

Advanced XML

<Inforu>
  <User>
    <Username>MyUserName</Username>
    <Password>MyPassword</Password>
  </User>
  <Content Type="sms">
    <Message> This is a test SMS Message </Message>
  </Content>
  <Recipients>
    <PhoneNumber>0501111111;0502222222</PhoneNumber>
    <GroupNumber>5</GroupNumber>
  </Recipients>
  <Settings>
    <Sender>Inforu</Sender>
    <CustomerMessageID>112233</CustomerMessageID>
    <CustomerParameter>AffId4</CustomerParameter>
    <MessageInterval>0</MessageInterval>
    <TimeToSend>12/05/2013 12:23</TimeToSend>
    <DelayInSeconds>60</DelayInSeconds>
    <DeliveryNotificationUrl>http://mysite.co.il/Notif.aspx</DeliveryNotificationUrl>
    <MaxSegments>0</MaxSegments>
  </Settings>
</Inforu>

func (InforuXML) SendSMS

func (x InforuXML) SendSMS(h HTTPHandler) (*http.Response, error)

SendSMS sends the given SMS to InforU based on HTTP client

type Recipients

type Recipients struct {
	XMLName     xml.Name `xml:"Recipients"`
	PhoneNumber string   `xml:"PhoneNumber"`
	GroupNumber string   `xml:"GroupNumber,omitempty"`
}

Recipients holds contact information about phone numbers, seperated by semi-colon

type ResponseStatus

type ResponseStatus int

ResponseStatus holds information regarding the given response back from the server

const (
	StatusOK                          ResponseStatus = 1
	StatusFailed                      ResponseStatus = -1
	StatusBadUserNameOrPassword       ResponseStatus = -2
	StatusUserNameNotExist            ResponseStatus = -3
	StatusPasswordNotExists           ResponseStatus = -4
	StatusRecipientsDataNotExists     ResponseStatus = -6
	StatusMessageTextNotExists        ResponseStatus = -9
	StatusIllegalXML                  ResponseStatus = -11
	StatusUserQuotaExceeded           ResponseStatus = -13
	StatusProjectQuotaExceeded        ResponseStatus = -14
	StatusCustomerQuotaExceeded       ResponseStatus = -15
	StatusWrongDateTime               ResponseStatus = -16
	StatusNoValidRecipients           ResponseStatus = -18
	StatusInvalidSenderNumber         ResponseStatus = -20
	StatusInvalidSenderName           ResponseStatus = -21
	StatusUserBlocked                 ResponseStatus = -22
	StatusUserAuthenticationError     ResponseStatus = -26
	StatusNetworkTypeNotSupported     ResponseStatus = -28
	StatusNotAllNetworkTypesSupported ResponseStatus = -29
	StatusSenderIdentification        ResponseStatus = -90
)

Statuses

func (ResponseStatus) IsOK

func (s ResponseStatus) IsOK() bool

IsOK check to see if given ResponseStatus does not contain any error

func (ResponseStatus) MarshalXML

func (s ResponseStatus) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements XML marshaling for ResponseStatus

func (*ResponseStatus) Scan

func (s *ResponseStatus) Scan(src interface{}) error

Scan implements the database interface for Scan

func (ResponseStatus) String

func (s ResponseStatus) String() string

func (*ResponseStatus) UnmarshalXML

func (s *ResponseStatus) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implement unmarshaling for ResponseStatus

func (ResponseStatus) Value

func (s ResponseStatus) Value() (driver.Value, error)

Value implements the database interface of Value

type SMSError

type SMSError struct {
	Status      ResponseStatus
	Description string
	Effected    int64
}

SMSError holds information about sending information

func (SMSError) Error

func (e SMSError) Error() string

type Settings

type Settings struct {
	XMLName                 xml.Name `xml:"Settings"`
	Sender                  string   `xml:"Sender"`
	CustomerMessageID       string   `xml:"CustomerMessageID,omitempty"`
	CustomerParameter       string   `xml:"CustomerParameter,omitempty"`
	MessageInterval         int      `xml:"MessageInterval,omitempty"`
	TimeToSend              string   `xml:"TimeToSend,omitempty"`
	MaxSegments             int      `xml:"MaxSegments,omitempty"`
	DelayInSeconds          int64    `xml:"DelayInSeconds,omitempty"`
	DeliveryNotificationURL string   `xml:"DeliveryNotificationUrl,omitempty"`
	Priority                int      `xml:"priority,omitempty"`
}

Settings holds information regarding the sender and the sending of a message

type UserAuth

type UserAuth struct {
	XMLName  xml.Name `xml:"User"`
	UserName string   `xml:"Username"`
	Password string   `xml:"Password"`
}

UserAuth holds fields for User Authentication

type XMLResponse

type XMLResponse struct {
	XMLName            xml.Name       `xml:"Result"`
	Status             ResponseStatus `xml:"Status"`
	Description        string         `xml:"Description"`
	NumberOfRecipients int64          `xml:"NumberOfRecipients"`
}

XMLResponse holds the content for the answer arrived back for the request

<Result>
  <Status></Status>
  <Description></Description>
  <NumberOfRecipients></NumberOfRecipients>
</Result>

func (*XMLResponse) FromResponse

func (r *XMLResponse) FromResponse(buf []byte) error

FromResponse convert the body to XMLResponse, or error if something bad happened

func (XMLResponse) IsOK

func (r XMLResponse) IsOK() bool

IsOK Implements the interface to know if response holds success or not

func (XMLResponse) ToError

func (r XMLResponse) ToError() error

ToError converts XMLResponse to SMSError. If everything is ok, it will return nil

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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