API-Drip-Request
view release on metacpan or search on metacpan
lib/API/Drip/Request.pm view on Meta::CPAN
$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;
}
if ( $result->code == 204 ) {
$self->{debugger}->("Success, no content");
return undef;
}
my $decoded = eval {decode_json( $result->content )};
if ( $@ ) {
$self->{debugger}->('Failed to decode JSON:', $@, $result->content);
die $result;
}
return $decoded;
}
=head1 CONFIGURATION
Configuration data may be passed in through a number of different ways, which are searched in the following order of preference:
=over
=item 1. As direct paramteters to new().
=item 2. As environment variables.
=item 3. As elments of the first YAML configuration file that is found and readable in the following locations:
=over
=item 1. The location specified by the DRIP_CLIENT_CONF parameter supplied to new().
=item 2. The location specified by $ENV{DRIP_CLIENT_CONF}.
=item 3. $ENV{HOME}/.drip.conf
=back
=back
The following configuration data is accepted:
=over
=item * DRIP_TOKEN (required)
This is the user token assigned to you by drip. When you are logged in, look for "API Token" at https://www.getdrip.com/user/edit
=item * DRIP_ID (required)
This is the numeric user id assigned to you by drip. When logged in, find it in your settings under Account->General Info.
=item * DRIP_URI (optional)
This defaults to https://api.getdrip.com/v2. You probably shouldn't change this.
=item * DRIP_AGENT (optional)
Defaults to "API::Drip". Specifies the HTTP Agent header.
=item * DRIP_DEBUG (optional)
Defaults to 0. Set to a true value to enable debugging.
=cut
sub _load_conf {
my $OPT = shift();
my $conf = {};
KEY:
foreach my $key ( keys %DEFAULTS ) {
next KEY if defined $OPT->{$key};
if ( defined $ENV{$key} ) { $conf->{$key} = $ENV{$key}; next KEY; }
state $YAML_CONF //= _load_yaml_conf( $OPT );
if ( defined $YAML_CONF->{$key} ) { $conf->{$key} = $YAML_CONF->{$key}; next KEY; }
$conf->{$key} = $DEFAULTS{$key};
}
return $conf;
}
sub _load_yaml_conf {
my $OPT = shift();
FILE:
foreach my $location( $OPT->{DRIP_CLIENT_CONF}, $ENV{DRIP_CLIENT_CONF}, File::Spec->catfile( File::HomeDir->my_home, '.drip.conf' )) {
no warnings 'uninitialized';
next FILE unless -f $location && -r _;
return YAML::LoadFile $location;
}
}
=head1 AUTHOR
Dan Wright, C<< <Dan at DWright.Org> >>
=head1 BUGS
Please report bugs as an issue via GitHub L<https://github.com/dwright/API-Drip/issues>.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc API::Drip::Request
You can also look for information at:
=over 4
=item * Github repository (please report bugs here)
( run in 1.672 second using v1.01-cache-2.11-cpan-39bf76dae61 )