API-Drip-Request
view release on metacpan or search on metacpan
'YAML' => 0,
},
add_to_cleanup => ['API-Drip-*'],
meta_merge => {
'meta-spec' => { version => '2',
url => 'https://metacpan.org/pod/CPAN::Meta::Spec',
},
resources => { bugtracker => { web => 'https://github.com/dwright/API-Drip/issues', },
repository => { url => 'https://github.com/dwright/API-Drip.git',
web => 'https://github.com/dwright/API-Drip',
type => 'git',
}
},
}, );
$builder->create_build_script();
"file" : "lib/API/Drip/Request.pm",
"version" : "0.05"
}
},
"release_status" : "stable",
"resources" : {
"bugtracker" : {
"web" : "https://github.com/dwright/API-Drip/issues"
},
"repository" : {
"type" : "git",
"url" : "https://github.com/dwright/API-Drip.git",
"web" : "https://github.com/dwright/API-Drip"
}
},
"version" : "0.05",
"x_serialization_backend" : "JSON::PP version 2.27300"
}
lib/API/Drip/Request.pm view on Meta::CPAN
A codref that should accept a list of diagnostic strings and log them somewhere
useful for debugging purposes. Only used when DRIP_DEBUG is true.
=back
=cut
my $config_validator = validation_for(
params => {
DRIP_CLIENT_CONF => { type => Str(), optional => 1 },
map { $_ => { type => Str(), optional => 1 } } keys %DEFAULTS,
debugger => { type => CodeRef(), optional => 1 },
}
);
sub new {
my $class = shift;
my %OPT = $config_validator->(@_);
my $self = _load_conf( \%OPT );
# At this point, all configuration values should be set
lib/API/Drip/Request.pm view on Meta::CPAN
=back
On success, returns a Perl data structure corresponding to the data returned
from the server. Some operations (DELETE), do not return any data and may
return undef on success. On error, this method will die() with the
HTTP::Response object.
=cut
my $request_validator = validation_for( params => [ {type => Str()}, {type => Str()}, {type => HashRef(), optional => 1} ] );
sub do_request {
my $self = shift;
my ($method, $endpoint, $content) = $request_validator->(@_);
my $uri = URI->new($self->{DRIP_URI});
$uri->path_segments( $uri->path_segments, $self->{DRIP_ID}, split( '/', $endpoint) );
$self->{debugger}->( 'Requesting: ' . $uri->as_string );
my $request = HTTP::Request->new( $method => $uri->as_string, );
if ( ref($content) ) {
$request->content_type('application/vnd.api+json');
$request->content( encode_json( $content ) );
}
$request->authorization_basic( $self->{DRIP_TOKEN}, '' );
$self->{agent} //= LWP::UserAgent->new( agent => $self->{DRIP_AGENT} );
my $result = $self->{agent}->request( $request );
unless ( $result->is_success ) {
$self->{debugger}->("Request failed", $result->content);
die $result;
( run in 3.219 seconds using v1.01-cache-2.11-cpan-df04353d9ac )