1 package Net::Indosoft::QSuite;
5 use vars qw( $AUTOLOAD );
7 use Net::HTTPS::Any qw( https_post );
11 Net::Indosoft::QSuite - Interface to Indosoft Q-Suite API
19 our $VERSION = '0.01';
24 use Net::Indosoft::QSuite;
26 my $qsuite = Net::Indosoft::QSuite->new(
27 host => 'server.example.com',
28 gateway_key => '09ad8f6b692717316913809f9903fd08',
36 my $uuid = $qsuite->editTenant(
40 hostname => 'one.tenant.com',
41 callerid_name => 'Tenant One',
42 callerid_number => '5551112222',
44 or die "can't create tenant: ". $qsuite->errstr;
46 my $uuid = $qsuite->editTenant(
48 uuid => 'Tenant UUID',
49 name => 'Tenant Name',
50 shortname => 'Tenant shortname',
51 hostname => 'Tenant hostname',
52 callerid_name => 'Nailup caller ID name',
53 callerid_number => 'Nailup caller ID number',
55 or die "can't edit tenant: ". $qsuite->errstr;
59 uuid => 'Tenant UUID',
61 or die "can't delete tenant: ". $qsuite->errstr;
65 # Manage Trunk Assignments
68 my $uuid = $qsuite->assignTrunkToTenant(
70 tenant_uuid => 'f269fa3480e739d77e4fee61f94575e2',
71 trunk_id => '1', #provided by indosoft
73 or die "can't assign trunk to tenant ". $qsuite->errstr;
75 my $uuid = $qsuite->assignTrunkToTenant(
77 tenant_uuid => 'Tenant UUID',
78 trunk_id => 'trunk ID, #provided by indosoft
80 or die "can't trunk from tenant: ". $qsuite->errstr;
87 my $number = $qsuite->editDID(
89 tenant_uuid => 'f269fa3480e739d77e4fee61f94575e2',
90 number => '4445550011',
91 auto_attendant_uuid => 'c4367c52bf45525bfbb7614b167a5335',
93 or die "can't create DID: ". $qsuite->errstr;
96 my $number = $qsuite->editDID(
98 tenant_uuid => 'Tenant UUID',
99 number => 'The DID number',
100 auto_attendant_uuid => 'UUID of the assigned auto attendant',
102 or die "can't edit DID: ". $qsuite->errstr;
104 my $number = $qsuite->editDID(
106 tenant_uuid => 'Tenant UUID',
108 or die "can't delete DID: ". $qsuite->errstr;
112 # Manage Auto Attendant
115 my $uuid = $qsuite->editAutoAttendant(
117 tenant_uuid => 'f269fa3480e739d77e4fee61f94575e2',
118 name => 'Auto F. Atttendant',
120 response_limit => 32,
121 allow_extension-dialing => 0, # 0 or 1
123 or die "can't create auto attendant: ". $qsuite->errstr;
125 my $uuid = $qsuite->editAutoAttendant(
127 tenant_uuid => 'Tenant UUID',
128 uuid => 'UUID of the assigned auto attendant',
129 name => 'Auto Attenant name',
130 repeat_limit => 54, # The number of time to attempt to gather input
131 response_limit => 32, # The timeout on the response
132 allow_extension-dialing => 0, # "Allow the caller to dial extensions with the menu
134 or die "can't edit auto attendant: ". $qsuite->errstr;
136 my $uuid = $qsuite->editAutoAttendant(
138 tenant_uuid => 'Tenant UUID',
139 uuid => 'UUID of the assigned auto attendant',
141 or die "can't delete auto attendant: ". $qsuite->errstr;
148 my $uuid = $qsuite->editRingGroup(
150 tenant_uuid => 'f269fa3480e739d77e4fee61f94575e2',
151 #docs say uuid ('ring group uuid') for create, but prob. wrong
152 name => 'Ring Group',
154 extension_uuids => '432789473febdf00fe1ee77777777777,ab98342efabc43',
156 or die "can't create ring group: ". $qsuite->errstr;
158 my $uuid = $qsuite->editRingGroup(
160 tenant_uuid => 'Tenant UUID',
161 uuid => 'Ring group UUID',
162 name => 'Ring group name',
163 timeout => 54, # Ring group timeout
164 extension_uuids => '1234abc,999fefefefe', # Comma-separated list of extension UUIDs that make up the ring group
166 or die "can't edit ring group: ". $qsuite->errstr;
168 my $uuid = $qsuite->editRingGroup(
170 tenant_uuid => 'Tenant UUID',
171 uuid => 'Ring group UUID',
173 or die "can't delete ring group: ". $qsuite->errstr;
177 # Manage Employee/User
180 my $uuid = $qsuite->editEmployee(
182 tenant_uuid => 'f269fa3480e739d77e4fee61f94575e2',
183 #docs say uuid ('employee uuid') for create, but prob. wrong
185 password => 'beast1',
189 or die "can't create employee: ". $qsuite->errstr;
191 my $uuid = $qsuite->editEmployee(
193 tenant_uuid => 'Tenant UUID',
194 uuid => 'Employee UUID',
196 password => 'beast1',
200 or die "can't edit employee: ". $qsuite->errstr;
202 my $uuid = $qsuite->editEmployee(
204 tenant_uuid => 'Tenant UUID',
205 uuid => 'Employee UUID',
207 or die "can't delete employee: ". $qsuite->errstr;
214 #or does this return an "extension uuid"? its wanted for devices...
215 my $number = $qsuite->editExtension(
217 tenant_uuid => 'f269fa3480e739d77e4fee61f94575e2',
220 or die "can't create extension: ". $qsuite->errstr;
222 #this is documented but seems to make no sense
223 #my $number = $qsuite->editExtension(
225 # tenant_uuid => 'Tenant UUID',
228 # or die "can't edit extension: ". $qsuite->errstr;
230 #or does this want an "extension uuid"?
231 my $number = $qsuite->editExtension(
233 tenant_uuid => 'Tenant UUID',
236 or die "can't delete extension: ". $qsuite->errstr;
243 my $uuid = $qsuite->editDevice(
245 tenant_uuid => 'f269fa3480e739d77e4fee61f94575e2',
246 employee_uuid => 'f269fa3480e739d77e4fee61f94575e2',
247 extension_uuid => 'f269fa3480e739d77e4fee61f94575e2',
248 #docs say "device uuid" for create, but i doubt it
249 protocol => 'sip', #sip iax or dahdi
251 or die "can't create device: ". $qsuite->errstr;
253 my $uuid = $qsuite->editDevice(
255 tenant_uuid => 'Tenant UUID',
256 employee_uuid => 'Employee UUID',
257 extension_uuid => 'Extension UUID',
258 uuid => 'Device UUID',
259 protocol => 'sip', #sip iax or dahdi
261 or die "can't edit device: ". $qsuite->errstr;
263 #docs for required fields here appear to be on crack (tenant_uuid only?),
265 my $uuid = $qsuite->editDevice(
267 #perhaps? tenant_uuid => 'Tenant UUID',
268 #perhaps? employee_uuid => 'Employee UUID',
269 #perhaps? extension_uuid => 'Extension UUID',
270 uuid => 'Device UUID',
272 or die "can't delete device: ". $qsuite->errstr;
276 # Manage Voicemail Settings
279 my $uuid = $qsuite->editVoicemailSettings(
280 extension_uuid => 'f269fa3480e739d77e4fee61f94575e2',
283 or die "can't edit voicemail: ". $qsuite->errstr;
287 # Manage Extension Forwarding Settings
290 my $uuid = $qsuite->editForwardingSettings(
291 #perhaps? docs say yes, exampe no tenant_uuid => 'f269fa3480e739d77e4fee61f94575e2',
292 extension_uuid => 'f269fa3480e739d77e4fee61f94575e2',
293 number => '555-888-2222',
295 or die "can't edit forwarding: ". $qsuite->errstr;
302 Creates a new Net::Indosoft:QSuite object. Options may be passed
303 as a hash reference or a flat list of names and values.
307 =item host (required)
309 =item gateway_key - A valid API gateway key (required)
311 =item debug (optional)
319 my $class = ref($proto) || $proto;
320 my $self = ref($_[0]) ? shift : { @_ };
321 $self->{'debug'} ||= 0;
322 bless($self, $class);
332 # unless ref($class) && $class->isa('Net::VoIP_Innovations');
334 my $self = shift; #$class;
340 =head2 assignTrunkToTenant
344 =head2 editAutoAttendant
349 # 'Tenant' => 'uuid',
351 # 'AutoAttendant' => 'uuid',
352 # 'RingGroup' => 'uuid', #? its undocumented
353 # 'Employee' => 'uuid',
354 # 'Extension' => 'number',
355 # 'Device' => 'uuid',
356 # 'VoicemailSettings' => 'uuid',
357 # 'ForwardingSettings' => 'uuid',
362 my $opts = ref($_[0]) ? shift : { @_ };
364 $AUTOLOAD =~ /(^|::)(\w+)$/ or die "unparsable AUTOLOAD: $AUTOLOAD";
366 my $path = "/cti/api/external/$func.json";
368 my ( $page, $https_response, %reply_headers ) =
369 https_post({ host => $self->{host},
374 unless ( $https_response =~ /^200/i ) {
375 #this is a lower-layer communication error, so it warrants an exception
376 die "Error POSTing to https://". $self->{host}. "$path : $https_response\n";
377 #$self->{'errstr'} = $https_response;
381 my $response = decode_json( $page );
384 #warn Dumper($response); #if $self->{debug};
386 unless ( $response->{success} ) { # == 1
387 $self->{errstr} = $response->{error};
391 $self->{errstr} = '';
393 # use %return if it gets more complicated
394 if ( $func =~ /(DID|Extension)$/ ) {
395 return $response->{data}{number};
397 return $response->{data}{uuid};
404 Ivan Kohler, C<< <ivan-indosoft at freeside.biz> >>
408 Please report any bugs or feature requests to C<bug-net-indosoft-qsuite at rt.cpan.org>, or through
409 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Indosoft-QSuite>. I will be notified, and then you'll
410 automatically be notified of progress on your bug as I make changes.
414 You can find documentation for this module with the perldoc command.
416 perldoc Net::Indosoft::QSuite
419 You can also look for information at:
423 =item * RT: CPAN's request tracker (report bugs here)
425 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Indosoft-QSuite>
427 =item * AnnoCPAN: Annotated CPAN documentation
429 L<http://annocpan.org/dist/Net-Indosoft-QSuite>
433 L<http://cpanratings.perl.org/d/Net-Indosoft-QSuite>
437 L<http://search.cpan.org/dist/Net-Indosoft-QSuite/>
442 =head1 ACKNOWLEDGEMENTS
445 =head1 LICENSE AND COPYRIGHT
447 Copyright (C) 2014 Freeside Internet Services, Inc. (http://freeside.biz/)
449 This program is free software; you can redistribute it and/or modify it
450 under the same terms as Perl itself.
454 Need a complete, open-source back-office and customer self-service solution?
455 The Freeside software includes support for Indosoft integration, CDR
456 rating, invoicing, credit card and electronic check processing, integrated
457 trouble ticketing, and customer signup and self-service web interfaces.
459 http://freeside.biz/freeside/