-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompanyNameSimKey.go
42 lines (32 loc) · 1.59 KB
/
CompanyNameSimKey.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
41
// Provides a hashed similarity key from the input data used to match with other similar company name data.
// Use the generated similarity key, rather than the actual data itself, to match and/or sort company
// name data by similarity. This avoids the problems of data inconsistency, misspellings, and name variations
// when matching within a single dataset, and can also help matching across datasets or for more advanced searching.
package CompanyNameSimKey
// 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 {
SimKey string // generated similarity key
Code string // success or fail
Credits string // credits remaining for this API license key
}
// this function takes a company name and an API license key and returns the generated similarity key
func GetSimKey(license,company string) (string, string, string, error) {
response, err := http.Get("https://api.interzoid.com/getcompanymatchadvanced?license="+url2.QueryEscape(license)+"&company="+url2.QueryEscape(company)+"&algorithm=wide")
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 "","Fail","0",errors.New(response.Status)
}
thePayload := payload{}
json.NewDecoder(response.Body).Decode(&thePayload)
return thePayload.SimKey,thePayload.Code,thePayload.Credits,nil
}