-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFullNameMatchScore.go
41 lines (31 loc) · 1.43 KB
/
FullNameMatchScore.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Generates a matching score from 0-100, where 100 is the highest, on how closely
// two individual full names match. The scoring is based on a series of tests,
// algorithms, AI, and an ever-growing body of Machine Learning-based generated knowledge.
package FullNameMatchScore
// visit www.interzoid.com to obtain the required API license key - free trial available
import (
"encoding/json"
"errors"
"net/http"
url2 "net/url"
)
// used to retrieve the data payload from the Interzoid API
type payload struct {
Score string // match score
Code string // success or fail
Credits string // credits remaining for this API license key
}
// this function takes two individual names and the API license key and returns the match score
func GetScore(license,fullname1,fullname2 string) (string, string, string, error) {
response, err := http.Get("https://api.interzoid.com/getfullnamematchscore?license="+url2.QueryEscape(license)+"&fullname1="+url2.QueryEscape(fullname1)+"&fullname2="+url2.QueryEscape(fullname2))
if err != nil || response.StatusCode != 200 {
switch response.StatusCode {
case 403 : response.Status = "Invalid API license key. Register at www.interzoid.com"
case 400 : response.Status = "Invalid parameters"
}
return "0","Fail","0",errors.New(response.Status)
}
thePayload := payload{}
json.NewDecoder(response.Body).Decode(&thePayload)
return thePayload.Score,thePayload.Code,thePayload.Credits,nil
}