gophonenumbers

package module
v0.4.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2024 License: MIT Imports: 18 Imported by: 3

README

GoPhoneNumbers

Build Status Go Report Card Docs License

This library provides phone number information functionality including ability to access number look up APIs. It includes a Go client and CLI app for the Numverify API, and Twilio API.

https://numverify.com/documentation

Installation

Install Command
SDK only $ go get github.com/grokify/gophonenumbers
CLI only $ go get github.com/grokify/gophonenumbers/apps/numverify
SDK and CLI $ go get github.com/grokify/gophonenumbers/...

Usage

CLI App
Options Long Short Example
.env File --env -e -e=/path/to/.env
Access Token --token -t -t=<myToken>
Validate Number --number -n -n=<number>
List Countries --countries -c -c
Example Commands
$ numverify -e=/path/to/.env -n=+16505550100
$ numverify -t=<myToken> -n=+16505550100
$ numverify -e=/path/to/.env -c
$ numverify -t=<myToken> -c
SDK
Validate Number
import(
	nv "github.com/grokify/gophonenumbers/numverify"
)

func main() {
	client := nv.NumverifyClient{AccessKey: "myAccessKey"}

	apiSuccessInfo, apiErrorInfo, resp, err := client.Validate(
		nv.NumverifyParams{Number: number})

	[...]
}
Get Countries
import(
	nv "github.com/grokify/gophonenumbers/numverify"
)

func main() {
	client := nv.NumverifyClient{AccessKey: "myAccessKey"}

	countries, apiErrorInfo, resp, err := client.Countries()

	[...]
}

Documentation

Index

Constants

View Source
const (
	CarrierATT     = "att"
	CarrierSprint  = "sprint"
	CarrierTMobile = "tmobile"
	CarrierVerizon = "verizon"

	LineTypeLocal    = "local"
	LineTypeMobile   = "mobile"
	LineTypeTollFree = "tollfree"

	SourceEkata     = "ekata"
	SourceNumverify = "numverify"
	SourcePlivo     = "plivo"
	SourceTwilio    = "twilio"
)
View Source
const (
	A2gCsvRelPath = "github.com/grokify/mogo/strconv/phonenumber/us-area-code-geo.csv"
)

Variables

This section is empty.

Functions

func A2gCsvFullPath added in v0.3.0

func A2gCsvFullPath() string

A2gCsvFullPath reads data from: https://github.com/ravisorg/Area-Code-Geolocation-Database

func E164Format added in v0.3.0

func E164Format(numberToParse, defaultRegion string, numberFormat phonenumbers.PhoneNumberFormat) (string, error)

func LetterToNumberMap added in v0.3.0

func LetterToNumberMap() map[string]int

func LocalNumberUS added in v0.3.0

func LocalNumberUS(ac uint16, ln uint16) uint64

LocalNumberUS returns a US E.164 number given an areacode and line number

func MustE164Format added in v0.3.0

func MustE164Format(numberToParse, defaultRegion string, numberFormat phonenumbers.PhoneNumberFormat) string

func NewPointString added in v0.3.0

func NewPointString(lat string, lon string) (*geo.Point, error)

NewPointString returns a *geo.Point based on string lat and lon values.

func StringToNumbers added in v0.3.0

func StringToNumbers(s string) string

Types

type AreaCodeIncrementor added in v0.3.0

type AreaCodeIncrementor struct {
	Counter map[uint16]uint16
	Base    uint16
}

func NewAreaCodeIncrementor added in v0.3.0

func NewAreaCodeIncrementor(base uint16) AreaCodeIncrementor

func (*AreaCodeIncrementor) GetNext added in v0.3.0

func (aci *AreaCodeIncrementor) GetNext(ac uint16) uint64

type AreaCodeInfo added in v0.3.0

type AreaCodeInfo struct {
	AreaCode uint16
	Point    *geo.Point
}

func NewAreaCodeInfoStrings added in v0.3.0

func NewAreaCodeInfoStrings(ac, lat, lon string) (AreaCodeInfo, error)

NewAreaCodeInfoStrings returns an AreaCodeInfo based on string area code, lat and lon values.

type AreaCodeToGeo added in v0.3.0

type AreaCodeToGeo struct {
	AreaCodeInfos  map[uint16]AreaCodeInfo
	DistanceMatrix map[uint16]map[uint16]float64
}

func NewAreaCodeToGeo added in v0.3.0

func NewAreaCodeToGeo() AreaCodeToGeo

func (*AreaCodeToGeo) AreaCodeSlice added in v0.3.0

func (a2g *AreaCodeToGeo) AreaCodeSlice() []AreaCodeInfo

func (*AreaCodeToGeo) AreaCodes added in v0.3.0

func (a2g *AreaCodeToGeo) AreaCodes() []uint16

func (*AreaCodeToGeo) AreaCodesSorted added in v0.3.0

func (a2g *AreaCodeToGeo) AreaCodesSorted() []uint16

func (*AreaCodeToGeo) GcdAreaCodes added in v0.3.0

func (a2g *AreaCodeToGeo) GcdAreaCodes(ac1Int uint16, ac2Int uint16) (float64, error)

func (*AreaCodeToGeo) GetDistanceMatrix added in v0.3.0

func (a2g *AreaCodeToGeo) GetDistanceMatrix() map[uint16]map[uint16]float64

func (*AreaCodeToGeo) Inflate added in v0.3.0

func (a2g *AreaCodeToGeo) Inflate()

func (*AreaCodeToGeo) ReadCsvPath added in v0.3.0

func (a2g *AreaCodeToGeo) ReadCsvPath(csvpath string) error

func (*AreaCodeToGeo) ReadData added in v0.3.0

func (a2g *AreaCodeToGeo) ReadData() error

type CarrierNumberInfo added in v0.2.0

type CarrierNumberInfo struct {
	E164Number        string `json:"e164Number"`
	MobileCountryCode string `json:"mobileCountryCode,omitempty"`
	MobileNetworkCode string `json:"mobileNetworkCode,omitempty"`
	Name              string `json:"name,omitempty"`
	LineType          string `json:"lineType,omitempty"`
	ErrorCode         string `json:"errorCode,omitempty"`
}

type Components

type Components struct {
	E164Number       string
	E164NumberUint   uint
	RegionCode       string
	CountryCode      uint
	NANPAreaCode     uint // NPA - Numbering plan area code
	NANPExchangeCode uint // NXX - Central office (exchange) code
	NANPLineNumber   uint // xxxx - Line number or subscriber number
}

type FakeNumberGenerator added in v0.3.0

type FakeNumberGenerator struct {
	AreaCodes []uint16
}

func NewFakeNumberGenerator added in v0.3.0

func NewFakeNumberGenerator(areacodes []uint16) FakeNumberGenerator

func (*FakeNumberGenerator) LocalNumberUS added in v0.3.0

func (fng *FakeNumberGenerator) LocalNumberUS(ac uint16, ln uint16) uint64

LocalNumberUS returns a US E.164 number given an areacode and line number

func (*FakeNumberGenerator) RandomAreaCode added in v0.3.0

func (fng *FakeNumberGenerator) RandomAreaCode() uint16

RandomAreaCode generates a random area code.

func (*FakeNumberGenerator) RandomLineNumber added in v0.3.0

func (fng *FakeNumberGenerator) RandomLineNumber() uint16

RandomLineNumber generates a random line number

func (*FakeNumberGenerator) RandomLineNumberMinMax added in v0.3.0

func (fng *FakeNumberGenerator) RandomLineNumberMinMax(min, max uint16) uint16

RandomLineNumber generates a random line number

func (*FakeNumberGenerator) RandomLocalNumberUS added in v0.3.0

func (fng *FakeNumberGenerator) RandomLocalNumberUS() (uint64, error)

RandomLocalNumberUS returns a US E.164 number AreaCode + Prefix + Line Number

func (*FakeNumberGenerator) RandomLocalNumberUSAreaCodes added in v0.3.0

func (fng *FakeNumberGenerator) RandomLocalNumberUSAreaCodes(acs []uint16) uint64

RandomLocalNumberUS returns a US E.164 number AreaCode + Prefix + Line Number

func (*FakeNumberGenerator) RandomLocalNumberUSUnique added in v0.3.0

func (fng *FakeNumberGenerator) RandomLocalNumberUSUnique(set map[uint64]int8) (uint64, map[uint64]int8, error)

RandomLocalNumberUSUnique returns a US E.164 number AreaCode + Prefix + Line Number

func (*FakeNumberGenerator) RandomLocalNumberUSUniqueAreaCodeSet added in v0.3.0

func (fng *FakeNumberGenerator) RandomLocalNumberUSUniqueAreaCodeSet(set map[uint64]int8, acs []uint16) (uint64, map[uint64]int8, error)

RandomLocalNumberUSUnique returns a US E.164 number AreaCode + Prefix + Line Number

type Lookup added in v0.2.0

type Lookup struct {
	CarrierNumberInfo CarrierNumberInfo      `json:"carrierNumberInfo"`
	LookupSource      string                 `json:"lookupSource"`
	LookupTime        time.Time              `json:"lookupTime"`
	LookupResponse    map[string]interface{} `json:"lookupResponse"`
}

type LookupSet added in v0.2.0

type LookupSet struct {
	LookupMap map[string]Lookup `json:"lookupMap"`
}

func NewLookupSet added in v0.2.0

func NewLookupSet() LookupSet

func (LookupSet) Add added in v0.2.0

func (set LookupSet) Add(lookup Lookup)

func (LookupSet) Latest added in v0.2.0

func (set LookupSet) Latest(source string) (Lookup, error)

func (LookupSet) Validate added in v0.2.0

func (set LookupSet) Validate()

type MapStringString added in v0.2.0

type MapStringString map[string]string

type Number added in v0.2.0

type Number struct {
	E164Number        string            `json:"e164Number"`
	CountryCode       string            `json:"countryCode"`
	CarrierNumberInfo CarrierNumberInfo `json:"carrier"`
	Lookups           LookupSet         `json:"lookups"`
}

func NewNumber added in v0.2.0

func NewNumber() Number

func (*Number) NANPComponents added in v0.2.0

func (num *Number) NANPComponents() (Components, error)

func (*Number) RemoveLookups added in v0.3.0

func (num *Number) RemoveLookups()

func (*Number) SetLatest added in v0.2.0

func (num *Number) SetLatest(source string) error

type NumberSet added in v0.2.0

type NumberSet struct {
	Numbers map[string]Number `json:"numbers"`
}

func NewNumberSet added in v0.2.0

func NewNumberSet() NumberSet

func (*NumberSet) Add added in v0.2.0

func (set *NumberSet) Add(num Number) error

func (*NumberSet) HistogramCarrierName added in v0.3.0

func (set *NumberSet) HistogramCarrierName() map[string]int

func (*NumberSet) MapNumberCarrierName added in v0.2.0

func (set *NumberSet) MapNumberCarrierName() map[string]string

func (*NumberSet) MapNumberLineType added in v0.2.0

func (set *NumberSet) MapNumberLineType() map[string]string

func (*NumberSet) RemoveLookups added in v0.3.0

func (set *NumberSet) RemoveLookups()

func (*NumberSet) Validate added in v0.3.0

func (set *NumberSet) Validate() error

func (*NumberSet) WriteFileJSON added in v0.2.0

func (set *NumberSet) WriteFileJSON(filename, prefix, indent string, perm fs.FileMode) error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL