three18ti has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
Long time listener, first time caller.
I'm working on a perl module (https://github.com/three18ti/kayako3-staffapi) to wrap the Kayako Help Desk API (http://wiki.kayako.com/display/DEV/Kayako+Staff+API) in an easy to use Perl Module.
Everything seems to work ok with the initialization and login in, however, I am having trouble when loading tickets.
Essentially, what I have done is created a method to dispatch the API call, then I have another method that parses the XML response, builds a Moose object, and sticks the Moose Object in one of the Parent Objects members.
Everything seems to work when the first ticket is loaded (or when the ticket list is loaded), however, every subsequent request never dispatches the API call, therefore returning the information from the first API call.
What follows is an excerpt from https://github.com/three18ti/kayako3-staffapi/blob/master/lib/Kayako3/StaffAPI.pm to illustrate how I am performing my calls. Any suggestions on this specific problem or the module in general are greatly appreciated.
=head2 get_ticket_list User function to get ticket list, requres department and status =cut =head2 ticket_list_respnse ticket list response object Object storage for Kayako3::StaffAPI::Response::TicketList Stores the XML response from $self->_do_ticket_list as a Moose Object =cut has 'ticket_list_response' => ( is => 'rw', isa => 'Kayako3::StaffAPI::Response::TicketList::Kayako_staffapi', lazy => 1, builder => '_do_ticket_list', handles => qr/^(?:_.*|ticket_list|get.*)/, ); =head2 _ticket_list_request_parameters Parameters set prior to calling $self->get_ticket_list to enable correct parameters are passed to function * I believe this is part of the problem =cut has '_ticket_list_request_parameters' => ( is => 'rw', isa => 'HashRef', lazy => 1, # trigger => \&_do_ticket_list, default => sub { {} }, ); =head2 get_ticket_list User function to get ticket list, requres department and status =cut sub get_ticket_list { my $self = shift; my $department = shift; my $status = shift; my ($department_id, $status_id) = ($department, $status); $self->_ticket_list_request_parameters( { sessionid => $self->_session_id, departmentid => $department_id, } ); $self->_ticket_list_request_parameters->{statusid} = $status_id if $status_id; } =head2 _do_ticket_list Performs the parsing of XML and initialization of "Ticket List Response" Object =cut sub _do_ticket_list { my $self = shift; # loads options from $self->_ticket_list_request_parameters my $response = $self->_get_ticket_list; my $unzipped_content = $self->_unzip($response->content); my $loader = XML::Toolkit::App->new( xmlns => { '' => 'Kayako3::StaffAPI::Response::TicketList' } )->loader; $loader->parse_string( $unzipped_content ); shift $loader->filter->objects; } =head2 _get_ticket_list Performs the _get_ticket_list API call =cut sub _get_ticket_list { my $self = shift; my $response = $self->ua->post( $self->_api_ticket_list, $self->_ticket_list_request_parameters, ); }
As you can see, what I am attempting to do is provide an interface for the user to pass parameters, then once those parameters are set, the _do_ticket_list function should be called, and return the results of _do_ticket_list results to the ticket_list_response member. Again, everything works the first time around, but every subsequent call does not trigger _do_ticket_list since the ticket_list_response member has already been built. Would un-setting ticket_list_response (or setting it equal to null... well, that would likely cause a Moose error as NULL wouldn't match the type definition.) do the trick, or is there something else that I'm overlooking?
Also, if you have any suggestions to the overall format of the module, please do let me know.
Thanks in advance.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Moose Troubles
by moritz (Cardinal) on May 27, 2012 at 19:36 UTC | |
by three18ti (Monk) on May 27, 2012 at 21:07 UTC | |
by CountZero (Bishop) on May 28, 2012 at 07:29 UTC | |
by moritz (Cardinal) on May 28, 2012 at 08:07 UTC | |
Re: Moose Troubles
by Anonymous Monk on May 27, 2012 at 19:58 UTC | |
by three18ti (Monk) on May 27, 2012 at 21:20 UTC |