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