Bintray-API
view release on metacpan or search on metacpan
lib/Bintray/API/Session.pm view on Meta::CPAN
use strict;
use warnings FATAL => 'all';
use Carp qw(croak carp);
#######################
# VERSION
#######################
our $VERSION = '1.0.2';
#######################
# LOAD CPAN MODULES
#######################
use JSON::Any;
use Encode qw();
use HTTP::Tiny qw();
use URI::Encode qw();
use MIME::Base64 qw(encode_base64);
use Params::Validate qw(validate_with :types);
use Object::Tiny qw(
json
debug
apikey
apiurl
error
client
limits
hascreds
username
urlencoder
);
#######################
# PUBLIC METHODS
#######################
## Constructor
sub new {
my ( $class, @args ) = @_;
my %opts = validate_with(
params => [@args],
spec => {
username => {
type => SCALAR,
default => '',
},
apikey => {
type => SCALAR,
default => '',
},
debug => {
type => BOOLEAN,
default => 0,
},
},
);
# Set API URL
$opts{apiurl} = 'https://bintray.com/api/v1';
# Check for credentials
if ( $opts{username} and $opts{apikey} ) {
$opts{hascreds} = 1;
}
# Init HTTP Client
$opts{client} = HTTP::Tiny->new(
agent => 'perl-bintray-api-client',
default_headers => {
'Accept' => 'application/json',
'Content-Type' => 'application/json',
# Save Credentials for Basic Auth
(
$opts{hascreds}
? (
'Authorization' => sprintf(
'%s %s', 'Basic',
encode_base64(
join( ':', $opts{username}, $opts{apikey} ), ''
),
),
)
: ()
),
},
);
# Init Encoder
$opts{urlencoder} = URI::Encode->new();
# Init JSON
$opts{json} = JSON::Any->new(
utf8 => 1,
);
# Init Empty error
$opts{error} = '';
# Return Object (tiny)
return $class->SUPER::new(%opts);
} ## end sub new
## Talk
sub talk {
my ( $self, @args ) = @_;
my %opts = validate_with(
params => [@args],
spec => {
method => {
type => SCALAR,
default => 'GET',
},
path => {
type => SCALAR,
},
query => {
type => ARRAYREF,
default => [],
},
params => {
( run in 0.781 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )