Skip to content

Commit

Permalink
Address review comments in PR #49
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Swarbrick <[email protected]>
  • Loading branch information
dswarbrick committed Sep 18, 2018
1 parent 3fbcb07 commit d4f6b9b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
1 change: 0 additions & 1 deletion examples/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ providers:
sipgate:
username: 'username'
password: 'password'
url: "https://api.sipgate.com/v2/sessions/sms"

receivers:
- name: 'team-sms'
Expand Down
14 changes: 5 additions & 9 deletions provider/sipgate/sipgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import (
"github.com/messagebird/sachet"
)

const sipgateURL = "https://api.sipgate.com/v2/sessions/sms"

var sipgateHTTPClient = &http.Client{Timeout: time.Second * 20}

// Config is the configuration struct for Sipgate provider
type Config struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
URL string `yaml:"url"`
}

// Sipgate contains the necessary values for the Sipgate provider
Expand All @@ -26,9 +27,6 @@ type Sipgate struct {

// NewSipgate creates and returns a new Sipgate struct
func NewSipgate(config Config) *Sipgate {
if config.URL == "" {
config.URL = "https://api.sipgate.com/v2/sessions/sms"
}
return &Sipgate{config}
}

Expand All @@ -41,20 +39,18 @@ type payload struct {
// Send sends SMS to user registered in configuration
func (c *Sipgate) Send(message sachet.Message) error {
for _, recipient := range message.To {
var body bytes.Buffer

params := payload{
SmsID: message.From,
Recipient: recipient,
Message: message.Text,
}

enc := json.NewEncoder(&body)
if err := enc.Encode(params); err != nil {
data, err := json.Marshal(params)
if err != nil {
return err
}

request, err := http.NewRequest("POST", c.URL, &body)
request, err := http.NewRequest("POST", sipgateURL, bytes.NewBuffer(data))
if err != nil {
return err
}
Expand Down

0 comments on commit d4f6b9b

Please sign in to comment.