line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::DataDog::Comment; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
12368
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3
|
use base qw( WebService::DataDog ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
308
|
|
7
|
1
|
|
|
1
|
|
5
|
use Carp qw( carp croak ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
39
|
|
8
|
1
|
|
|
1
|
|
5
|
use Data::Dumper; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
9
|
1
|
|
|
1
|
|
3
|
use Try::Tiny; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
422
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
WebService::DataDog::Comment - Interface to Comment functions in DataDog's API. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 VERSION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Version 1.0.1 |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '1.0.1'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
This module allows you interact with the Comment endpoint of the DataDog API. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Per DataDog: "Comments are how discussion happens on Datadog. You can create, |
30
|
|
|
|
|
|
|
edit, delete and reply to comments. Comments are essentially special forms of |
31
|
|
|
|
|
|
|
events that appear in the stream. They can start a new discussion thread or |
32
|
|
|
|
|
|
|
optionally, reply in another thread." |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
NOTE: the 'handle' parameter must specify a user on the "team" |
35
|
|
|
|
|
|
|
(https://app.datadoghq.com/account/team) associated with |
36
|
|
|
|
|
|
|
your account, otherwise your update will fail with a 400 or 404 error |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 METHODS |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 create() |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Create a new comment. This includes both starting a new thread as well as |
44
|
|
|
|
|
|
|
replying to an existing comment (specified with the 'related_event_id' parameter). |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $comment = $datadog->build('Comment'); |
47
|
|
|
|
|
|
|
$comment->create( |
48
|
|
|
|
|
|
|
message => $message, # the comment text |
49
|
|
|
|
|
|
|
handle => $handle, # optional - handle of the user making the comment |
50
|
|
|
|
|
|
|
related_event_id => $event_id, # optional - the id of another comment or event to reply to |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Example: |
54
|
|
|
|
|
|
|
$comment->create( |
55
|
|
|
|
|
|
|
message => 'My message goes here', |
56
|
|
|
|
|
|
|
handle => 'user@example.com', |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Parameters: |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=over 4 |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item * message |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Text of the comment. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=item * handle |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Handle of the user making the comment. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item * related_event_id |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
The id of another comment or event to reply to. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=back |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub create |
80
|
|
|
|
|
|
|
{ |
81
|
0
|
|
|
0
|
1
|
|
my ( $self, %args ) = @_; |
82
|
0
|
|
|
|
|
|
my $verbose = $self->verbose(); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Check for mandatory parameters |
85
|
0
|
|
|
|
|
|
foreach my $arg ( qw( message ) ) |
86
|
|
|
|
|
|
|
{ |
87
|
0
|
0
|
0
|
|
|
|
croak "ERROR - Argument '$arg' is required for create()." |
88
|
|
|
|
|
|
|
if !defined( $args{$arg} ) || ( $args{$arg} eq '' ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
0
|
|
|
|
if ( defined $args{'related_event_id'} && $args{'related_event_id'} !~ /^\d+$/ ) |
92
|
|
|
|
|
|
|
{ |
93
|
0
|
|
|
|
|
|
croak "ERROR - 'related_event_id' must be an integer"; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my $url = $WebService::DataDog::API_ENDPOINT . 'comments'; |
97
|
|
|
|
|
|
|
|
98
|
0
|
0
|
|
|
|
|
my $data = { |
|
|
0
|
|
|
|
|
|
99
|
|
|
|
|
|
|
message => $args{'message'}, |
100
|
|
|
|
|
|
|
handle => defined $args{'handle'} ? $args{'handle'} : undef, |
101
|
|
|
|
|
|
|
related_event_id => defined $args{'related_event_id'} ? $args{'related_event_id'} : undef, |
102
|
|
|
|
|
|
|
}; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
my $response = $self->_send_request( |
105
|
|
|
|
|
|
|
method => 'POST', |
106
|
|
|
|
|
|
|
url => $url, |
107
|
|
|
|
|
|
|
data => $data, |
108
|
|
|
|
|
|
|
); |
109
|
|
|
|
|
|
|
|
110
|
0
|
0
|
0
|
|
|
|
if ( !defined($response) || !defined($response->{'comment'}) ) |
111
|
|
|
|
|
|
|
{ |
112
|
0
|
|
|
|
|
|
croak "Fatal error. No response or 'comment' missing from response."; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
return $response->{'comment'}; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 update() |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Modify an existing comment. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $comment = $datadog->build('Comment'); |
124
|
|
|
|
|
|
|
$comment->update( |
125
|
|
|
|
|
|
|
comment_id => $comment_id # id of existing comment |
126
|
|
|
|
|
|
|
message => $message, # comment text |
127
|
|
|
|
|
|
|
handle => $handle, # optional - handle of the user making the comment |
128
|
|
|
|
|
|
|
); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Example: |
131
|
|
|
|
|
|
|
$comment->update( |
132
|
|
|
|
|
|
|
comment_id => $existing_comment, |
133
|
|
|
|
|
|
|
message => 'My message goes here', |
134
|
|
|
|
|
|
|
handle => 'user@example.com', |
135
|
|
|
|
|
|
|
); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Parameters: |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=over 4 |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item * comment_id |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
ID of existing comment. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item * message |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Text of the comment. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item * handle |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Handle of the user making the comment. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=back |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub update |
158
|
|
|
|
|
|
|
{ |
159
|
0
|
|
|
0
|
1
|
|
my ( $self, %args ) = @_; |
160
|
0
|
|
|
|
|
|
my $verbose = $self->verbose(); |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# Check for mandatory parameters |
163
|
0
|
|
|
|
|
|
foreach my $arg ( qw( comment_id message ) ) |
164
|
|
|
|
|
|
|
{ |
165
|
0
|
0
|
0
|
|
|
|
croak "ERROR - Argument '$arg' is required for update()." |
166
|
|
|
|
|
|
|
if !defined( $args{$arg} ) || ( $args{$arg} eq '' ); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
my $url = $WebService::DataDog::API_ENDPOINT . 'comments/' . $args{'comment_id'}; |
170
|
|
|
|
|
|
|
|
171
|
0
|
0
|
|
|
|
|
my $data = { |
172
|
|
|
|
|
|
|
message => $args{'message'}, |
173
|
|
|
|
|
|
|
handle => defined $args{'handle'} ? $args{'handle'} : undef, |
174
|
|
|
|
|
|
|
}; |
175
|
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
|
my $response = $self->_send_request( |
177
|
|
|
|
|
|
|
method => 'PUT', |
178
|
|
|
|
|
|
|
url => $url, |
179
|
|
|
|
|
|
|
data => $data, |
180
|
|
|
|
|
|
|
); |
181
|
|
|
|
|
|
|
|
182
|
0
|
0
|
0
|
|
|
|
if ( !defined($response) || !defined($response->{'comment'}) ) |
183
|
|
|
|
|
|
|
{ |
184
|
0
|
|
|
|
|
|
croak "Fatal error. No response or 'comment' missing from response."; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
return $response->{'comment'}; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head2 delete() |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Delete an existing comment. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
my $comment = $datadog->build('Comment'); |
196
|
|
|
|
|
|
|
$comment->delete( comment_id => $existing_comment ); |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Parameters: |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=over 4 |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=item * comment_id |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
ID of existing comment to be deleted. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=back |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub delete |
211
|
|
|
|
|
|
|
{ |
212
|
0
|
|
|
0
|
1
|
|
my ( $self, %args ) = @_; |
213
|
0
|
|
|
|
|
|
my $verbose = $self->verbose(); |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
# Check for mandatory parameters |
216
|
0
|
|
|
|
|
|
foreach my $arg ( qw( comment_id ) ) |
217
|
|
|
|
|
|
|
{ |
218
|
0
|
0
|
0
|
|
|
|
croak "ERROR - Argument '$arg' is required for delete()." |
219
|
|
|
|
|
|
|
if !defined( $args{$arg} ) || ( $args{$arg} eq '' ); |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
0
|
|
|
|
|
|
my $url = $WebService::DataDog::API_ENDPOINT . 'comments/' . $args{'comment_id'}; |
223
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
my $response = $self->_send_request( |
225
|
|
|
|
|
|
|
method => 'DELETE', |
226
|
|
|
|
|
|
|
url => $url, |
227
|
|
|
|
|
|
|
data => {}, |
228
|
|
|
|
|
|
|
); |
229
|
|
|
|
|
|
|
|
230
|
0
|
|
|
|
|
|
return; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
1; |