line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Slack::WebApi::Client; |
2
|
5
|
|
|
5
|
|
37
|
use strict; |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
181
|
|
3
|
5
|
|
|
5
|
|
30
|
use warnings; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
150
|
|
4
|
5
|
|
|
5
|
|
25
|
use utf8; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
33
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
3376
|
use HTTP::AnyUA; |
|
5
|
|
|
|
|
114384
|
|
|
5
|
|
|
|
|
186
|
|
7
|
5
|
|
|
5
|
|
2364
|
use JSON; |
|
5
|
|
|
|
|
31730
|
|
|
5
|
|
|
|
|
38
|
|
8
|
5
|
|
|
5
|
|
728
|
use WebService::Slack::WebApi::Exception; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
298
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Class::Accessor::Lite::Lazy ( |
11
|
5
|
|
|
|
|
112
|
new => 1, |
12
|
|
|
|
|
|
|
rw => [qw/ team_domain token opt useragent /], |
13
|
|
|
|
|
|
|
ro_lazy => [qw/ ua /], |
14
|
5
|
|
|
5
|
|
35
|
); |
|
5
|
|
|
|
|
11
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _build_ua { |
17
|
7
|
|
|
7
|
|
129
|
my $self = shift; |
18
|
7
|
|
|
|
|
16
|
my $ua; |
19
|
|
|
|
|
|
|
# Before introducing the parameter 'ua' to WebService::Slack::WebApi |
20
|
|
|
|
|
|
|
# we used Furl. So let's keep ourselves backward compatible! |
21
|
7
|
100
|
|
|
|
40
|
if( $self->useragent ) { |
22
|
4
|
|
|
|
|
65
|
$ua = HTTP::AnyUA->new( ua => $self->useragent ); |
23
|
|
|
|
|
|
|
} else { |
24
|
|
|
|
|
|
|
# Attn. Using expression form of eval because otherwise |
25
|
|
|
|
|
|
|
# the "use" would be executed before arriving to eval. |
26
|
3
|
50
|
|
2
|
|
247
|
eval 'use Furl; 1;' or do { |
|
2
|
|
|
1
|
|
1187
|
|
|
2
|
|
|
|
|
46517
|
|
|
2
|
|
|
|
|
40
|
|
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
12
|
|
27
|
0
|
|
|
|
|
0
|
my $msg = 'Illegal parameters. Unable to use package Furl.' |
28
|
|
|
|
|
|
|
. ' If no \'ua\' is defined, we use Furl by default'; |
29
|
0
|
|
|
|
|
0
|
WebService::Slack::WebApi::Exception::IllegalParameters->throw( |
30
|
|
|
|
|
|
|
message => $msg, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
}; |
33
|
3
|
|
100
|
|
|
12
|
my %opt = %{ $self->opt // +{} }; |
|
3
|
|
|
|
|
17
|
|
34
|
3
|
|
|
|
|
49
|
my $env_proxy = delete $opt{env_proxy}; |
35
|
3
|
|
|
|
|
16
|
my $furl = Furl->new(%opt); |
36
|
3
|
100
|
|
|
|
145
|
$furl->env_proxy if $env_proxy; |
37
|
3
|
|
|
|
|
36
|
$ua = HTTP::AnyUA->new( ua => $furl ); |
38
|
|
|
|
|
|
|
} |
39
|
7
|
|
|
|
|
384
|
return $ua; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub base_url { |
43
|
109
|
|
|
109
|
0
|
646
|
my $self = shift; |
44
|
109
|
50
|
|
|
|
229
|
my $team_domain = $self->team_domain ? $self->team_domain . '.' : ''; |
45
|
109
|
|
|
|
|
712
|
return sprintf 'https://%sslack.com/api', $team_domain; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub request { |
49
|
110
|
|
|
110
|
0
|
788
|
my ($self, $path, $params) = @_; |
50
|
|
|
|
|
|
|
|
51
|
110
|
|
|
|
|
175
|
my %headers; |
52
|
110
|
100
|
100
|
|
|
253
|
if( $self->token && $params->{'http_auth'} ) { |
53
|
1
|
|
|
|
|
9
|
my $msg = 'Illegal parameters. You have defined \'token\' but the ' |
54
|
|
|
|
|
|
|
. ' method you are using defines its own HTTP Authorization header.'; |
55
|
1
|
|
|
|
|
31
|
WebService::Slack::WebApi::Exception::IllegalParameters->throw( |
56
|
|
|
|
|
|
|
message => $msg, |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
} |
59
|
109
|
100
|
|
|
|
872
|
if( $self->token ) { |
|
|
50
|
|
|
|
|
|
60
|
108
|
|
|
|
|
550
|
$headers{ 'Authorization' } = 'Bearer ' . $self->token; |
61
|
|
|
|
|
|
|
} elsif( $params->{'http_auth'} ) { |
62
|
1
|
|
|
|
|
7
|
$headers{ 'Authorization' } = $params->{'http_auth'}; |
63
|
|
|
|
|
|
|
} |
64
|
109
|
|
|
|
|
615
|
my %options = ( headers => \%headers ); |
65
|
|
|
|
|
|
|
my $response = $self->ua->post_form( |
66
|
|
|
|
|
|
|
$self->base_url . $path, |
67
|
|
|
|
|
|
|
[ |
68
|
109
|
|
|
|
|
334
|
%{ $params }, |
|
109
|
|
|
|
|
646
|
|
69
|
|
|
|
|
|
|
], |
70
|
|
|
|
|
|
|
\%options, |
71
|
|
|
|
|
|
|
); |
72
|
109
|
100
|
|
|
|
33374
|
return decode_json $response->{content} if $response->{success}; |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
22
|
WebService::Slack::WebApi::Exception::FailureResponse->throw( |
75
|
|
|
|
|
|
|
message => 'request failed.', |
76
|
|
|
|
|
|
|
response => $response, |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|