WWW::FreshBooks::API - Perl Interface to the Freshbooks 2.1 API!
Version 0.1.0
use WWW::FreshBooks::API; my $fb = WWW::FreshBooks::API->new({ svc_url => "https://sample.freshbooks.com/api/xml-in", auth_token => "yourfreshbooksapiauthenticationtoken", }); # old n' busted - though still works for backward compatibility # --------------------------------------------------------------- # $ref is a hash reference created from the xml response. # $resp is an HTTP::Response object containg the response. my ($ref,$resp) = $fb->call('client.list', { $arg1 => 'val1', $arg2 => 'val2', }); # Verifies that the request was completed successfully. # Displays the client_id of the first client in the list. if ($ref) { $ref->{'client'}[0]->{'client_id'}; } # Displays the response content as a string $resp->as_string; # --------------------------------------------------------------- # new hotness - better data handling, easier access to response data, etc. # ---------------------------------------------------------------- # result and response data now accessed via class accessors. $fb->call("client.list", {foo => "bar", biz => "baz"}); my $response = $fb->response; unless ($response->status eq "ok") { return; } my $results = $fb->results; $results->total; # Total number of result items $results->items; # array of results as result item classes $results->item_fields; # hash of result item field names keyed by class - used to create item class accessors $results->item_class; # name of the class created from the result items $results->iterator; # iterator for list of result items my $items = $results->iterator; my $fields = $results->item_fields->{$results->item_class}; while (my $item = $items->next()) { $item->client_id; $item->organization; # or something like .. map { print $_ . " --> " . $item->$_ . "\n" } @{$fields}; } # -----------------------------------------------------------------
The long awaited update to the original perl freshbooks api interface adds some much needed data handling improvements, on-the-fly response item class creation, and a simple result item iterator for improved handling of result lists. Stubs of the original implementation exist for backwards compatibility, and access to new features are possible without changing old code.
The result item classes are built on the fly using the data contained within the response. This is meant to keep class accessors up to date in the absence of a provided service description and without having to maintain your own. Example of how this works:
# your "client.list" request returns: <?xml version="1.0" encoding="utf-8"?> <response status="ok"> <clients page="1" per_page="15" pages="3" total="42"> <client> <client_id>13</client_id> <organization>ABC Corp</organization> <username>janedoe</username> <first_name>Jane</first_name> <last_name>Doe</last_name> <email>janedoe@freshbooks.com</email> </client> ... </clients> </response> # on the fly we create WWW::FreshBooks::API::Client with accessors available via: my $item = $results->iterator->next(); $item->client_id; # 13 $item->organization; # ABC Corp $item->username; # janedoe ....
Please note that "item" refers to each object returned in the list of results. This is not to be confused with a Freshbooks line item. I realize that this is a bit semantically unsound, but I have to point the finger at the FB kats for this one. I mean "item" is pretty vague for a top level api, no? My vocab-fu is not strong ... plus, by the time I noticed the collision, I was married to the item reference.
new
init
call
$response-
$results-
Class::Accessor::Children Iterator::Simple LWP::UserAgent XML::Simple
Anthony Decena, <anthony at mindelusions.com>
<anthony at mindelusions.com>
Please report any bugs or feature requests to bug-www-freshbooks-api at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-FreshBooks-API. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-www-freshbooks-api at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc WWW::FreshBooks::API
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-FreshBooks-API
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/WWW-FreshBooks-API
CPAN Ratings
http://cpanratings.perl.org/d/WWW-FreshBooks-API
Search CPAN
http://search.cpan.org/dist/WWW-FreshBooks-API/
Copyright 2009 Anthony Decena, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install WWW::FreshBooks::API, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::FreshBooks::API
CPAN shell
perl -MCPAN -e shell install WWW::FreshBooks::API
For more information on module installation, please visit the detailed CPAN module installation guide.