| WebService-FogBugz documentation | Contained in the WebService-FogBugz distribution. |
WebService::FogBugz - Perl interface to the FogBugz API
use WebService::FogBugz;
my $fogbugz = WebService::FogBugz->new({
email => 'yourmail@example.com',
password => 'yourpassword',
base_url => 'http://yourfogbugz.example.com/api.asp',
});
$fogbugz->logon;
# your request.
my $xml = $fogbugz->request_method('search', {
q => 'WebService',
});
$fogbugz->logoff;
This module provides you Perl interface for FogBugz API. FogBugz is a project management system.
the 2nd argument is parameters of command of 1st argument.
Please report any bugs or feature requests to
bug-webservice-fogbugz@rt.cpan.org, or through the web interface at
http://rt.cpan.org.
You can find documentation for this module with the perldoc command.
perldoc WebService::FogBugz
You can also look for information at:
http://www.fogcreek.com/FogBugz/docs/60/topics/advanced/API.html
Takatsugu Shigeta <takatsugu.shigeta@gmail.com>
Copyright (c) 2007, Takatsugu Shigeta <takatsugu.shigeta@gmail.com>. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
| WebService-FogBugz documentation | Contained in the WebService-FogBugz distribution. |
package WebService::FogBugz; use warnings; use strict; use LWP::UserAgent; use XML::Liberal; use XML::LibXML; our $VERSION = '0.0.4'; sub new { my $class = shift; my ($param) = @_; die 'you need to input email, password and base url.' unless $param->{email} and $param->{password} and $param->{base_url}; my $self = bless {%$param}, $class; $self->{ua} = $param->{ua} || LWP::UserAgent->new; $self->{ua}->agent(__PACKAGE__.'/'.$VERSION); $self->{parser} = XML::Liberal->new('LibXML'); return $self; } sub logon { my $self = shift; my $res = $self->{ua}->get($self->{base_url} . '?cmd=logon' . '&email=' . $self->{email} . '&password=' . $self->{password}); if ($self->_is_error($res->content)) { return; } my $doc = $self->{parser}->parse_string($res->content); $self->{token} = $doc->findvalue("//*[local-name()='response']/*[local-name()='token']/text()"); return $self->{token}; } sub logoff { my $self = shift; my $res = $self->{ua}->get($self->{base_url} . '?cmd=logoff' . '&token=' . $self->{token}); if ($self->_is_error($res->content)) { return; } delete $self->{token}; return; } sub request_method { my $self = shift; my ($cmd, $param) = @_; my $query = join('', map {'&' . $_ . '=' . $param->{$_}} keys(%$param)); my $res = $self->{ua}->get($self->{base_url} . '?cmd=' . $cmd . '&token=' . $self->{token} . $query); if ($self->_is_error($res->content)) { return; } return $res->content; } sub _is_error { my $self = shift; my ($content) = @_; $content =~ s/<\?xml\s+.*?\?>//g; my $doc = $self->{parser}->parse_string($content); $self->{error}{code} = $doc->findvalue("//*[local-name()='response']/*[local-name()='error']/\@code"); $self->{error}{msg} = $doc->findvalue("//*[local-name()='response']/*[local-name()='error']/text()"); return $self->{error}{code} ? '1' : '0'; } 1; __END__