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