mirror of
https://github.com/nikoksr/notify.git
synced 2025-07-13 01:30:32 +02:00
feat(service): formatted code
This commit is contained in:
@ -1,54 +1,54 @@
|
|||||||
package textmagic
|
package textmagic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
tm "github.com/textmagic/textmagic-rest-go-v2/v2"
|
tm "github.com/textmagic/textmagic-rest-go-v2/v2"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TMagicService allow you to configure a TextMagic SDK client.
|
//TMagicService allow you to configure a TextMagic SDK client.
|
||||||
type TMagicService struct {
|
type TMagicService struct {
|
||||||
UserName string
|
UserName string
|
||||||
APIKey string
|
APIKey string
|
||||||
destinations []string
|
destinations []string
|
||||||
TextMagicAPIClient *tm.APIClient
|
TextMagicAPIClient *tm.APIClient
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTextMagicClient creates a new text magic client
|
//NewTextMagicClient creates a new text magic client
|
||||||
func NewTextMagicClient(userName, apiKey string) *TMagicService {
|
func NewTextMagicClient(userName, apiKey string) *TMagicService {
|
||||||
|
|
||||||
config := tm.NewConfiguration()
|
config := tm.NewConfiguration()
|
||||||
client := tm.NewAPIClient(config)
|
client := tm.NewAPIClient(config)
|
||||||
|
|
||||||
return &TMagicService{
|
return &TMagicService{
|
||||||
TextMagicAPIClient: client,
|
TextMagicAPIClient: client,
|
||||||
UserName: userName,
|
UserName: userName,
|
||||||
APIKey: apiKey,
|
APIKey: apiKey,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddReceivers adds the given destination phone numbers to the notifier.
|
// AddReceivers adds the given destination phone numbers to the notifier.
|
||||||
func (s *TMagicService) AddReceivers(phoneNumbers ...string) {
|
func (s *TMagicService) AddReceivers(phoneNumbers ...string) {
|
||||||
s.destinations = append(s.destinations, phoneNumbers...)
|
s.destinations = append(s.destinations, phoneNumbers...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send sends a SMS via TextMagic to all previously added receivers.
|
// Send sends a SMS via TextMagic to all previously added receivers.
|
||||||
func (s *TMagicService) Send(ctx context.Context, subject, message string) error {
|
func (s *TMagicService) Send(ctx context.Context, subject, message string) error {
|
||||||
|
|
||||||
// put your Username and API Key from https://my.textmagic.com/online/api/rest-api/keys page.
|
// put your Username and API Key from https://my.textmagic.com/online/api/rest-api/keys page.
|
||||||
auth := context.WithValue(context.Background(), tm.ContextBasicAuth, tm.BasicAuth{
|
auth := context.WithValue(context.Background(), tm.ContextBasicAuth, tm.BasicAuth{
|
||||||
UserName: s.UserName,
|
UserName: s.UserName,
|
||||||
Password: s.APIKey,
|
Password: s.APIKey,
|
||||||
})
|
})
|
||||||
|
|
||||||
text := subject + "\n" + message
|
text := subject + "\n" + message
|
||||||
_, _, err := s.TextMagicAPIClient.TextMagicApi.SendMessage(auth, tm.SendMessageInputObject{
|
_, _, err := s.TextMagicAPIClient.TextMagicApi.SendMessage(auth, tm.SendMessageInputObject{
|
||||||
Text: text,
|
Text: text,
|
||||||
Phones: strings.Join(s.destinations, ","),
|
Phones: strings.Join(s.destinations, ","),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user