Skip to content

Instantly share code, notes, and snippets.

@globau
Last active August 29, 2015 13:55
Show Gist options
  • Save globau/8703296 to your computer and use it in GitHub Desktop.
Save globau/8703296 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use strict;
use warnings;
use HTTP::Cookies;
use SOAP::Lite
+trace => [ transport => sub { print $_[0]->as_string, "\n" } ];
use XMLRPC::Lite;
use Data::Dumper;
$Data::Dumper::Terse = 1;
$Data::Dumper::Sortkeys = 1;
use constant USERNAME => 'glob@example.com';
use constant PASSWORD => 'password';
use constant URL_BASE => 'http://bugzilla.example.com'; # url without trailing /
my ($result, $id);
$result = bugzilla(
'User.login', {
login => USERNAME,
password => PASSWORD,
remember => 1,
});
print Dumper($result);
my $_bugzilla;
sub bugzilla {
my ($method, $params) = @_;
my $soapresult;
eval {
$_bugzilla ||= XMLRPC::Lite->proxy(
URL_BASE . '/xmlrpc.cgi',
'cookie_jar' => HTTP::Cookies->new);
$soapresult = $_bugzilla->call($method, $params);
if ($soapresult->fault) {
my ($package, $filename, $line) = caller;
die $soapresult->faultcode . ' ' . $soapresult->faultstring .
" in SOAP call near $filename line $line.\n";
}
};
if ($@) {
print $@;
exit;
}
return $soapresult->result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment