Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sundowndev
GitHub Repository: sundowndev/phoneinfoga
Path: blob/master/lib/remote/numverify_scanner.go
988 views
1
package remote
2
3
import (
4
"errors"
5
"github.com/sundowndev/phoneinfoga/v2/lib/number"
6
"github.com/sundowndev/phoneinfoga/v2/lib/remote/suppliers"
7
)
8
9
const Numverify = "numverify"
10
11
type numverifyScanner struct {
12
client suppliers.NumverifySupplierInterface
13
}
14
15
type NumverifyScannerResponse struct {
16
Valid bool `json:"valid" console:"Valid"`
17
Number string `json:"number" console:"Number,omitempty"`
18
LocalFormat string `json:"local_format" console:"Local format,omitempty"`
19
InternationalFormat string `json:"international_format" console:"International format,omitempty"`
20
CountryPrefix string `json:"country_prefix" console:"Country prefix,omitempty"`
21
CountryCode string `json:"country_code" console:"Country code,omitempty"`
22
CountryName string `json:"country_name" console:"Country name,omitempty"`
23
Location string `json:"location" console:"Location,omitempty"`
24
Carrier string `json:"carrier" console:"Carrier,omitempty"`
25
LineType string `json:"line_type" console:"Line type,omitempty"`
26
}
27
28
func NewNumverifyScanner(s suppliers.NumverifySupplierInterface) Scanner {
29
return &numverifyScanner{client: s}
30
}
31
32
func (s *numverifyScanner) Name() string {
33
return Numverify
34
}
35
36
func (s *numverifyScanner) Description() string {
37
return "Request info about a given phone number through the Numverify API."
38
}
39
40
func (s *numverifyScanner) DryRun(_ number.Number, opts ScannerOptions) error {
41
if opts.GetStringEnv("NUMVERIFY_API_KEY") != "" {
42
return nil
43
}
44
return errors.New("API key is not defined")
45
}
46
47
func (s *numverifyScanner) Run(n number.Number, opts ScannerOptions) (interface{}, error) {
48
apiKey := opts.GetStringEnv("NUMVERIFY_API_KEY")
49
50
res, err := s.client.Request().SetApiKey(apiKey).ValidateNumber(n.International)
51
if err != nil {
52
return nil, err
53
}
54
55
data := NumverifyScannerResponse{
56
Valid: res.Valid,
57
Number: res.Number,
58
LocalFormat: res.LocalFormat,
59
InternationalFormat: res.InternationalFormat,
60
CountryPrefix: res.CountryPrefix,
61
CountryCode: res.CountryCode,
62
CountryName: res.CountryName,
63
Location: res.Location,
64
Carrier: res.Carrier,
65
LineType: res.LineType,
66
}
67
68
return data, nil
69
}
70
71