Skip to content

Instantly share code, notes, and snippets.

@globau
Created February 4, 2014 04:59
Show Gist options
  • Save globau/8798382 to your computer and use it in GitHub Desktop.
Save globau/8798382 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/.
# See https://bugzilla.mozilla.org/show_bug.cgi?id=793784
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 = bugzilla(
'User.login', {
login => USERNAME,
password => PASSWORD,
remember => 1,
});
my $content = "hello world.\n";
$result = bugzilla(
'Bug.add_attachment', {
ids => [ 770 ],
data => XMLRPC::Data->type('base64', $content),
file_name => 'hello_world.txt',
summary => 'hello world',
content_type => 'text/plain',
});
print Dumper($result);
#
# helpers
#
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