line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SMS::ClickSend; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
15671
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
15
|
use 5.008_005; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
71
|
|
8
|
1
|
|
|
1
|
|
23929
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
44113
|
|
|
1
|
|
|
|
|
31
|
|
9
|
1
|
|
|
1
|
|
680
|
use JSON; |
|
1
|
|
|
|
|
9639
|
|
|
1
|
|
|
|
|
5
|
|
10
|
1
|
|
|
1
|
|
585
|
use MIME::Base64; |
|
1
|
|
|
|
|
543
|
|
|
1
|
|
|
|
|
76
|
|
11
|
1
|
|
|
1
|
|
5
|
use HTTP::Request; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
12
|
1
|
|
|
1
|
|
4
|
use vars qw/$errstr/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
445
|
|
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
0
|
0
|
|
sub errstr { $errstr } |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
18
|
0
|
0
|
|
|
|
|
my %args = @_ % 2 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
0
|
0
|
|
|
|
|
$args{username} or croak 'username is required.'; |
21
|
0
|
0
|
|
|
|
|
$args{api_key} or croak 'api_key is required.'; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
0
|
|
|
|
$args{ua} ||= LWP::UserAgent->new; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
return bless \%args, $class; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub send { |
29
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
30
|
0
|
0
|
|
|
|
|
my %params = @_ % 2 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
$self->request('send', 'GET', \%params); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub reply { |
35
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
36
|
0
|
0
|
|
|
|
|
my %params = @_ % 2 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$self->request('reply', 'GET', \%params); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub delivery { |
41
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
42
|
0
|
|
|
|
|
|
my %params; |
43
|
0
|
0
|
0
|
|
|
|
if (scalar(@_) == 1 and ref($_[0]) ne 'HASH') { |
44
|
0
|
|
|
|
|
|
%params = (messageid => $_[0]); |
45
|
|
|
|
|
|
|
} else { |
46
|
0
|
0
|
|
|
|
|
%params = @_ % 2 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
48
|
0
|
|
|
|
|
|
$self->request('delivery', 'GET', \%params); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub balance { |
52
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
53
|
0
|
|
|
|
|
|
my %params; |
54
|
0
|
0
|
0
|
|
|
|
if (scalar(@_) == 1 and ref($_[0]) ne 'HASH') { |
55
|
0
|
|
|
|
|
|
%params = (country => $_[0]); |
56
|
|
|
|
|
|
|
} else { |
57
|
0
|
0
|
|
|
|
|
%params = @_ % 2 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} |
59
|
0
|
|
|
|
|
|
$self->request('balance', 'GET', \%params); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub history { |
63
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
64
|
0
|
0
|
|
|
|
|
my %params = @_ % 2 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$self->request('history', 'GET', \%params); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub request { |
69
|
0
|
|
|
0
|
0
|
|
my ($self, $url, $method, $params) = @_; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$url = 'https://api.clicksend.com/rest/v2/' . $url . '.json'; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
0
|
|
|
|
$params ||= {}; |
74
|
0
|
|
|
|
|
|
$params->{method} = 'rest'; # we prefer rest |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $uri = URI->new($url); |
77
|
0
|
|
|
|
|
|
$uri->query_form($params); |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my %headers = (); |
80
|
0
|
|
|
|
|
|
$headers{Authorization} = 'Basic ' . encode_base64($self->{username} . ':' . $self->{api_key}, ''); |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new($method, $uri, HTTP::Headers->new(%headers)); |
83
|
0
|
|
|
|
|
|
my $res = $self->{ua}->request($req); |
84
|
0
|
0
|
|
|
|
|
if (not $res->header('Content-Type') =~ /json/) { |
85
|
0
|
|
|
|
|
|
$errstr = $res->status_line; |
86
|
0
|
|
|
|
|
|
return; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return decode_json($res->decoded_content); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
__END__ |