Spoor/ApiClient.pm

filter: Statementstmt 100% 33 / 33 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 100% 43 / 43 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Spoor/AccessUnitFile.pm ↑ Summary Spoor/CpanelHookFile.pm »
1 package App::Spoor::ApiClient;
2  
3 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use PHP::HTTPBuildQuery qw(http_build_query);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use MIME::Base64 qw(encode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 App::Spoor::ApiClient
13  
14 =head1 VERSION
15  
16 Version 0.07
17  
18 =cut
19  
20 1 our $VERSION = '0.07';
21  
22 =head1 SYNOPSIS
23  
24 Interacts with the Spoor API. see the individual subroutines for more detail.
25  
26 use Sys::Hostname;
27 use App::Spoor::ApiClient;
28  
29 my %data = (
30 ...
31 );
32 my $user_agent = LWP::UserAgent->new;
33  
34 my $transmission_config = App::Spoor::Config::get_transmission_config();
35  
36 App::Spoor::ApiClient::most_recent_reports(hostname, $user_agent, $transmission_config);
37 App::Spoor::ApiClient::most_recent_mailbox_events(hostname, $user_agent, $transmission_config);
38  
39 =head1 SUBROUTINES/METHODS
40  
41 =head2 most_recent_reports
42  
43 Fetches the most recent reports from the SpoorAPI. When the SpoorAPI receives data, it creates a report instance. This
44 report instance is then parsed and, if all is in order, a mailbox event is created.
45  
46 This subroutine returns a reference to an array of hashes representing the individual report instances.
47  
48 use Sys::Hostname;
49 use App::Spoor::ApiClient;
50  
51 my %data = (
52 ...
53 );
54 my $user_agent = LWP::UserAgent->new;
55  
56 my $transmission_config = App::Spoor::Config::get_transmission_config();
57  
58 App::Spoor::ApiClient::most_recent_reports(hostname, $user_agent, $transmission_config);
59  
60 =cut
61  
62 1 ▶sub most_recent_reports {
Subroutine most_recent_reports: called CC=1 SCAR=0.0
Pod documented
63 1 my $host = shift;
64 1 my $user_agent = shift;
65 1 my $config = shift;
66  
67 1 my $uri = $config->{host} . '/api/reports?' . http_build_query({reports => {host => $host}});
68  
69 my $credentials = 'Basic ' . encode_base64(
70 $config->{credentials}{api_identifier} . ':' . $config->{credentials}{api_secret}
71 1 );
72  
73 1 my $response = $user_agent->get(
74 $uri,
75 'Authorization' => $credentials,
76 'HTTP-Accept' => 'application/json'
77 );
78  
79 1 from_json($response->content)->{reports};
80 }
81  
82 =head2 most_recent_mailbox_events
83  
84 Fetches the most recent mailbox events from the SpoorAPI.
85  
86 Thsi subroutine returns a reference to an array of hashes representing individual mailbox events.
87  
88 use Sys::Hostname;
89 use App::Spoor::ApiClient;
90  
91 my %data = (
92 ...
93 );
94 my $user_agent = LWP::UserAgent->new;
95  
96 my $transmission_config = App::Spoor::Config::get_transmission_config();
97  
98 App::Spoor::ApiClient::most_recent_mailbox_events(hostname, $user_agent, $transmission_config);
99  
100 =cut
101  
102 1 ▶sub most_recent_mailbox_events {
Subroutine most_recent_mailbox_events: called CC=1 SCAR=0.0
Pod documented
103 1 my $host = shift;
104 1 my $user_agent = shift;
105 1 my $config = shift;
106  
107 1 my $uri = $config->{host} . '/api/mailbox_events?' . http_build_query({mailbox_events => {host => $host}});
108  
109 my $credentials = 'Basic ' . encode_base64(
110 $config->{credentials}{api_identifier} . ':' . $config->{credentials}{api_secret}
111 1 );
112  
113 1 my $response = $user_agent->get(
114 $uri,
115 'Authorization' => $credentials,
116 'HTTP-Accept' => 'application/json'
117 );
118  
119 1 from_json($response->content)->{mailbox_events};
120 }
121  
122 =head1 AUTHOR
123  
124 Rory McKinley, C<< <rorymckinley at capefox.co> >>
125  
126 =head1 BUGS
127  
128 Please report any bugs or feature requests to C<bug-. at rt.cpan.org>, or through
129 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=.>. I will be notified, and then you'll
130 automatically be notified of progress on your bug as I make changes.
131  
132  
133 =head1 SUPPORT
134  
135 You can find documentation for this module with the perldoc command.
136  
137 perldoc App::Spoor::ApiClient
138  
139  
140 You can also look for information at:
141  
142 =over 4
143  
144 =item * RT: CPAN's request tracker (report bugs here)
145  
146 L<httops://rt.cpan.org/NoAuth/Bugs.html?Dist=.>
147  
148 =item * AnnoCPAN: Annotated CPAN documentation
149  
150 L<http://annocpan.org/dist/.>
151  
152 =item * CPAN Ratings
153  
154 L<https://cpanratings.perl.org/d/.>
155  
156 =item * Search CPAN
157  
158 L<https://metacpan.org/release/.>
159  
160 =back
161  
162 =head1 LICENSE AND COPYRIGHT
163  
164 Copyright 2019 Rory McKinley.
165  
166 This program is free software; you can redistribute it and/or modify it
167 under the terms of the the Artistic License (2.0). You may obtain a
168 copy of the full license at:
169  
170 L<http://www.perlfoundation.org/artistic_license_2_0>
171  
172 Any use, modification, and distribution of the Standard or Modified
173 Versions is governed by this Artistic License. By using, modifying or
174 distributing the Package, you accept this license. Do not use, modify,
175 or distribute the Package, if you do not accept this license.
176  
177 If your Modified Version has been derived from a Modified Version made
178 by someone other than you, you are nevertheless required to ensure that
179 your Modified Version complies with the requirements of this license.
180  
181 This license does not grant you the right to use any trademark, service
182 mark, tradename, or logo of the Copyright Holder.
183  
184 This license includes the non-exclusive, worldwide, free-of-charge
185 patent license to make, have made, use, offer to sell, sell, import and
186 otherwise transfer the Package with respect to any patent claims
187 licensable by the Copyright Holder that are necessarily infringed by the
188 Package. If you institute patent litigation (including a cross-claim or
189 counterclaim) against any party alleging that the Package constitutes
190 direct or contributory patent infringement, then this Artistic License
191 to you shall terminate on the date that such litigation is filed.
192  
193 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
194 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
195 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
196 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
197 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
198 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
199 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
200 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
201  
202  
203 =cut
204  
205 1 1; # End of App::Spoor::ApiClient
« Spoor/AccessUnitFile.pm ↑ Summary Spoor/CpanelHookFile.pm »