| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WWW::Twilio::API; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
26328
|
use 5.008001; |
|
|
2
|
|
|
|
|
6
|
|
|
4
|
2
|
|
|
2
|
|
6
|
use strict; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
28
|
|
|
5
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
70
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.19'; |
|
8
|
|
|
|
|
|
|
our $Debug = 0; |
|
9
|
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
1706
|
use LWP::UserAgent (); |
|
|
2
|
|
|
|
|
61518
|
|
|
|
2
|
|
|
|
|
43
|
|
|
11
|
2
|
|
|
2
|
|
11
|
use URI::Escape qw(uri_escape uri_escape_utf8); |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
99
|
|
|
12
|
2
|
|
|
2
|
|
7
|
use Carp 'croak'; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
61
|
|
|
13
|
2
|
|
|
2
|
|
7
|
use List::Util 'pairs'; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
1114
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
0
|
|
|
0
|
0
|
0
|
sub API_URL { 'https://api.twilio.com' } |
|
16
|
1
|
|
|
1
|
1
|
3
|
sub API_VERSION { '2010-04-01' } |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
## NOTE: This is an inside-out object; remove members in |
|
19
|
|
|
|
|
|
|
## NOTE: the DESTROY() sub if you add additional members. |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my %account_sid = (); |
|
22
|
|
|
|
|
|
|
my %auth_token = (); |
|
23
|
|
|
|
|
|
|
my %api_version = (); |
|
24
|
|
|
|
|
|
|
my %lwp_callback = (); |
|
25
|
|
|
|
|
|
|
my %utf8 = (); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new { |
|
28
|
1
|
|
|
1
|
1
|
8
|
my $class = shift; |
|
29
|
1
|
|
|
|
|
2
|
my %args = @_; |
|
30
|
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
2
|
my $self = bless \(my $ref), $class; |
|
32
|
|
|
|
|
|
|
|
|
33
|
1
|
|
50
|
|
|
7
|
$account_sid {$self} = $args{AccountSid} || ''; |
|
34
|
1
|
|
50
|
|
|
4
|
$auth_token {$self} = $args{AuthToken} || ''; |
|
35
|
1
|
|
33
|
|
|
3
|
$api_version {$self} = $args{API_VERSION} || API_VERSION(); |
|
36
|
1
|
|
50
|
|
|
4
|
$lwp_callback {$self} = $args{LWP_Callback} || undef; |
|
37
|
1
|
|
50
|
|
|
4
|
$utf8 {$self} = $args{utf8} || undef; |
|
38
|
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
2
|
return $self; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub GET { |
|
43
|
0
|
|
|
0
|
1
|
0
|
_do_request(shift, METHOD => 'GET', API => shift, @_); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub HEAD { |
|
47
|
0
|
|
|
0
|
0
|
0
|
_do_request(shift, METHOD => 'HEAD', API => shift, @_); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub POST { |
|
51
|
0
|
|
|
0
|
1
|
0
|
_do_request(shift, METHOD => 'POST', API => shift, @_); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub PUT { |
|
55
|
0
|
|
|
0
|
1
|
0
|
_do_request(shift, METHOD => 'PUT', API => shift, @_); |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub DELETE { |
|
59
|
0
|
|
|
0
|
|
0
|
_do_request(shift, METHOD => 'DELETE', API => shift, @_); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
## METHOD => GET|POST|PUT|DELETE |
|
63
|
|
|
|
|
|
|
## API => Calls|Accounts|OutgoingCallerIds|IncomingPhoneNumbers| |
|
64
|
|
|
|
|
|
|
## Recordings|Notifications|etc. |
|
65
|
|
|
|
|
|
|
sub _do_request { |
|
66
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
|
67
|
0
|
|
|
|
|
0
|
my %args = @_; |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
my $lwp = LWP::UserAgent->new; |
|
70
|
|
|
|
|
|
|
$lwp_callback{$self}->($lwp) |
|
71
|
0
|
0
|
|
|
|
0
|
if ref($lwp_callback{$self}) eq 'CODE'; |
|
72
|
0
|
|
|
|
|
0
|
$lwp->agent("perl-WWW-Twilio-API/$VERSION"); |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
0
|
my $method = delete $args{METHOD}; |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
0
|
my $url = API_URL() . '/' . $api_version{$self}; |
|
77
|
0
|
|
0
|
|
|
0
|
my $api = delete $args{API} || ''; |
|
78
|
0
|
|
|
|
|
0
|
$url .= "/Accounts/" . $account_sid{$self}; |
|
79
|
0
|
0
|
|
|
|
0
|
$url .= ( $api eq 'Accounts' ? '' : "/$api" ); |
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
0
|
my $content = ''; |
|
82
|
0
|
0
|
|
|
|
0
|
if( keys %args ) { |
|
83
|
0
|
|
|
|
|
0
|
$content = $self->_build_content( %args ); |
|
84
|
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
0
|
if( $method eq 'GET' ) { |
|
86
|
0
|
|
|
|
|
0
|
$url .= '?' . $content; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
0
|
my $req = HTTP::Request->new( $method => $url ); |
|
91
|
0
|
|
|
|
|
0
|
$req->authorization_basic( $account_sid{$self}, $auth_token{$self} ); |
|
92
|
0
|
0
|
0
|
|
|
0
|
if( $content and $method ne 'GET' ) { |
|
93
|
0
|
|
|
|
|
0
|
$req->content_type( 'application/x-www-form-urlencoded' ); |
|
94
|
0
|
|
|
|
|
0
|
$req->content( $content ); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
0
|
local $ENV{HTTPS_DEBUG} = $Debug; |
|
98
|
0
|
|
|
|
|
0
|
my $res = $lwp->request($req); |
|
99
|
0
|
0
|
|
|
|
0
|
print STDERR "Request sent: " . $req->as_string . "\n" if $Debug; |
|
100
|
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
0
|
return { code => $res->code, |
|
102
|
|
|
|
|
|
|
message => $res->message, |
|
103
|
|
|
|
|
|
|
content => $res->content }; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
## builds a string suitable for LWP's content() method |
|
107
|
|
|
|
|
|
|
sub _build_content { |
|
108
|
2
|
|
|
2
|
|
1317
|
my $self = shift; |
|
109
|
|
|
|
|
|
|
|
|
110
|
2
|
50
|
|
|
|
6
|
my $escape_method = $utf8{$self} ? \&uri_escape_utf8 : \&uri_escape; |
|
111
|
|
|
|
|
|
|
|
|
112
|
2
|
|
|
|
|
2
|
my @args = (); |
|
113
|
2
|
|
|
|
|
19
|
for my $pair (pairs @_) { |
|
114
|
7
|
|
|
|
|
104
|
my ($key, $val) = @$pair; |
|
115
|
|
|
|
|
|
|
|
|
116
|
7
|
|
100
|
|
|
11
|
push @args, &$escape_method($key) . '=' . &$escape_method($val // ''); |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
2
|
|
50
|
|
|
47
|
return join('&', @args) || ''; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub DESTROY { |
|
123
|
1
|
|
|
1
|
|
660
|
my $self = $_[0]; |
|
124
|
|
|
|
|
|
|
|
|
125
|
1
|
|
|
|
|
3
|
delete $account_sid {$self}; |
|
126
|
1
|
|
|
|
|
1
|
delete $auth_token {$self}; |
|
127
|
1
|
|
|
|
|
2
|
delete $api_version {$self}; |
|
128
|
1
|
|
|
|
|
1
|
delete $lwp_callback{$self}; |
|
129
|
1
|
|
|
|
|
2
|
delete $utf8 {$self}; |
|
130
|
|
|
|
|
|
|
|
|
131
|
1
|
|
|
|
|
8
|
my $super = $self->can("SUPER::DESTROY"); |
|
132
|
1
|
50
|
|
|
|
25
|
goto &$super if $super; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |
|
136
|
|
|
|
|
|
|
__END__ |