Astro-SpaceTrack
view release on metacpan or search on metacpan
inc/Mock/LWP/UserAgent.pm view on Meta::CPAN
F<t/data/Mock-LWP-UserAgent/resp.json>, but this can be changed by
localizing C<$Mock::LWP::UserAgent::CANNED_RESPONSE_FILE> and storing
the path to the desired file in it B<before> instantiating
L<LWP::UserAgent|LWP::UserAgent>.
The canned response file is a JSON representaton of a hash keyed by URL
and, within URL, by HTTP method (C<GET>, C<POST>, and so on). The actual
responses are four-element arrays that constitute the arguments to
C<< HTTP::Response->new() >>.
Assuming the given file can be opened, read, and decoded, any request
will be satisfied by an L<HTTP::Response|HTTP::Response> object
generated from the data in the file. If the URL and method do not appear
in the file, a 404 response is generated.
=head1 METHODS
This class supports the following public method:
=head2 install_mock
inc/Mock/LWP/UserAgent.pm view on Meta::CPAN
=head1 SUBROUTINES
This class also has a couple old-school subroutines to manage its data.
These are unsupported, and documented solely for the convenience of the
author.
=head2 __load_data
This subroutine loads data from a JSON file and returns a reference to a
two-element hash. Key C<{path}> contains the path to the file, and key
C<{data}> contains the data in the file, after it has been decoded from
JSON.
The path to the file comes from
C<$Mock::LWP::UserAgent::CANNED_DATA_FILE>. If that is C<undef> (which
it is by default), F<t/data/Mock-LWP-UserAgent/resp.json> is read.
Optional arguments can be specified as name/value pairs. The following
arguments are supported:
=over
lib/Astro/SpaceTrack.pm view on Meta::CPAN
# content
# Invalid query: "GROUP=fubar&FORMAT=TLE" (GROUP=fubar not found)
unless ( $resp->is_success() ) {
$resp->code == HTTP_NOT_FOUND
and return $self->_no_such_catalog(
$source => $name, @args);
return $resp;
}
my $content = $resp->decoded_content();
if ( $content =~ m/ \A Invalid \s+ query: /smx ) {
$content =~ m/ \b (?: GROUP | FILE ) =\Q$name\E \s not \s found \b /smx
and return $self->_no_such_catalog(
$source => $name, @args);
$resp->code( HTTP_BAD_REQUEST );
$resp->message( HTTP::Status::status_message(
HTTP_BAD_REQUEST ) );
return $resp;
}
lib/Astro/SpaceTrack.pm view on Meta::CPAN
or do {
my $msg = 'No Content-Type header found';
@args and $msg = "@args; $msg";
return $self->_no_such_catalog(
$source => $name, $msg);
};
foreach my $type ( _trim( split ',', $type ) ) {
$type =~ s/ ; .* //smx;
$valid_type{$type}
or next;
local $_ = $resp->decoded_content();
# As of February 12 2022 Celestrak does this
# As of July 23 2022 this is not at the beginning of the
# string
m/^No GP data found\b/sm
and last;
# As of July 25 2022 Celestrak does this.
m/^(?:GROUP|FILE) "[^"]+" does not exist/sm
and last;
return;
}
lib/Astro/SpaceTrack.pm view on Meta::CPAN
# attribute. Individual accumulators are at liberty to
# ignore this.
#
# The return is a code reference. This reference is intended to be
# called as
# $accumulator->( $self, $resp )
# for each successful HTTP response. After all responses have been
# processed, the accumulated data are retrieved using
# ( $content, $data ) = $accumulator( $self )
# The first return is the text representation of the accumulated
# data. The second is the decoded data, and is returned at the
# accumulator's option. In scalar context only $content is returned.
sub _accumulator_for {
my ( $format, $opt ) = @_;
my $name = $format_map{$format} || $format;
my $accumulator = __PACKAGE__->can( "_accumulate_${name}_data" )
|| \&_accumulate_unknown_data;
my $returner = __PACKAGE__->can( "_accumulate_${name}_return" )
|| sub {
my ( undef, $context ) = @_;
lib/Astro/SpaceTrack.pm view on Meta::CPAN
}
# The data accumulators. The conventions which must be followed are
# that, given a format named 'fmt':
#
# 1) There MUST be an accumulator named _accumulate_fmt_data(). Its
# arguments are the invocant, the content of the return, and the
# context hash. It must accumulate data in $context->{data}, in any
# format it likes.
# 2) If _accumulate_fmt_data() decodes the data, it SHOULD return a
# reference to the decoded array. Otherwise it MUST return nothing.
# 3) There MAY be a returner named _accumulate_fmt_return(). If it
# exists its arguments are the invocant and the context hash. It MUST
# return a valid representation of the accumulated data in the
# desired format.
# 4) If _accumulate_fmt_return() does not exist, the return will be the
# contents of $context->{data}, which MUST have been maintained by
# _accumulate_fmt_data() as a valid representation of the data in the
# desired format.
# 5) Note that if _accumulate_fmt_return() exists,
# _accumulate_fmt_data need not maintain $context->{data} as a valid
( run in 1.004 second using v1.01-cache-2.11-cpan-26ccb49234f )