our
$VERSION
=
'0.002'
;
sub
new {
my
$class
=
shift
;
my
$self
=
$class
->SUPER::new(
@_
);
my
%extra_args
;
if
(
defined
$self
->ua_timeout) {
$extra_args
{timeout} =
$self
->ua_timeout;
}
$self
->{_ua} = LWP::UserAgent->new(
agent
=>
$self
->agent_string(),
%extra_args
);
return
$self
;
}
sub
_post_data {
my
$self
=
shift
;
$self
->log_info(
"Posting to %s via %s."
,
$self
->smokedb_url,
$self
->poster);
$self
->log_debug(
"Report data: %s"
,
my
$json
=
$self
->get_json);
my
$response
=
$self
->ua->post(
$self
->smokedb_url,
{
json
=>
$json
}
);
if
( !
$response
->is_success ) {
$self
->log_warn(
"POST failed: %s"
,
$response
->status_line);
die
sprintf
(
"POST to '%s' failed: %s%s\n"
,
$self
->smokedb_url,
$response
->status_line,
(
$response
->content ?
sprintf
(
" (%s)"
,
$response
->content) :
""
),
);
}
$self
->log_debug(
"[CoreSmokeDB] %s"
,
$response
->content);
return
$response
->content;
}
sub
_post_data_api {
my
$self
=
shift
;
$self
->log_info(
"Posting to %s via %s."
,
$self
->smokedb_url,
$self
->poster);
$self
->log_debug(
"Report data: %s"
,
my
$json
=
$self
->get_json);
my
$post_data
=
sprintf
(
qq/{"report_data": %s}/
,
$json
);
my
$request
= HTTP::Request->new(
POST
=>
$self
->smokedb_url,
HTTP::Headers->new(
'Content-Type'
,
'application/json'
),
$post_data
,
);
my
$response
=
$self
->ua->request(
$request
);
if
(!
$response
->is_success) {
$self
->log_warn(
"POST failed: %s"
,
$response
->status_line);
if
(not
$self
->queue_this_report()) {
die
sprintf
(
"POST to '%s' failed: %s%s\n"
,
$self
->smokedb_url,
$response
->status_line,
(
$response
->content ?
sprintf
(
" (%s)"
,
$response
->content) :
""
),
);
}
}
$self
->log_debug(
"[CoreSmokeDB] %s"
,
$response
->content);
return
$response
->content;
}
1;