31 Dec 2018 16:59:16 UTC
- Distribution: Magrathea-API
- Source (raw)
- Browse (raw)
- How to Contribute
- KwaliteeBus factor: 0
- 25.53% Coverage
- License: unknown
- Perl: v5.10.0
- Activity24 month
- Download (18.14KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionCMS Cliff Stanford
- MAIN API METHODS
- Allocation Methods
- Block Methods
- Service Methods
- Emergency Methods
- Low Level Methods
- COPYRIGHT AND LICENCE
Magrathea::API - Easier access to the Magrathea NTS API
use Magrathea::API; my $mt = new Magrathea::API; my $number = $mt->allocate('01792'); $mt->deactivate($number); my @list = $mt->list('01792'); my @numbers = $mt->block_allocate('01792', 10); $mt->fax2email($numbers, 'firstname.lastname@example.org'); $mt->divert($number, '+5716027171'); $emerg = $mt->emergency_info;
This module implements most of the Magrathea NTS API in a simple format.
This will create a new Magrathea object and open at telnet session to the server. If authorisation fails, it will croak.
my $mt = new Magrathea::API( username => 'myuser', password => 'mypass', );
The username and password allocated by Magrathea.
Defaults to api.magrathea-telecom.co.uk but could be overridden.
Defaults to 777.
In seconds. Defaults to 10.
If set to a true value, this will output the conversation between the API and Magrathea's server. Be careful as this will also echo the username and password.
In all cases where
$numberis passed, this may be a string containing a number in National format (020 1234 5678) or in International format (+44 20 1234 5678). Spaces are ignored. Also, Phone::Number objects may be passed.
When a number is returned, it will always be in the for of a Phone::Number object.
Passed a prefix, this will allocate and activate a number. You do not need to add the
_characters. If a number can be found, this routine will return a Phone::Number object. If no match is found, this routine will return
undef. It will croak on any other error from Magrathea.
Passed a number as a string or a Phone::Number, this will activate that number.
Passed a number as a string or a Phone::Number, this deactivates the number.
Reactivates a number that has previously been deactivated.
This should be passed a prefix and possibly a quantity (defaulting to 10. It will return a sorted random list of available numbers matching the prefix. These are returned as an array (or an arrayref) of Phone::Number. None of the numbers is allocated by this method.
If none are available, the method will return an empty array.
This should be passed a prefix (without any
_characters) and an optional block size (defaulting to 10). It will attempt to allocate and activate a block of numbers.
If a block can be found, this routine should return an array or arrayref of Phone::Number objects. Under odd circumstances, it is possible that fewer than the requested quantity of numbers will be returned;
If no range is found is found, this routine will return
undefin scalar context or an empty array in list context. It will croak on any other error from Magrathea.
This should be passed a number (string or Phone::Number) to check whether that number is part of a block.
If it is, the size of the block will be returned in scalar context; In list context, the response will be an array of all the numbers in that block.
If it is not a block, this will return
undefor an empty array.
This should be passed the first number in a block. It will deactivate and return the block of numbers.
This should be passed the first number in a block. It will reactivate the block and return the size of the block in scalar context or an array of the numbers in list context.
If the block is not available, this method will croak.
In testing, this method has never worked correctly.
Sets a number as a fax to email.
Sets a number as a voice to email.
$mt->sip($number, $host, [$username, [$inband]]);
Passed a number and a host, will set an inbound sip link to the international number (minus leading +) @ the host. If username is defined, it will be used instead of the number. If inband is true, it will force inband DTMF. The default is RFC2833 DTMF.
Returns the status for a given number.
my $status = $mt->status($number); my @status = $mt->status($number);
In scalar context, returns the first (and usually only) status as a Magrathea::API::Status object. In list context, returns up to three statuses representing the three possible setups created with ORDE.
If the number is not allocated to us and activated, this routine returns
undefin scalar context and an empty list in list context.
The Magrathea::API::Status object has the following calls:
A Phone::Number object representing the number to which this status refers.
The date this number expires in the form
One of sip, fax2email, voice2email, divert or unallocated.
The target email or phone number for this number;
The entry number (1, 2 or 3) for this status;
In addition, it overloads '""' to provide as tring comprising the type and the target, separated by a space.
Passed a phone number, this method returns a Magrathea::API::Emergency object with the current 999 information.
Optionally it can be passed a second parameter which, if it is a truthy value, will set the
All the Magrathea low level calls are available. These are simply passed an array of strings which are joined to create the command string. They return the raw response on success (minus the leading 0) and die on failure.
$@will contain the error.
See the Magrathea documentation.
The functions are:
This is called by "new" and should not be called directly.
This is called automatically upon the Magrathea::API object going out of scope and should not be called directly.
$mt->set('02012345678 1 441189999999'); $mt->set('02012345678 1 F:email@example.com'); $mt->set('02012345678 1 V:firstname.lastname@example.org'); $mt->set('02012345678 1 S:email@example.com'); $mt->set('02012345678 1 I:username:firstname.lastname@example.org');
$mt->feat('02012345678 D'); $mt->feat('02012345678 J');
$mt->orde('02012345678 1 0000');
$mt->info('02012345678 GEN Magrathea, 14 Shute End, RG40 1BJ');
It will not usually be necessary to call these functions directly.
Cliff Stanford, <email@example.com>
Please open any issues with this code on the Github Issues Page.
Copyright (C) 2012 - 2018 by Cliff Stanford
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available.
Module Install Instructions
To install Magrathea::API, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Magrathea::API
For more information on module installation, please visit the detailed CPAN module installation guide.