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.


In reply to Problem with Moose Dispatching Requests by three18ti

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.