Skip to content

jnarowski/freshbooks.rb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

= 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. 

Releases

No releases published

Packages

No packages published