4409b5bd9604bdf4110049ec90b6609fad664c0b
[Net-Vitelity.git] / lib / Net / Vitelity.pm
1 package Net::Vitelity;
2
3 use warnings;
4 use strict;
5 use LWP::UserAgent;
6
7 =head1 NAME
8
9 Net::Vitelity - Interface to Vitelity API
10
11 =cut
12
13 our $VERSION = '0.04';
14
15 our $AUTOLOAD;
16
17 =head1 SYNOPSIS
18
19     use Net::Vitelity;
20
21     my $vitelity = Net::Vitelity->new(
22                                        'login'   => $your_login,
23                                        'pass'    => $your_pass,
24                                        'apitype' => 'api', #api, fax or lnp
25                                      );
26
27 =head1 METHODS
28
29 =cut
30
31 =head2 new
32
33 Create a new Net::Vitelity object.  login and pass are required.
34
35 =cut
36
37 sub new {
38     my ($class,%data) = @_;
39     die "missing user and/or password" unless defined $data{'login'} && defined $data{'pass'};
40     my $self = { 'login' => $data{'login'}, 'pass' => $data{'pass'} };
41     $self->{apitype} = $data{'apitype'} ? $data{'apitype'} : 'api';
42     bless $self, $class;
43     return $self;
44 }
45
46 sub AUTOLOAD {
47   my $self = shift;
48
49   $AUTOLOAD =~ /(^|::)(\w+)$/ or die "unparsable AUTOLOAD: $AUTOLOAD";
50   my $cmd = $2;
51   return if $cmd eq 'DESTROY';
52
53   my $ua = LWP::UserAgent->new;
54
55   #XXX md5 encrypt pass
56
57   my $URL_API = 'http://api.vitelity.net/api.php';
58   my $URL_FAX = 'http://api.vitelity.net/fax.php';
59   my $URL_LNP = 'http://api.vitelity.net/lnp.php';
60
61   my $url = $URL_API;
62   $url = $URL_FAX if $self->{apitype} eq 'fax';
63   $url = $URL_LNP if $self->{apitype} eq 'lnp';
64
65   my $response = $ua->post($url, {
66                     login => $self->{login}, 
67                     pass  => $self->{pass},
68                     cmd   => $cmd,
69                     @_,
70                   }
71            );
72
73   die $response->status_line unless $response->is_success;
74
75   my $content = $response->decoded_content;
76
77   $content =~ /x\[\[(.*)\[\[x/s;
78   $content = $1;
79
80   wantarray ? split("\n", $content) : $content;
81
82 }
83
84 =head2 listtollfree
85
86 List ALL available toll free numbers
87
88 Possible Results: none OR [list of tf numbers]
89
90 =head2 callfromclick
91
92 Sends someone a phone call that then connects them to customer service/another number.
93
94 Options: number=number AND servicenumber=number
95
96 Possible Results:OK or INVALID
97
98 =head2 listlocal
99
100 Lists ALL available local numbers in a specific state and ratecenter
101
102 Requires: state=STATE
103
104 Options: type=unlimited OR type=pri OR withrates=yes
105                ratecenter=RATECENTER
106
107 Possible Results: unavailable or missing or [list of dids]
108
109 =head2 gettollfree
110
111 Orders a specific toll free number in our available list (SLOW)
112 Requires: did=TOLL-FREE-NUMBER
113 Options: routesip=route_to_this_subaccount
114 Possible Results: success or unavailable or missingdid
115
116 =head2 getlocaldid
117
118 Orders a specific local number from our available list
119
120 Requires: did=AVAILABLE-LOCAL-NUMBER
121
122 Options: type=perminute OR type=unlimited OR type=your-pri OR
123                routesip=route_to_this_subaccount
124
125 Possible Results: invalid or success or missingdid
126
127 =head2 removedid
128
129 Remove Local or Toll Free DID from account
130
131 Requires: did=AVAILABLE-LOCAL-NUMBER
132
133 Possible Results: success OR unavailable OR missingdid
134
135 =head2 listratecenters
136
137 Lists all of the available rate centers for a specific state line by line
138
139 Requires: state=STATE (ie, state=CO)
140
141 Options: type=perminute OR type=unlimited OR type=pri
142
143 Possible Results: unavailable OR missingdata OR [list of ratecenters]
144
145 =head2 listavailratecenters
146
147 Lists all available rate centers DIDs are currently in stock for a specific state line by line
148
149 Requires: state=STATE (ie, state=CO)
150
151 Options: type=unlimited OR type=pri
152
153 Possible Results: missingdata OR unavailable or [list of ratecenters]
154
155 =head2 requestvanity
156
157 Orders a specific available toll free number from the SMS database.
158
159 Requires: did=8009879891 (number can be any available number)
160
161 Possible Results: missingdata OR exists OR success
162
163 =head2 searchtoll
164
165 Searches the SMS/800 database for an available number matching the specific data you provide
166
167 Requires: did=8**333****
168
169 Possible Results: none OR missingdata OR [list of avail numbers]
170
171 =head2 listavailstates
172
173 Lists all states that have DIDs which are currently in stock
174
175 Options: type=perminute OR type=unlimited OR type=pri
176
177 Possible Results: unavailable OR [list of states]
178
179 =head2 liststates
180
181 Lists all available DID states line by line
182
183 Options: type=perminute OR type=unlimited OR type=pri
184
185 Possible Results: unavailable OR [list of states]
186
187 =head2 cnam
188
189 Lookup a specific caller id number for the name
190
191 Requires: did=3037855015 (number)
192
193 Possible Results: missingdata OR [cnam value]
194
195 =head2 searchtoll
196
197 Searches the SMS/800 database for an available number matching the specific data you provide
198
199 Requires: did=8**333****
200
201 Possible Results: none OR missingdata OR [list of avail numbers]
202
203 =head2 localbackorder
204
205 Orders a specific local number from our available list
206
207 Requires: ratecenter=RATECENTER and state=STATE
208
209 Options: type=perminute OR type=unlimited
210
211 Possible Results: invalid OR ok OR missing
212
213 =head2 reroute
214
215 Changes the sub account a DID rings to.
216
217 Requires: did=DID_NUMBER & routesip=SIP_SUB_ACCOUNT
218
219 Possible Results: missingdata OR ok OR invalid
220
221 =head2 balance
222
223 Reports back your current account balance
224
225 =head2 listdids
226
227 Lists all current Local and Toll free DIDs
228
229 Options: extra=yes
230
231 Results: number,ratecenter,price_per_minute,subaccount
232
233 extra=yes adds STATE,MONTHLY_DID_RATE
234
235 =head2 routeall
236
237 Changes the routing on all dids to a specific sip account
238
239 Requires: routesip=sub_account OR routesip=login (routes to main)
240
241 Possible Results: ok OR invalid
242
243 =head2 getrate
244
245 Gets a rate on a specific domestic or International call
246
247 Requires: number=[countrycode_thenumber] ex: 01144.. or 1303..
248
249 Results: invalid OR the_rate_per_minute
250
251 =head2 subaccounts
252
253 Lists sub accounts
254
255 Requires: do=list
256
257 Possible Results: subaccount list separated by return OR invalid
258
259 =head1 All Possible Result Return Codes
260
261 =over 4
262
263 =item success
264
265 The request you made was successful
266
267 =item missingdata
268
269 You are missing login= or pass= or cmd= or other in your URL string
270
271 =item invalidauth
272
273 You have submitted an invalid login or password
274
275 =item missingrc
276
277 You are missing the ratecenter or state for a specific local did order
278
279 =item unavailable
280
281 The number you requested is not available
282
283 =item none
284
285 There are no numbers available
286
287 =item missingdid
288
289 you are missing &did=number
290
291 =item list of data
292
293 If you asked for a list of numbers and we had some available, they will be listed.
294
295 In a list contect, all entries will be returned in a list.  In a scalar
296 scalar context, entries will be separated by newlines.
297
298 =back
299
300 =head1 AUTHOR
301
302 Ivan Kohler, C<< <ivan-vitelity at freeside.biz> >>
303
304 =head1 BUGS
305
306 Please report any bugs or feature requests to C<bug-net-vitelity at rt.cpan.org>, or through
307 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Vitelity>.  I will be notified, and then you'll
308 automatically be notified of progress on your bug as I make changes.
309
310 =head1 SUPPORT
311
312 You can find documentation for this module with the perldoc command.
313
314     perldoc Net::Vitelity
315
316 You can also look for information at:
317
318 =over 4
319
320 =item * RT: CPAN's request tracker
321
322 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Vitelity>
323
324 =item * AnnoCPAN: Annotated CPAN documentation
325
326 L<http://annocpan.org/dist/Net-Vitelity>
327
328 =item * CPAN Ratings
329
330 L<http://cpanratings.perl.org/d/Net-Vitelity>
331
332 =item * Search CPAN
333
334 L<http://search.cpan.org/dist/Net-Vitelity>
335
336 =back
337
338 =head1 ADVERTISEMENTS
339
340 This module was developed by Freeside Internet Services, Inc.
341 Need a complete, open-source back-office and customer self-service solution?
342 The Freeside software includes Vitelity integration, CDR rating,
343 invoicing, credit card and electronic check processing, integrated trouble
344 ticketing and customer signup and self-service web interfaces.
345
346 http://freeside.biz/
347
348 =head1 COPYRIGHT & LICENSE
349
350 Copyright 2009-2017 Freeside Internet Services, Inc.
351 All rights reserved.
352
353 This program is free software; you can redistribute it and/or modify it
354 under the same terms as Perl itself.
355
356 =cut
357
358 1;
359