RSS feed
FreshBooks API Guide

FreshBooks API Blog



FreshBooks, Ruby, and Rack

By Ben - July 9/2007 (Add Comment)

If you’re a Ruby or Rails developer looking to get started with the FreshBooks API, I recommend taking a look at the latest sample code we’ve put together: invoice_getter.rb.

It uses FreshBooks.rb, a Ruby wrapper I’ve written, to fetch a particular invoice’s details and render it as HTML. A call to invoice.list populates a select box letting you choose from your last 25 invoices. It might be a useful starting point for businesses that want to customize and style their invoice formats.

For fun, I’ve coded invoice_getter.rb using Rack, the modular web server interface, so it can be either launched traditionally using Apache/CGI, or using Ruby’s WEBrick server. As a Rails enthusiast, I love working with WEBrick – you can quickly launch and re-start your app from the command-line, skipping the messiness of an Apache conf file.

If you’ve already got Ruby and RubyGems installed, you can quickly install Rack and launch invoice_getter.rb like so:

# gem install rack -–include-dependencies
...
Successfully installed rack-0.2.0
Installing ri documentation for rack-0.2.0…
Installing RDoc documentation for rack-0.2.0

# ruby invoice_getter.rb
[2007-07-09 10:50:34] INFO WEBrick 1.3.1
[2007-07-09 10:50:34] INFO ruby 1.8.6 (2007-03-13) [i386-mswin32]
[2007-07-09 10:50:34] INFO WEBrick::HTTPServer#start: pid =3944, port=3000

Now, fire up your web browser to http://localhost:3000 and you’re good to go.

In case you missed the link above, you can download the sample code here.

 

Leave a comment
*
* (not published)

*
* required