Documentation ¶
Index ¶
Examples ¶
Constants ¶
const DefaultBulkURL = "https://restfulsms.com/api"
DefaultBulkURL is used to send requests to SMS provider by default.
const TokenTimeOut = 20 * time.Minute
TokenTimeOut indicates refresh time of the token for accessing APIs.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BulkSMS ¶
type BulkSMS struct { BaseURL string Token TokenProvider }
func (*BulkSMS) GetCredit ¶
GetCredit fetches the amount of the SMS count that remains on the account. It uses the token that provides by the Token.Get() method.
Example ¶
package main import ( "github.com/amirhosseinab/gosms" "log" ) func main() { tp := gosms.NewToken(gosms.Config{ APIKey: "YOUR_API_KEY", SecretKey: "YOUR_SECRET_KEY", }) client := gosms.NewBulkSMSClient(tp, gosms.DefaultBulkURL) credit, err := client.GetCredit() if err != nil { log.Fatal(err) } log.Printf("Your credit is: %d", credit) }
Output:
func (*BulkSMS) SendByTemplate ¶
func (b *BulkSMS) SendByTemplate(mobile string, templateId int, params map[string]string) (string, error)
SendByTemplate sends a bunch of key-value pair of data with a provided template(TemplateId) to the given mobile number.
Example ¶
package main import ( "github.com/amirhosseinab/gosms" "log" ) func main() { token := gosms.NewToken(gosms.Config{ APIKey: "YOUR_API_KEY", SecretKey: "YOUR_SECRET_KEY", }) client := gosms.NewBulkSMSClient(token, gosms.DefaultBulkURL) vId, err := client.SendByTemplate("09121234567", 1234, map[string]string{"VerificationCode": "9999"}) if err != nil { log.Fatal(err) return } log.Printf("Verification Id is %s", vId) }
Output:
func (*BulkSMS) SendVerificationCode ¶
SendVerificationCode sends a value(code) with default message template to the provided mobile number.
Example ¶
package main import ( "github.com/amirhosseinab/gosms" "log" ) func main() { token := gosms.NewToken(gosms.Config{ APIKey: "YOUR_API_KEY", SecretKey: "YOUR_SECRET_KEY", }) client := gosms.NewBulkSMSClient(token, gosms.DefaultBulkURL) vId, err := client.SendVerificationCode("09121234567", "123456") if err != nil { log.Fatal(err) return } log.Printf("Verification Id is %s", vId) }
Output:
type BulkSMSProvider ¶
type BulkSMSProvider interface { GetCredit() (int, error) SendVerificationCode(mobile, code string) (string, error) SendByTemplate(mobile string, templateId int, params map[string]string) (string, error) }
BulkSMSProvider exposes the methods of bulk SMS system.
func NewBulkSMSClient ¶
func NewBulkSMSClient(token TokenProvider, url string) BulkSMSProvider
NewBulkSMSClient creates a value that handles all requests for bulk SMS system.
type TokenProvider ¶
TokenProvider is used to fetch the token from the server.
func NewToken ¶
func NewToken(config Config) TokenProvider
NewToken provides value for fetching token from the server.