Last active
April 11, 2016 21:42
-
-
Save chuprik/ce9dc26d5ccd3fc052b399f2c7a9844c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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