| 1 | package Gruntmaster::SendResults; |
| 2 | |
| 3 | use 5.014000; |
| 4 | use strict; |
| 5 | use warnings; |
| 6 | use parent qw/Exporter/; |
| 7 | |
| 8 | use HTTP::Request; |
| 9 | use JSON qw/encode_json decode_json/; |
| 10 | use LWP::UserAgent; |
| 11 | |
| 12 | our $VERSION = '5999.000_005'; |
| 13 | our @EXPORT_OK = qw/send_results_request/; |
| 14 | |
| 15 | sub send_results_request { |
| 16 | my ($job_id, $result, $result_text) = @_; |
| 17 | |
| 18 | my $url = $ENV{REMOTE_ADDRESS}; |
| 19 | my $header = [ |
| 20 | 'Content-Type' => 'application/json' |
| 21 | ]; |
| 22 | my $data = { |
| 23 | gm_id => $job_id, |
| 24 | result => $result, |
| 25 | result_text => $result_text |
| 26 | }; |
| 27 | |
| 28 | my $encoded_data = encode_json($data); |
| 29 | my $request = HTTP::Request->new(POST => $url, $header, $encoded_data); |
| 30 | my $ua = LWP::UserAgent->new(); |
| 31 | my $response = $ua->request($request); |
| 32 | |
| 33 | return $response; |
| 34 | } |
| 35 | |
| 36 | 1; |