Select Git revision
API.pm
API.pm 6.69 KiB
package RedMiner::API;
use 5.010;
use strict;
use warnings;
our $VERSION = '0.03';
use URI;
use URI::QueryParam;
use LWP::UserAgent;
use JSON::XS qw/encode_json decode_json/;
use Encode qw/decode/;
=pod
=encoding UTF-8
=head1 NAME
RedMiner::API - Wrapper for RedMine REST API (http://www.redmine.org/projects/redmine/wiki/Rest_api).
=head1 SYNOPSIS
use RedMiner::API;
=head1 DESCRIPTION
Stub documentation for RedMiner::API, created by h2xs. It looks like the
author of the extension was negligent enough to leave the stub
unedited.
=head2 EXPORT
None.
=cut
sub new
{
my $class = shift;
my %arg = @_;
my $self = {
error => '',
protocol => $arg{protocol} // 'http',
ua => LWP::UserAgent->new,
};
foreach my $param (qw/host user pass key/) {
$self->{$param} = $arg{$param} // '';
}
if (length $self->{host} && $self->{host} =~ m|^(https?)://|i) {
$self->{protocol} = lc $1;
$self->{host} =~ s/^https?://i;
} else {
$self->{protocol} = 'http' if $self->{protocol} !~ /^https?$/i;
}
my $auth = '';
if (!length $self->{key} && length $self->{user}) {
$auth = $self->{user};
if (length $self->{pass}) {
$auth .= ':' . $self->{pass};
}
$auth .= '@';
}
$self->{uri} = "$self->{protocol}://$auth$self->{host}";