blib/lib/Net/SMS/Massenversand.pm

filter: Statementstmt 90.3% 56 / 62 Branchbran 50.0% 4 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 100% 3 / 3 totaltotal 88.2% 75 / 85 CC 6 SCAR 6.4
CC
6
Cov
86%
send
3.3
_get_response
3.0
limit
2.0
CRAP 1.9
↑ Summary
1 package Net::SMS::Massenversand;
2 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use base "Class::Accessor::Fast";
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use URI::QueryParam;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 3 __PACKAGE__->mk_accessors(qw(user test password msg_count error id));
11  
12 =head1 NAME
13  
14 Net::SMS::Massenversand - Send SMS via Massenversand.de
15  
16 =head1 VERSION
17  
18 Version 0.03
19  
20 =cut
21  
22 3 our $VERSION = '0.03';
23  
24 =head1 SYNOPSIS
25  
26 use Net::SMS::Massenversand;
27  
28 my $sms = Net::SMS::Massenversand->new();
29 $sms->user('someuserid');
30 $sms->password('somepassword');
31 $sms->send(
32 type => "sms",
33 message => "Your SMS text",
34 sender => 'Your Name',
35 recipient => '00123456789'
36 );
37 my $limit = $sms->limit;
38  
39  
40 =head1 METHODS
41  
42  
43 =head2 new
44  
45 Create a new object.
46  
47 =head2 user
48  
49 Sets the user id of your Massenversand.de account
50  
51 =head2 password
52  
53 Sets the password of your Massenversand.de account
54  
55 =cut
56  
57  
58 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
59 1 my $class = shift;
60 1 return bless( {}, $class );
61 }
62  
63 =head2 limit
64  
65 This method returns the credit which is left at your account.
66  
67 Sets L</error> in case of an error.
68  
69 =cut
70  
71 1 ▶sub limit {
Subroutine limit: called CC=2 SCAR=7.1
Pod documented
72 1 my $self = shift;
73 1 $self->_clear_object;
74 1 my $response = $self->_get_response( getLimit => 1 );
75 1 ▶ if ( $response->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 1 0 1
76 1 my $c = $response->content;
77 1 return $c;
78 } else {
79 0 die $response->status_line;
80 }
81 }
82  
83 =head2 send
84  
85 Sends the actual message. It is called with a hash which includes the necessary
86 information. This method expects a latin1 encoded string as message. Available parameters are:
87  
88 =over
89  
90 =item id
91  
92 Defaults to C<< $sms->user >>
93  
94 =item pw
95  
96 Defaults to C<< $sms->password >>
97  
98 =item receiver
99  
100 Set the phone number of the receiver (international format starting with "00")
101  
102 =item sender
103  
104 11 alphanumerical or 16 numerical characters allowed. Allowed characters: a-z, A-Z and 0-9
105  
106 =item message
107  
108 The actual message you want to send. Mind that the maximum length of a sms is 160. If you
109 want to send more than 160 characters specify C<msgtype>.
110  
111 =item msgtype
112  
113 Specify the type of your sms message. Avaiable types are
114  
115 =over
116  
117 =item t: text SMS
118  
119 =item f: flash SMS
120  
121 =item b: blink SMS
122  
123 =item c: longer-than-160-character SMS
124
125 =back
126  
127 Defaults to C<c>.
128  
129 =back
130  
131 After sending a sms you can access the sms-id which has been set by Massenversand.de
132 by calling L<< $sms->id >> and the number of messages your message was split into
133 L<< $sms->msg_count >>.
134  
135 There are three Massenversand.de servers specified. If one fails the next one
136 is used. The timeout for a request is set to 15 seconds.
137  
138 Returns 1 on success or 0 and sets L</error> in case of an error.
139  
140 =cut
141  
142  
143 1 ▶sub send {
Subroutine send: called CC=3 SCAR=12.0
Pod documented
144 1 my $self = shift(@_);
145 1 my %param = @_;
146 1 $self->_clear_object;
147
148 1 $param{message} = $param{message};
149
150 my $response = $self->_get_response(
151 receiver => $param{receiver},
152 sender => $param{sender},
153 msg => $param{message},
154 1 msgtype => 'c',
155 getID => 1,
156 countMsg => 1,
157 getStatus => 1
158 );
159 1 ▶ if ( $response->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 1 0 1
160 1 my $c = $response->content;
161 1 ▶ if ( $c =~ /OK \((\d+), (\d+) .*\)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ /OK \((\d+), (\d+) .*\)/) { } 0 1 1
162 0 $self->id($1);
163 0 $self->msg_count($2);
164 0 return 1;
165 } else {
166 1 $self->error($self->_parse_error($c));
167 1 return 0;
168 }
169 } else {
170 0 die( $response->status_line );
171 }
172 }
173  
174 2 ▶sub _get_response {
Subroutine _get_response: called CC=3 SCAR=11.1
175 2 my $self = shift;
176 2 my %param = @_;
177 2 my $response;
178 2 for ( 1 .. 3 ) {
179 2 my $url =
180 new URI( 'https://gate' . $_ . '.goyyamobile.com/sms/sendsms.asp' );
181 2 $url->query_form_hash(
182 id => $self->user,
183 pw => $self->password,
184 test => scalar $self->test,
185 %param
186 );
187 2 my $ua = new LWP::UserAgent;
188 2 $ua->timeout(15);
189 2 $response = $ua->get($url);
190 2 ▶ return $response if ( $response->is_success );
Branch: 1 branch
BranchTrueFalseTotal
if $response->is_success 2 0 2
191 }
192 0 return $response;
193 }
194  
195 1 ▶sub _parse_error {
Subroutine _parse_error: called CC=1 SCAR=0.0
196 1 my $self = shift;
197 1 my $c = shift;
198 1 $self->_clear_object;
199 1 $self->error($c);
200 }
201  
202 3 ▶sub _clear_object {
Subroutine _clear_object: called CC=1 SCAR=0.0
203 3 my $self = shift;
204 3 $self->id("");
205 3 $self->msg_count("");
206 }
207  
208 =head1 TODO
209  
210 =over
211  
212 =item Add support for all the sms types like flash sms.
213  
214 =item MMS support
215  
216 =back
217  
218 =head1 AUTHOR
219  
220 Manuel Laux, C<< <laux at netcubed.de> >>,
221  
222 Moritz Onken, C<< <onken at netcubed.de> >>
223  
224 =head1 BUGS
225  
226 Please report any bugs or feature requests to C<bug-net-sms-massenversand at rt.cpan.org>, or through
227 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-SMS-Massenversand>. I will be notified, and then you'll
228 automatically be notified of progress on your bug as I make changes.
229  
230  
231  
232  
233 =head1 SUPPORT
234  
235 You can find documentation for this module with the perldoc command.
236  
237 perldoc Net::SMS::Massenversand
238  
239  
240 You can also look for information at:
241  
242 =over 4
243  
244 =item * RT: CPAN's request tracker
245  
246 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-SMS-Massenversand>
247  
248 =item * AnnoCPAN: Annotated CPAN documentation
249  
250 L<http://annocpan.org/dist/Net-SMS-Massenversand>
251  
252 =item * CPAN Ratings
253  
254 L<http://cpanratings.perl.org/d/Net-SMS-Massenversand>
255  
256 =item * Search CPAN
257  
258 L<http://search.cpan.org/dist/Net-SMS-Massenversand>
259  
260 =back
261  
262 =head1 COPYRIGHT & LICENSE
263  
264 Copyright 2008 netCubed GbR, all rights reserved.
265  
266 This program is free software; you can redistribute it and/or modify it
267 under the same terms as Perl itself.
268  
269  
270 =cut
271  
272 3 1; # End of Net::SMS::Massenversand
↑ Summary