Skip to content

Instantly share code, notes, and snippets.

@chuprik
Last active April 11, 2016 21:42
Show Gist options
  • Save chuprik/ce9dc26d5ccd3fc052b399f2c7a9844c to your computer and use it in GitHub Desktop.
Save chuprik/ce9dc26d5ccd3fc052b399f2c7a9844c to your computer and use it in GitHub Desktop.
const (
twilioAuth = "Basic {base64}" // https://www.twilio.com/docs/quickstart/php/lookups
)
// doTwilioCheck returns true if exists
func doTwilioCheck(number string) (exists bool, err error) {
url := fmt.Sprintf("https://lookups.twilio.com/v1/PhoneNumbers/%s", number)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return false, err
}
req.Header.Add("authorization", twilioAuth)
res, err := http.DefaultClient.Do(req)
if err != nil {
return false, err
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return false, err
}
var parsed map[string]interface{}
err = json.Unmarshal(body, &parsed)
if err != nil {
return false, err
}
return parsed["status"] == nil, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment