line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Slack::IncomingWebHook; |
2
|
3
|
|
|
3
|
|
507710
|
use 5.008001; |
|
3
|
|
|
|
|
12
|
|
3
|
3
|
|
|
3
|
|
19
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
208
|
|
4
|
3
|
|
|
3
|
|
18
|
use warnings; |
|
3
|
|
|
|
|
17
|
|
|
3
|
|
|
|
|
163
|
|
5
|
3
|
|
|
3
|
|
2661
|
use utf8; |
|
3
|
|
|
|
|
36
|
|
|
3
|
|
|
|
|
16
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
1103
|
use JSON; |
|
3
|
|
|
|
|
21859
|
|
|
3
|
|
|
|
|
24
|
|
8
|
3
|
|
|
3
|
|
2535
|
use Furl; |
|
3
|
|
|
|
|
77655
|
|
|
3
|
|
|
|
|
118
|
|
9
|
3
|
|
|
3
|
|
25
|
use Carp (); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
1096
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = "0.02"; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
12
|
|
|
12
|
1
|
30849
|
my ($class, %args) = @_; |
15
|
12
|
100
|
|
|
|
132
|
Carp::croak('required webhook url') if ! exists $args{webhook_url}; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $self = bless { |
18
|
11
|
|
|
|
|
25
|
map { ( $_ => $args{$_} ) } qw( webhook_url channel icon_emoji icon_url username ) |
|
55
|
|
|
|
|
166
|
|
19
|
|
|
|
|
|
|
} => $class; |
20
|
|
|
|
|
|
|
|
21
|
11
|
|
|
|
|
153
|
$self->{json} = JSON->new->utf8; |
22
|
11
|
|
|
|
|
84
|
$self->{furl} = Furl->new(agent => "$class.$VERSION"); |
23
|
|
|
|
|
|
|
|
24
|
11
|
|
|
|
|
612
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub post { |
28
|
5
|
|
|
5
|
1
|
46
|
my ($self, %args) = @_; |
29
|
|
|
|
|
|
|
|
30
|
5
|
|
|
|
|
24
|
my $post_data = $self->_make_post_data(%args); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $res = $self->{furl}->post( |
33
|
|
|
|
|
|
|
$self->{webhook_url}, |
34
|
|
|
|
|
|
|
['Content-Type' => 'application/json'], |
35
|
5
|
|
|
|
|
127
|
$self->{json}->encode($post_data), |
36
|
|
|
|
|
|
|
); |
37
|
5
|
50
|
|
|
|
14733
|
if (! $res->is_success) { |
38
|
5
|
|
|
|
|
92
|
Carp::carp('post failed: '. $res->body); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _make_post_data { |
43
|
11
|
|
|
11
|
|
39
|
my ($self, %args) = @_; |
44
|
|
|
|
|
|
|
return +{ |
45
|
|
|
|
|
|
|
( |
46
|
|
|
|
|
|
|
map { |
47
|
55
|
100
|
|
|
|
132
|
exists $args{$_} ? ( $_ => $args{$_} ) : () |
48
|
|
|
|
|
|
|
} qw( text pretext color fields attachments ) |
49
|
|
|
|
|
|
|
), |
50
|
|
|
|
|
|
|
# override if parameter specified |
51
|
|
|
|
|
|
|
( |
52
|
|
|
|
|
|
|
map { |
53
|
11
|
100
|
|
|
|
21
|
( $_ => exists $args{$_} ? $args{$_} : $self->{$_} ) |
|
44
|
|
|
|
|
184
|
|
54
|
|
|
|
|
|
|
} qw( channel icon_emoji icon_url username ) |
55
|
|
|
|
|
|
|
), |
56
|
|
|
|
|
|
|
}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
__END__ |