Skip to content

Instantly share code, notes, and snippets.

@Ramya-Raghu
Created June 4, 2016 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ramya-Raghu/ae7f41fe55af1b74aa768204af7fc2ea to your computer and use it in GitHub Desktop.
Save Ramya-Raghu/ae7f41fe55af1b74aa768204af7fc2ea to your computer and use it in GitHub Desktop.
package main
import (
"net/http"
"io/ioutil"
"fmt"
"bytes"
)
func main() {
send_sms()
make_call()
}
func send_sms(){
// Set initial variables
authId := "Your AUTH ID"
authToken := "Your AUTH TOKEN"
urlStr := "https://api.plivo.com/v1/Account/" + authId + "/Message/"
var jsonprep string = `{"src":"18583650857","dst":"18583650856","text":"Hello"}`
var jsonStr = []byte(jsonprep)
// Create client
client := &http.Client{}
req, err := http.NewRequest("POST", urlStr, bytes.NewBuffer(jsonStr))
req.SetBasicAuth(authId, authToken)
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json")
// Make request
resp, _ := client.Do(req)
if err != nil {
fmt.Println("Unable to reach the server.")
} else {
fmt.Println(resp.Status)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("body=", string(body))
}
}
func make_call(){
// Set initial variables
authId := "Your AUTH ID"
authToken := "Your AUTH TOKEN"
urlStr := "https://api.plivo.com/v1/Account/" + authId + "/Call/"
var jsonprep string = `{"from":"18583650857","to":"18583650856","answer_url":"https://s3.amazonaws.com/static.plivo.com/answer.xml","answer_method":"GET"}`
var jsonStr = []byte(jsonprep)
// Create client
client := &http.Client{}
req, err := http.NewRequest("POST", urlStr, bytes.NewBuffer(jsonStr))
req.SetBasicAuth(authId, authToken)
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json")
// Make request
resp, _ := client.Do(req)
if err != nil {
fmt.Println("Unable to reach the server.")
} else {
fmt.Println(resp.Status)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("body=", string(body))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment