From 3b5df9f78fb7938446bf695400a83de7415b88cb Mon Sep 17 00:00:00 2001 From: Adrian Gallagher Date: Mon, 24 Nov 2014 00:01:59 +1100 Subject: [PATCH] Added SMSGlobal HTTP support. --- smsglobal.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 smsglobal.go diff --git a/smsglobal.go b/smsglobal.go new file mode 100644 index 00000000..94c65080 --- /dev/null +++ b/smsglobal.go @@ -0,0 +1,45 @@ +package main + +import ( + "net/http" + "net/url" + "strings" + "fmt" + "io/ioutil" + "errors" +) + +const ( + SMSGLOBAL_API_URL = "http://www.smsglobal.com/http-api.php" +) + +func SMSNotify(username, password, from, to, message string) (error) { + values := url.Values{} + values.Set("action", "sendsms") + values.Set("user", username) + values.Set("password", password) + values.Set("from", from) + values.Set("to", to) + values.Set("text", message) + + reqBody := strings.NewReader(values.Encode()) + req, err := http.NewRequest("POST", SMSGLOBAL_API_URL, reqBody) + + if err != nil { + return err + } + + req.Header.Add("Content-Type", "application/x-www-form-urlencoded") + + client := &http.Client{} + resp, err := client.Do(req) + + if err != nil { + return errors.New("PostRequest: Unable to send request") + } + + contents, _ := ioutil.ReadAll(resp.Body) + fmt.Printf("Recieved raw: %s\n", string(contents)) + resp.Body.Close() + return nil +} \ No newline at end of file