blib/lib/Voicent.pm

filter: Statementstmt 29.6% 27 / 91 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 6 / 12 Podpod 100% 5 / 5 totaltotal 31.6% 38 / 120 CC 7 SCAR 20.5
CC
7
Cov
26%
call_status
20.0
_call_now
12.0
call_remove
6.0
CRAP 7.8
↑ Summary
1 package Voicent;
2
3 1 ▶use 5.008006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use HTTP::Request::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
9
10 1 require Exporter;
11 1 ▶use AutoLoader qw(AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
12
13 1 our @ISA = qw(Exporter);
14
15 1 our @EXPORT = qw(
16 host
17 port
18 call_text
19 call_audio
20 call_status
21 call_remove
22 call_till_confirm
23 );
24
25 1 our %EXPORT_TAGS = ( 'all' => [ @EXPORT ] );
26
27 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
28
29 1 our $VERSION = '1.1';
30
31 # change to the host name for your installation
32 1 $Voicent::host = "localhost";
33 1 $Voicent::port = 8155;
34
35 0 ▶sub _call_now {
Subroutine _call_now: not called CC=3 SCAR=24.8
36 0 my %params = %{$_[0]};
37
38 0 my $ua = LWP::UserAgent->new(agent => 'Mozilla/4.0');
39
40 0 my $url = 'http://' . $Voicent::host . ':' . $Voicent::port . '/ocall/callreqHandler.jsp';
41 0 my $resp = $ua->request(POST $url,
42 Content_Type => 'application/x-www-form-urlencoded',
43 Content => [ %params ]
44 );
45
46 0 ▶ unless ($resp->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($resp->is_success) 0 0 0
47 0 print "Error sending call request to Voicent Gateway";
48 0 return "";
49 }
50
51 0 my $result = $resp->content();
52 0 my $pos = index ($result, '[ReqId=');
53 0 ▶ unless ($pos >=0) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pos >= 0) 0 0 0
54 0 print "Error getting call request id from Voicent Gateway";
55 0 return "";
56 }
57 0 $pos = $pos + 7;
58 0 my $pos2 = index ($result, ']', $pos);
59 0 my $reqId = substr($result, $pos, $pos2 - $pos);
60
61 0 return $reqId;
62 }
63
64 0 ▶sub call_text {
Subroutine call_text: not called CC=1 SCAR=6.9
Pod documented
65 0 my ($phoneno, $textmsg, $selfdelete) = @_;
66
67 0 my %params = ();
68 0 $params{'info'} = 'call ' . $phoneno;
69 0 $params{'phoneno'} = $phoneno;
70 0 $params{'firstocc'} = '10';
71 0 $params{'txt'} = $textmsg;
72 0 $params{'selfdelete'} = $selfdelete;
73
74 0 return _call_now(\%params);
75 }
76
77 0 ▶sub call_audio {
Subroutine call_audio: not called CC=1 SCAR=6.9
Pod documented
78 0 my ($phoneno, $audiofile, $selfdelete) = @_;
79
80 0 my %params = ();
81 0 $params{'info'} = 'call ' . $phoneno;
82 0 $params{'phoneno'} = $phoneno;
83 0 $params{'firstocc'} = '10';
84 0 $params{'audiofile'} = $audiofile;
85 0 $params{'selfdelete'} = $selfdelete;
86
87 0 return _call_now(\%params);
88 }
89
90 0 ▶sub call_status {
Subroutine call_status: not called CC=4 SCAR=30.0
Pod documented
91 0 my ($reqId) = @_;
92
93 0 my $url = 'http://' . $Voicent::host . ':' . $Voicent::port . '/ocall/callstatusHandler.jsp';
94 0 $url = $url . '?reqid=' . $reqId;
95
96 0 my $ua = LWP::UserAgent->new(agent => 'Mozilla/4.0');
97
98 0 my $resp = $ua->request(GET $url);
99
100 0 ▶ unless ($resp->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($resp->is_success) 0 0 0
101 0 print "Error sending call request to Voicent Gateway";
102 0 return "";
103 }
104
105 0 my $result = $resp->content();
106
107 0 ▶ if ($result =~ m#\Q^made^\E#) { return "Call Made"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($result =~ /\^made\^/) 0 0 0
108 0 ▶ if ($result =~ m#\Q^failed^\E#) { return "Call Failed"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($result =~ /\^failed\^/) 0 0 0
109 0 print "";
110 }
111
112 0 ▶sub call_remove {
Subroutine call_remove: not called CC=2 SCAR=17.9
Pod documented
113 0 my ($reqId) = @_;
114
115 0 my $url = 'http://' . $Voicent::host . ':' . $Voicent::port . '/ocall/callremoveHandler.jsp';
116 0 $url = $url . '?reqid=' . $reqId;
117
118 0 my $ua = LWP::UserAgent->new(agent => 'Mozilla/4.0');
119
120 0 my $resp = $ua->request(GET $url);
121
122 0 ▶ unless ($resp->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($resp->is_success) 0 0 0
123 0 print "Error sending call request to Voicent Gateway";
124 0 return "";
125 }
126 }
127
128 # voc file must reside on the same machine as the gateway
129 # this function can be achieved using command line interface
130 # vcast.exe -startnow -confirmcode [code] -wavfile [wavfile]
131
132 0 ▶sub call_till_confirm {
Subroutine call_till_confirm: not called CC=1 SCAR=6.9
Pod documented
133 0 my ($vcast, $vocfile, $confirmcode, $wavfile) = @_;
134
135 0 my %params = ();
136 0 $params{'info'} = 'call till concel';
137 0 $params{'phoneno'} = '0000000';
138 0 $params{'firstocc'} = '10';
139 0 $params{'startexec'} = $vcast;
140 0 $params{'selfdelete'} = '1';
141 0 $params{'cmdline'} = '"' . $vocfile . '" -startnow -confirmcode ' . $confirmcode
142 . ' -wavfile "' . $wavfile . '"';
143
144 0 return _call_now(\%params);
145 }
146
147 # samples
148 # $reqId = call_text(1234567, 'hello, how are you', 0);
149 # $reqId = call_audio(1234567, 'C:\temp\welcome.wav', 0);
150 # $status = call_status($reqId);
151 # call_remove($reqId);
152 # call_till_confirm('c:\Program Files\Voicent\BroadcastByPhone\bin\vcast.exe', 'c:\temp\tt1.voc', '1234', 'c:\temp\welcome.wav');
153
154
155 1 1;
156 __END__
↑ Summary