line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
43630
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
3
|
|
|
|
|
|
|
package SMS::Send::WebSMS; |
4
|
|
|
|
|
|
|
$SMS::Send::WebSMS::VERSION = '0.001'; |
5
|
|
|
|
|
|
|
# ABSTRACT: SMS::Send driver for the WebSMS service |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
3
|
use Carp; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
50
|
|
8
|
1
|
|
|
1
|
|
661
|
use HTTP::Tiny; |
|
1
|
|
|
|
|
44267
|
|
|
1
|
|
|
|
|
62
|
|
9
|
1
|
|
|
1
|
|
753
|
use URI::Escape qw( uri_escape ); |
|
1
|
|
|
|
|
1470
|
|
|
1
|
|
|
|
|
65
|
|
10
|
1
|
|
|
1
|
|
505
|
use JSON::MaybeXS qw( decode_json encode_json JSON ); |
|
1
|
|
|
|
|
5535
|
|
|
1
|
|
|
|
|
75
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
7
|
use base 'SMS::Send::Driver'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
370
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
4
|
|
|
4
|
1
|
3191
|
my $class = shift; |
17
|
4
|
|
|
|
|
13
|
my $self = { @_ }; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$self->{$_} |
20
|
|
|
|
|
|
|
or croak "$_ missing" |
21
|
4
|
|
100
|
|
|
69
|
for qw( _login _password ); |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
5
|
return bless $self, $class; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub send_sms { |
27
|
0
|
|
|
0
|
1
|
|
my ($self, %args) = @_; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my $http = HTTP::Tiny->new( |
30
|
|
|
|
|
|
|
default_headers => { |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# to ensure the response is JSON and not the XML default |
33
|
|
|
|
|
|
|
'accept' => 'application/json; charset=utf-8', |
34
|
|
|
|
|
|
|
'content-type' => 'application/json; charset=utf-8', |
35
|
|
|
|
|
|
|
}, |
36
|
|
|
|
|
|
|
timeout => 3, |
37
|
|
|
|
|
|
|
verify_ssl => 1, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# remove leading + |
41
|
0
|
|
|
|
|
|
( my $recipient = $args{to} ) =~ s/^\+//; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my %message = ( |
44
|
|
|
|
|
|
|
messageContent => $args{text}, |
45
|
|
|
|
|
|
|
recipientAddressList => [ $recipient ], |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# add all underscore args |
49
|
0
|
|
|
|
|
|
$message{$_} = $args{"_$_"} |
50
|
0
|
|
|
|
|
|
for map { $_ =~ s/^_//; $_; } |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
grep { $_ =~ /^_/ } keys %args; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $response = $http->post( |
54
|
|
|
|
|
|
|
'https://' |
55
|
|
|
|
|
|
|
. uri_escape( $self->{_login} ) |
56
|
|
|
|
|
|
|
. ':' |
57
|
|
|
|
|
|
|
. uri_escape( $self->{_password} ) |
58
|
|
|
|
|
|
|
. '@api.websms.com/rest/smsmessaging/text', |
59
|
|
|
|
|
|
|
{ |
60
|
|
|
|
|
|
|
content => encode_json(\%message), |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# for example a timeout error |
65
|
0
|
0
|
|
|
|
|
die $response->{content} |
66
|
|
|
|
|
|
|
unless $response->{success}; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
my $response_message = decode_json( $response->{content} ); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# https://websms.at/entwickler/apis/rest-sms-api#dev-rest-statuscodes |
71
|
0
|
0
|
|
|
|
|
return 1 |
72
|
|
|
|
|
|
|
if $response_message->{statusCode} =~ /^20\d\d/; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
$@ = $response_message; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return 0; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |