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