Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sundowndev
GitHub Repository: sundowndev/phoneinfoga
Path: blob/master/lib/remote/ovh_scanner.go
988 views
1
package remote
2
3
import (
4
"fmt"
5
"github.com/sundowndev/phoneinfoga/v2/lib/number"
6
"github.com/sundowndev/phoneinfoga/v2/lib/remote/suppliers"
7
)
8
9
const OVH = "ovh"
10
11
type ovhScanner struct {
12
client suppliers.OVHSupplierInterface
13
}
14
15
// OVHScannerResponse is the OVH scanner response
16
type OVHScannerResponse struct {
17
Found bool `json:"found" console:"Found"`
18
NumberRange string `json:"number_range,omitempty" console:"Number range,omitempty"`
19
City string `json:"city,omitempty" console:"City,omitempty"`
20
ZipCode string `json:"zip_code,omitempty" console:"Zip code,omitempty"`
21
}
22
23
func NewOVHScanner(s suppliers.OVHSupplierInterface) Scanner {
24
return &ovhScanner{client: s}
25
}
26
27
func (s *ovhScanner) Name() string {
28
return OVH
29
}
30
31
func (s *ovhScanner) Description() string {
32
return "Search a phone number through the OVH Telecom REST API."
33
}
34
35
func (s *ovhScanner) DryRun(n number.Number, _ ScannerOptions) error {
36
if !s.isSupported(n.CountryCode) {
37
return fmt.Errorf("country code %d is not supported", n.CountryCode)
38
}
39
return nil
40
}
41
42
func (s *ovhScanner) Run(n number.Number, _ ScannerOptions) (interface{}, error) {
43
res, err := s.client.Search(n)
44
if err != nil {
45
return nil, err
46
}
47
48
data := OVHScannerResponse{
49
Found: res.Found,
50
NumberRange: res.NumberRange,
51
City: res.City,
52
ZipCode: res.ZipCode,
53
}
54
55
return data, nil
56
}
57
58
func (s *ovhScanner) supportedCountryCodes() []int32 {
59
// See https://api.ovh.com/console/#/telephony/number/detailedZones#GET
60
return []int32{33, 32, 44, 34, 41}
61
}
62
63
func (s *ovhScanner) isSupported(code int32) bool {
64
supported := false
65
for _, c := range s.supportedCountryCodes() {
66
if code == c {
67
supported = true
68
}
69
}
70
return supported
71
}
72
73