desc
[Net-VoIP_Innovations.git] / lib / Net / VoIP_Innovations.pm
1 package Net::VoIP_Innovations;
2
3 use warnings;
4 use strict;
5 use Data::Dumper;
6 use SOAP::Lite;
7 #SOAP::Lite->import(+trace=>'debug');
8
9 =head1 NAME
10
11 Net::VoIP_Innovations - Interface to VoIP Innovations API
12
13 =cut
14
15 our $VERSION = '3.00_01';
16 our $URI     = 'http://dev.voipinnovations.com/VOIP/Services/APIService.asmx';
17 our $NS      = 'http://tempuri.org'; #nice one
18
19 our $AUTOLOAD;
20 our $errstr = '';
21
22 =head1 SYNOPSIS
23
24     use Net::VoIP_Innovations 3;
25
26     my $voip_innovations = Net::VoIP_Innovations->new(
27         'login'    => 'tofu',
28         'password' => 'beast', #secret
29     );
30
31
32     ##
33     # DID functions
34     ##
35
36     #auditDIDs
37     #queryDID
38     #reserveDID
39     #assignDID
40     #configDID
41     #releaseDID
42
43
44     ###
45     # 911 Functions
46     ###
47
48     #insert911
49     my $response = $voip_innovations->insert911(
50       'did'        => '4155551212',
51       'address1'   => '1234 Test Lane',
52       'address2'   => '',
53       'city'       => 'Testington',
54       'state'      => 'CA',
55       'zip'        => '95454',
56       'plusFour'   => '',
57       'callerName' => 'Joe Caller',
58     );
59     if ( $response->{'responseCode'} != 100 ) {
60       die $response->{'responseMessage'};
61     }
62
63     #update911
64     my $response = $voip_innovations->update911(
65       'did'        => '4155551212',
66       'address1'   => '1234 Test Lane',
67       'address2'   => '',
68       'city'       => 'Testington',
69       'state'      => 'CA',
70       'zip'        => '95454',
71       'plusFour'   => '',
72       'callerName' => 'Joe Caller',
73     );
74     if ( $response->{'responseCode'} != 100 ) {
75       die $response->{'responseMessage'};
76     }
77
78     #remove911
79     my $response = $voip_innovations->remove911(
80       'did'        => '4155551212',
81     );
82     if ( $response->{'responseCode'} != 100 ) {
83       die $response->{'responseMessage'};
84     }
85
86
87     ###
88     # Locator Functions
89     ###
90
91     ...
92
93 =head1 METHODS
94
95 =head2 new HASHREF | OPTION, VALUE ...
96
97 Creates a new Net::VoIP_Innovations object.  Options may be passed
98 as a hash reference or a flat list of names and values.
99
100 =over 4
101
102 =item login (required)
103
104 =item password (secret) (required)
105
106 =back
107
108 =cut
109
110 #  If there is an error,
111 #returns false and sets an error string which may be queried with the I<errstr>
112 #class method.
113
114 sub new {
115   my $proto = shift;
116   my $class = ref($proto) || $proto;
117   my $self = ref($_[0]) ? shift : { @_ };
118   bless($self, $class);
119 }
120
121 =head2 errstr
122
123 =cut
124
125 sub errstr {
126   my $class = shift;
127
128   return $errstr
129     unless ref($class) && $class->isa('Net::VoIP_Innovations');
130
131   my $self = $class;
132   $self->{errstr};
133 }
134
135 sub DESTROY { }; # no-op
136
137 sub AUTOLOAD {
138   my $self = shift;
139   my $opts = ref($_[0]) ? shift : { @_ };
140
141   $AUTOLOAD =~ /(^|::)(\w+)$/ or die "unparsable AUTOLOAD: $AUTOLOAD";
142   my $function = $2;
143
144   $opts->{'login'}  ||= $self->{'login'};
145   $opts->{'secret'} ||= $self->{'password'};
146   my @soap_opts = map { SOAP::Data->name($_)->value( $opts->{$_} ) }
147                     keys %$opts;
148
149   SOAP::Lite
150     ->proxy($URI)
151     #->uri($NS)
152     ->default_ns($NS)
153     ->on_action( sub { join '/', @_ } )
154     ->$function( @soap_opts )
155     ->result();
156
157 }
158
159 =head1 AUTHOR
160
161 Ivan Kohler, C<< <ivan-net-voipinnovations at freeside.biz> >>
162
163 =head1 BUGS
164
165 Please report any bugs or feature requests to C<bug-net-voip_innovations at rt.cpan.org>, or through
166 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-VoIP_Innovations>.  I will be notified, and then you'll
167 automatically be notified of progress on your bug as I make changes.
168
169
170 =head1 SUPPORT
171
172 You can find documentation for this module with the perldoc command.
173
174     perldoc Net::VoIP_Innovations
175
176
177 You can also look for information at:
178
179 =over 4
180
181 =item * RT: CPAN's request tracker
182
183 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-VoIP_Innovations>
184
185 =item * AnnoCPAN: Annotated CPAN documentation
186
187 L<http://annocpan.org/dist/Net-VoIP_Innovations>
188
189 =item * CPAN Ratings
190
191 L<http://cpanratings.perl.org/d/Net-VoIP_Innovations>
192
193 =item * Search CPAN
194
195 L<http://search.cpan.org/dist/Net-VoIP_Innovations>
196
197 =back
198
199
200 =head1 COPYRIGHT & LICENSE
201
202 Copyright 2008-2014 Freeside Internet Services, Inc. (http://freeside.biz/)
203
204 This program is free software; you can redistribute it and/or modify it
205 under the same terms as Perl itself.
206
207
208 =head1 ADVERTISEMENT
209
210 Need a complete, open-source back-office and customer self-service solution?
211 The Freeside software includes support for VoIP Innovations integration, CDR
212 rating, invoicing, credit card and electronic check processing, integrated
213 trouble ticketing, and customer signup and self-service web interfaces.
214
215 L<http://freeside.biz/freeside/>
216
217 =cut
218
219 1;