Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
FreshBooks API wrapper
Ruby
branch: master

This branch is 12 commits ahead, 90 commits behind bcurren:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
script
test
.gitignore
History.txt
LICENSE
Manifest.txt
README
Rakefile
freshbooks.rb.gemspec

README

= About

Freshbooks.rb is a Ruby interface to the Freshbooks API. It exposes easy-to-use classes and methods for interacting with your Freshbooks account. Read more on ELC's blog:
http://elctech.com/tags/freshbooks

= Examples

Installation:
  gem install elc-freshbooks.rb --source http://gems.github.com

Initialization:

  Freshbooks::Base.establish_connection( 'sample.freshbooks.com', 'mytoken' )

Updating a client name:

  clients = Freshbooks::Client.list
  client = clients[0]
  client.first_name = 'Suzy'
  client.update

Updating an invoice:

  invoice = Freshbooks::Invoice.get(4)
  invoice.lines[0].quantity += 1
  invoice.update

Creating a new item

  item = Freshbooks::Item.new
  item.name = 'A sample item'
  item.create

Getting an invoice pdf:

  invoice = Freshbooks::Invoice.get(4)
  original_status = invoice.status
  invoice.status = "sent"
  raise "API Change or error" unless invoice.update
  html_url = invoice.client_view
  cookiejar = Tempfile.new("cookies")
  pdf_file = Tempfile.new("pdf")
  html_doc = `wget "#{html_url}"  --no-check-certificate --cookies=on --keep-session-cookies --save-cookies='#{cookiejar.path}'  -O -`
  `wget 'https://#{freshbooks_api_host}/getPDF.php' --post-data='invoice_id[]=#{invoice.number}' --cookies=on --keep-session-cookies 
    --load-cookies='#{cookiejar.path}'  --no-check-certificate -O '#{pdf_file.path}'"`
  invoice.status = original_status
  raise "API Change or error" unless invoice.update
  pdf_file.path # Here's the PDF!

= License

This work is distributed under the MIT License. Use/modify the code however you like.

= Download

Freshbooks.rb is distributed as a gem via Rubyforge. The easiest way to install it is like so:

  gem install freshbooks

Alternatively, you can download it from the Rubyforge project page.

= Credits

Freshbooks.rb is written and maintained by Ben Vinegar, with contributions from Flinn Meuller, Kenneth Kalmer, and others. 

Something went wrong with that request. Please try again.