File Coverage

blib/lib/SMS/Send/Kannel/SMSbox.pm
Criterion Covered Total %
statement 9 34 26.4
branch 0 20 0.0
condition 0 3 0.0
subroutine 3 8 37.5
pod 1 1 100.0
total 13 66 19.7


line stmt bran cond sub pod time code
1             package SMS::Send::Kannel::SMSbox;
2 2     2   449479 use strict;
  2         5  
  2         92  
3 2     2   13 use warnings;
  2         12  
  2         142  
4 2     2   30 use base qw{SMS::Send::Driver::WebService};
  2         14  
  2         1623  
5              
6             our $VERSION = '0.08';
7             our $PACKAGE = __PACKAGE__;
8              
9             =head1 NAME
10              
11             SMS::Send::Kannel::SMSbox - SMS::Send driver for Kannel SMSbox Web Service
12              
13             =head1 SYNOPSIS
14              
15             Using L Driver API
16              
17             SMS-Send.ini
18             [Kannel::SMSbox]
19             host=mykannelserver
20             username=myuser
21             password=mypass
22              
23             use SMS::Send;
24             my $service = SMS::Send->new('Kannel::SMSbox');
25             my $success = $service->send_sms(
26             to => '+1-800-555-0000',
27             text => 'Hello World!',
28             );
29              
30             =head1 DESCRIPTION
31              
32             SMS::Send driver for Kannel SMSbox Web Service
33              
34             =head1 USAGE
35              
36             use SMS::Send::Kannel::SMSbox;
37             my $service = SMS::Send::Kannel::SMSbox->new(
38             username => $username,
39             password => $password,
40             host => $host,
41             );
42             my $success = $service->send_sms(
43             to => '+18005550000',
44             text => 'Hello World!',
45             );
46              
47             =head1 METHODS
48              
49             =head2 send_sms
50              
51             Sends the SMS message and returns 1 for success and 0 for failure or die on critical error.
52              
53             =cut
54              
55             sub send_sms {
56 0     0 1   my $self = shift;
57 0           my %argv = @_;
58 0 0         my $to = $argv{"to"} or die("Error: to address required");
59 0 0         print "Package: $PACKAGE, Method: send_sms, to: $to\n" if $self->debug >= 3;
60 0 0         my $text = defined($argv{"text"}) ? $argv{"text"} : '';
61 0 0         print "Package: $PACKAGE, Method: send_sms, text: $text\n" if $self->debug >= 3;
62 0           my $url = $self->url; #isa URI
63 0           my @form = (
64             username => $self->username,
65             password => $self->password,
66             to => $to,
67             text => $text,
68             );
69 0           $url->query_form(\@form);
70 0 0         print "Package: $PACKAGE, Method: send_sms, URL: $url\n" if $self->debug >= 2;
71 0           my $response = $self->ua->get($url);
72 0 0         die(sprintf("HTTP Error: %s", $response->status_line)) unless $response->is_success;
73 0 0         if ($self->debug >= 6) {
74 0           require Data::Dumper;
75 0           print Data::Dumper::Dumper($response);
76             }
77 0           my $content = $response->decoded_content;
78 0 0         print "Package: $PACKAGE, Method: send_sms, content: $content\n" if $self->debug >= 1;
79 0           $self->{"__data"} = $self->{"__content"} = $content;
80 0 0         my $status = $content =~ m/^0:/ ? 1 : 0;
81 0 0 0       warn("Package: $PACKAGE, Method: send_sms, Status: $status, Content: $content\n") if ($status != 1 and $self->warnings);
82 0           return $status;
83             }
84              
85             =head1 PROPERTIES
86              
87             =head2 username
88              
89             Sets and returns the username string value
90              
91             Override in sub class
92              
93             sub _username_default {"myusername"};
94              
95             Override in configuration
96              
97             [Kannel::SMSbox]
98             username=myusername
99              
100             =cut
101              
102             #see SMS::Send::Driver::WebService->userame
103              
104             =head2 password
105              
106             Sets and returns the password string value
107              
108             Override in sub class
109              
110             sub _password_default {"mypassword"};
111              
112             Override in configuration
113              
114             [Kannel::SMSbox]
115             password=mypassword
116              
117             =cut
118              
119             #see SMS::Send::Driver::WebService->password
120              
121             =head2 host
122              
123             Default: 127.0.0.1
124              
125             Override in sub class
126              
127             sub _host_default {"myhost.domain.tld"};
128              
129             Override in configuration
130              
131             [Kannel::SMSbox]
132             host=myhost.domain.tld
133              
134             =cut
135              
136             #see SMS::Send::Driver::WebService->host
137              
138 0     0     sub _host_default {"127.0.0.1"};
139              
140             =head2 protocol
141              
142             Default: http
143              
144             Override in sub class
145              
146             sub _protocol_default {"https"};
147              
148             Override in configuration
149              
150             [Kannel::SMSbox]
151             protocol=https
152              
153             =cut
154              
155             #see SMS::Send::Driver::WebService->protocol
156              
157 0     0     sub _protocol_default {"http"};
158              
159             =head2 port
160              
161             Default: 13013
162              
163             Override in sub class
164              
165             sub _port_default {443};
166              
167             Override in configuration
168              
169             [Kannel::SMSbox]
170             port=443
171              
172             =cut
173              
174             #see SMS::Send::Driver::WebService->port
175              
176 0     0     sub _port_default {13013};
177              
178             =head2 script_name
179              
180             Default: /cgi-bin/sendsms
181              
182             Override in sub class
183              
184             sub _script_name_default {"/path/file"};
185              
186             Override in configuration
187              
188             [Kannel::SMSbox]
189             script_name=/path/file
190              
191             =cut
192              
193             #see SMS::Send::Driver::WebService->script_name
194              
195 0     0     sub _script_name_default {'/cgi-bin/sendsms'};
196              
197             =head2 url
198              
199             Returns a L object based on above properties
200              
201             =cut
202              
203             #see SMS::Send::Driver::WebService->url
204              
205             =head2 warnings
206              
207             Default: 0
208              
209             Override in sub class
210              
211             sub _warnings_default {1};
212              
213             Override in configuration
214              
215             [Kannel::SMSbox]
216             warnings=1
217              
218             =cut
219              
220             #see SMS::Send::Driver::WebService->warnings
221              
222             =head2 debug
223              
224             Default: 0
225              
226             Override in sub class
227              
228             sub _debug_default {5};
229              
230             Override in configuration
231              
232             [Kannel::SMSbox]
233             debug=5
234              
235             =cut
236              
237             #see SMS::Send::Driver::WebService->debug
238              
239             =head1 BUGS
240              
241             =head1 SUPPORT
242              
243             =head1 AUTHOR
244              
245             Michael R. Davis
246              
247             =head1 COPYRIGHT and LICENSE
248              
249             Copyright (c) 2025 Michael R. Davis
250              
251             This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
252              
253             The full text of the license can be found in the LICENSE file included with this module.
254              
255             =head1 SEE ALSO
256              
257             L, L
258              
259             =cut
260              
261             1;