Number Carriers
The knm_carriers
module provides the interface to the enabled carrier modules, allowing upper-level applications a single interface to interact with carriers.
The primary API concerns searching for, acquiring, and disconnecting numbers from the underlying carrier modules, as well as standardizing the results (including errors) across all carrier modules.
Behaviour
The knm_gen_carrier
module provides an Erlang behaviour which all carrier modules must implement.
There are six callbacks:
find_numbers/3
acquire_number/1
disconnect_number/1
should_lookup_cnam/0
is_number_billable/1
is_local/0
find_numbers/3
The arguments are:
- A prefix: used to search the carrier’s stock of numbers.
- The quantity: how many numbers matching that prefix to search for
- Options list: various flags the carrier module can use to refine searching
Returns either:
{ok, Numbers}
whereNumbers
is a list ofknm_search
results{bulk, Numbers}
whereNumbers
is a list ofknm_search
results{error, Reason}
an error tuple
acquire_number/1
The argument is the #knm_number{}
record representing the number desired.
The result is the modified #knm_number{}
record.
An exception is thrown on error.
disconnect_number/1
The argument is the #knm_number{}
record representing the number to be disconnected.
The result is the modified #knm_number{}
record.
An exception is thrown on error.
should_lookup_cnam/0
Returns a boolean for whether this carrier’s numbers should be queried for CNAM.
is_number_billable/1
The argument is the #knm_phone_number{}
record.
The result is a boolean, representing whether the number should be billed.
is_local/0
Returns a boolean for whether the carrier handles numbers local to the system.
Note: a non-local (foreign) carrier module usually makes HTTP requests.