App-Spoor
view release on metacpan or search on metacpan
lib/App/Spoor/EntryTransmitter.pm view on Meta::CPAN
package App::Spoor::EntryTransmitter;
use v5.10;
use strict;
use warnings;
use JSON;
use MIME::Base64 qw(encode_base64);
=head1 NAME
App::Spoor::EntryTransmitter
=head1 VERSION
Version 0.01
=cut
our $VERSION = '0.01';
=head1 SYNOPSIS
Makes a call to the Spoor API.
=head1 SUBROUTINES/METHODS
=head2 transmit
Transmits a report to the Spoor API. Returns a 'truthy' response if the API responds with HTTP '202', and a falsey response if the API responds with anything other than '202'.
my %data = (
...
);
my $user_agent = LWP::UserAgent->new;
my $transmission_config = App::Spoor::Config::get_transmission_config();
$transmission_config->{'reporter'} = 'foo.baz.com';
App::Spoor::EntryTransmitter::transmit(\%data, $user_agent, $transmission_config);
=cut
sub transmit {
my $data = shift;
my $ua = shift;
my $config = shift;
my $uri = $config->{host} . $config->{endpoints}{report};
my $credentials = 'Basic ' . encode_base64(
$config->{credentials}{api_identifier} . ':' . $config->{credentials}{api_secret}
);
my $content = to_json({
report => {
entries => [
$data
],
metadata => {
reporter => $config->{reporter}
}
},
});
my $result = $ua->post(
$uri,
'Content-Type' => 'application/json',
'Authorization' => $credentials,
'Content' => $content
);
$result->code() eq '202';
}
=head1 AUTHOR
Rory McKinley, C<< <rorymckinley at capefox.co> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-. at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=.>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc App::Spoor::EntryTransmitter
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker (report bugs here)
L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=.>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/.>
=item * CPAN Ratings
L<https://cpanratings.perl.org/d/.>
( run in 1.690 second using v1.01-cache-2.11-cpan-5a3173703d6 )