Astro-SpaceTrack
view release on metacpan or search on metacpan
lib/Astro/SpaceTrack.pm view on Meta::CPAN
# ).
{
my $strip = qr{ [=:|!+] .* }smx;
sub _extract_keys {
my ( $lgl_opts ) = @_;
if ( ARRAY_REF eq ref $lgl_opts ) {
my $len = @{ $lgl_opts };
my @rslt;
for ( my $inx = 0; $inx < $len; $inx += 2 ) {
( my $key = $lgl_opts->[$inx] ) =~ s/ $strip //smxo;
push @rslt, $key, 1;
}
return @rslt;
} else {
$lgl_opts =~ s/ $strip //smxo;
return $lgl_opts;
}
}
}
# The following are data transform routines for _search_rest().
# The arguments are the datum and the class for which it is being
# formatted.
# Parse an international launch id, and format it for a Space-Track REST
# query. The parsing is done by _parse_international_id(). The
# formatting prefixes the 'contains' wildcard '~~' unless year, sequence
# and part are all present.
sub _format_international_id_rest {
my ( $intl_id ) = @_;
my @parts = _parse_international_id( $intl_id );
@parts >= 3
and return sprintf '%04d-%03d%s', @parts;
@parts >= 2
and return sprintf '~~%04d-%03d', @parts;
return sprintf '~~%04d-', $parts[0];
}
# Parse a launch date, and format it for a Space-Track REST query. The
# parsing is done by _parse_launch_date(). The formatting prefixes the
# 'contains' wildcard '~~' unless year, month, and day are all present.
sub _format_launch_date_rest {
my ( $date ) = @_;
my @parts = _parse_launch_date( $date )
or return;
@parts >= 3
and return sprintf '%04d-%02d-%02d', @parts;
@parts >= 2
and return sprintf '~~%04d-%02d', @parts;
return sprintf '~~%04d', $parts[0];
}
# Note: If we have a bad cookie, we get a success status, with
# the text
# <?xml version="1.0" encoding="iso-8859-1"?>
# <!DOCTYPE html
# PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
# "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
# <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US"><head><title>Space-Track</title>
# </head><body>
# <body bgcolor='#fffacd' text='#191970' link='#3333e6'>
# <div align='center'><img src='http://www.space-track.org/icons/spacetrack_logo3.jpg' width=640 height=128 align='top' border=0></div>
# <h2>Error, Corrupted session cookie<br>
# Please <A HREF='login.pl'>LOGIN</A> again.<br>
# </h2>
# </body></html>
# If this happens, it would be good to retry the login.
sub _get_agent {
my ( $self ) = @_;
$self->{agent}
and return $self->{agent};
my $agent = $self->{agent} = LWP::UserAgent->new(
ssl_opts => {
verify_hostname => $self->getv( 'verify_hostname' ),
},
);
$agent->env_proxy();
$agent->cookie_jar()
or $agent->cookie_jar( {} );
return $agent;
}
# $resp = $self->_get_from_net( name => value ... )
#
# This private method retrieves a URL and returns the response object.
# The optional name/value pairs are:
#
# catalog => catalog_name
# If this exists, it is the name of the catalog to retrieve. An
# error is returned if it is not defined, or if the catalog does
# not exist.
# file => cache_file_name
# If this is defined, the data are returned only if it has been
# modified since the modification date of the file. If the data
# have been modified, the cache file is refreshed; otherwise the
# response is loaded from the cache file.
# method => method_name
# If this is defined, it is the name of the method doing the
# catalog lookup. This is unused unless 'catalog' is defined, and
# defaults to the name of the calling method.
# post_process => code reference
# If the network operation succeeded and this is defined, it is
# called and passed the invocant, the HTTP::Response object, and
# a reference to the catalog information hash (or to an empty hash
# if 'url' was specified). The HTTP::Response object returned
# (which may or may not be the one passed in) is the basis for any
# further processing.
# spacetrack_source => spacetrack_source
# If this is defined, the corresponding-named pragma is set. The
# default comes from the same-named key in the catalog info if that
# is defined, or the 'method' argument (as defaulted).
# spacetrack_type => spacetrack_type
# If this is defined, the corresponding-named pragma is set.
( run in 0.885 second using v1.01-cache-2.11-cpan-39bf76dae61 )