A collection of release tools used for Koha
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

89 lines
2.1 KiB

package Koha::BZ;
use Moose;
use Modern::Perl;
use JSON;
use YAML;
use REST::Client;
use URI::Escape qw( uri_escape );
has client => (is => 'rw', isa => 'REST::Client');
has url => (is => 'rw', isa => 'Str');
has login => (is => 'rw', isa => 'Str');
has password => (is => 'rw', isa => 'Str');
has token => (is => 'rw', isa => 'Str');
sub get {
my ($self, $cmd) = @_;
my $url = $self->url . "/rest/$cmd";
$url .= '&token=' . $self->token if $self->token;
$self->client->GET($url);
decode_json($self->client->responseContent());
}
sub put {
my ($self, $cmd, $data) = @_;
my $url = $self->url . "/rest/$cmd";
$url .= ($url =~ /\?/ ? '&' : '?') . 'token=' . $self->token;
$data = encode_json($data);
#say "putting to $url";
#say "putting with $data";
$self->client->PUT(
$url,
$data,
{
'Content-Type' => 'application/json',
'Accept' => 'application/json',
}
);
my $response = decode_json $self->client->responseContent();
if ( exists($response->{error}) ) {
say Dump($response) if exists($response->{error});
exit;
}
}
sub post_comment {
my ($self, $bug, $data) = @_;
my $url = $self->url . "/rest/bug/$bug/comment";
$url .= ($url =~ /\?/ ? '&' : '?') . 'token=' . $self->token;
$data = encode_json($data);
#say "putting to $url";
#say "putting with $data";
$self->client->POST(
$url,
$data,
{
'Content-Type' => 'application/json',
'Accept' => 'application/json',
}
);
my $response = decode_json $self->client->responseContent();
if ( exists($response->{error}) ) {
say Dump($response) if exists($response->{error});
exit;
}
}
sub BUILD {
my $self = shift;
$self->client( REST::Client->new() );
if ( $self->login ) {
my $response = $self->get('login?login=' . uri_escape($self->login) . "&password=" . uri_escape($self->password));
if ( $response->{error} ) {
say "Wrong login/password to BZ";
exit 1;
}
$self->token($response->{token});
}
}
1;