[Rt-commit] [svn] r803 - in RT-Client: . lib/RT
autrijus at pallas.eruditorum.org
autrijus at pallas.eruditorum.org
Sun May 2 11:23:40 EDT 2004
Author: autrijus
Date: Sun May 2 11:23:40 2004
New Revision: 803
Modified:
RT-Client/ (props changed)
RT-Client/lib/RT/Client.pm
Log:
----------------------------------------------------------------------
r4377 at not: autrijus | 2004-05-02T15:23:42.633674Z
* Allow use of $rt->path() to override the default '/REST/2.0' path.
* ->new() can now take a single URL string for user, pass, server and path.
* Correctly specify the HTTP 'Accept' header.
----------------------------------------------------------------------
Modified: RT-Client/lib/RT/Client.pm
==============================================================================
--- RT-Client/lib/RT/Client.pm (original)
+++ RT-Client/lib/RT/Client.pm Sun May 2 11:23:40 2004
@@ -12,7 +12,6 @@
use XML::Atom::Client;
use Digest::MD5 qw( md5_hex );
-use constant BASE_URI => 'REST/2.0';
=head1 NAME
@@ -22,22 +21,18 @@
use RT::Client;
- my $rt = RT::Client->new(
- Username => 'root',
- Password => 'password',
- Server => 'http://localhost',
- );
+ my $rt = RT::Client->new('http://root@password:localhost');
# search / list
my $tickets = $rt->search(
URI => 'tickets',
- Limit => "Priority > 5 and Status='new'",
+ Query => "Priority > 5 and Status='new'",
OrderBy => 'Subject',
Order => 'DESC',
);
# narrow search scope
- $tickets->search(Limit => "Owner='autrijus'");
+ $tickets->search(Query => "Owner='autrijus'");
# perform actions
$tickets->delete(); # perform action
@@ -93,12 +88,24 @@
}
sub new {
- my ($class, %args) = @_;
+ my $class = shift;
+ unshift @_, 'URI' if @_ == 1;
+
+ my %args = @_;
+ if (my $uri = delete $args{URI}) {
+ require URI;
+ $uri = URI->new($uri);
+ @args{'Username', 'Password'} = split(/:/, $uri->userinfo||'', 2);
+ $args{Server} = $uri->scheme . '://' .$uri->host_port;
+ $args{Path} = ($uri->path =~ m{^/+$}) ? $uri->path : '';
+ }
+
my $self = $class->SUPER::new(%args);
$self->username($args{Username}) if defined $args{Username};
$self->password($args{Password}) if defined $args{Password};
$self->server($args{Server}) if defined $args{Server};
+ $self->path($args{Path}) if defined $args{Path};
return $self;
}
@@ -124,6 +131,12 @@
return md5_hex(join(':', $username, $realm, md5_hex($self->{password})));
}
+sub path {
+ my $self = shift;
+ $self->{path} = shift if @_;
+ return $self->{path} || '/REST/2.0';
+}
+
sub realm {
my $self = shift;
$self->{realm} = shift if @_;
@@ -141,7 +154,7 @@
sub server_uri {
my $self = shift;
- return join('/', $self->server, $self->BASE_URI, @_ ? @_ : '');
+ return join('/', $self->server . $self->path, @_ ? @_ : '');
}
sub server_realm {
@@ -157,4 +170,16 @@
return $1;
}
+sub munge_request {
+ my ($self, $req) = @_;
+ $req->header(
+ Accept => 'application/x.atom+xml, application/xml, text/xml',
+ );
+ return $self->SUPER::munge_request($req);
+}
+
1;
+
+# my $rt = RT::Client->new('http://root:password@localhost/');
+# print $rt->search('templates')->as_xml;
+
More information about the Rt-commit
mailing list