line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Spoor::EntryTransmitter; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
230466
|
use v5.10; |
|
1
|
|
|
|
|
8
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
6
|
1
|
|
|
1
|
|
4
|
use JSON; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
81
|
use MIME::Base64 qw(encode_base64); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
168
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
App::Spoor::EntryTransmitter |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Version 0.01 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Makes a call to the Spoor API. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 transmit |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
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'. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my %data = ( |
32
|
|
|
|
|
|
|
... |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
my $user_agent = LWP::UserAgent->new; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $transmission_config = App::Spoor::Config::get_transmission_config(); |
37
|
|
|
|
|
|
|
$transmission_config->{'reporter'} = 'foo.baz.com'; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
App::Spoor::EntryTransmitter::transmit(\%data, $user_agent, $transmission_config); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub transmit { |
44
|
4
|
|
|
4
|
1
|
10701
|
my $data = shift; |
45
|
4
|
|
|
|
|
7
|
my $ua = shift; |
46
|
4
|
|
|
|
|
5
|
my $config = shift; |
47
|
|
|
|
|
|
|
|
48
|
4
|
|
|
|
|
12
|
my $uri = $config->{host} . $config->{endpoints}{report}; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $credentials = 'Basic ' . encode_base64( |
51
|
|
|
|
|
|
|
$config->{credentials}{api_identifier} . ':' . $config->{credentials}{api_secret} |
52
|
4
|
|
|
|
|
21
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $content = to_json({ |
55
|
|
|
|
|
|
|
report => { |
56
|
|
|
|
|
|
|
entries => [ |
57
|
|
|
|
|
|
|
$data |
58
|
|
|
|
|
|
|
], |
59
|
|
|
|
|
|
|
metadata => { |
60
|
|
|
|
|
|
|
reporter => $config->{reporter} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
}, |
63
|
4
|
|
|
|
|
25
|
}); |
64
|
|
|
|
|
|
|
|
65
|
4
|
|
|
|
|
99
|
my $result = $ua->post( |
66
|
|
|
|
|
|
|
$uri, |
67
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
68
|
|
|
|
|
|
|
'Authorization' => $credentials, |
69
|
|
|
|
|
|
|
'Content' => $content |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
|
72
|
4
|
|
|
|
|
13304
|
$result->code() eq '202'; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 AUTHOR |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Rory McKinley, C<< <rorymckinley at capefox.co> >> |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 BUGS |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Please report any bugs or feature requests to C<bug-. at rt.cpan.org>, or through |
82
|
|
|
|
|
|
|
the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=.>. I will be notified, and then you'll |
83
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SUPPORT |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
perldoc App::Spoor::EntryTransmitter |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
You can also look for information at: |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=over 4 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=.> |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
L<http://annocpan.org/dist/.> |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item * CPAN Ratings |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
L<https://cpanratings.perl.org/d/.> |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item * Search CPAN |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
L<https://metacpan.org/release/.> |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=back |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
116
|
|
|
|
|
|
|
Copyright 2019 Rory McKinley. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
119
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
120
|
|
|
|
|
|
|
copy of the full license at: |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
L<http://www.perlfoundation.org/artistic_license_2_0> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
125
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
126
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
127
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
130
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
131
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
134
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
137
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
138
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
139
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
140
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
141
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
142
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
143
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
146
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
147
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
148
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
149
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
150
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
151
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
152
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
1; # End of App::Spoor::EntryTransmitter |