For who does not know freshbooks, it is an online service for sending invoices and tracking time. You can access this service either through its web-interface or through its exposed APIs. It is not free, but you can create a test account and try it. I used it while working in project at eSpace company.
To access your freshbooks account through the APIs, you need first to enable its APIs and use the given URL and authentication token in your API connection. You will notice that freshbooks APIs have different versions and they distinguish between them using the API access URL, e.g. for API version 2.1 (latest one at post time), your URL will be "https://espacetest.freshbooks.com/api/2.1/xml-in"
You can access freshbooks APIs from inside Ruby on Rails project either directly through http connections or using a Ruby wrapper freshbooks.rb. To install it:
gem install freshbooks
The latest version of this gem (at post time) is freshbooks-2.2. This version contains a small issue regarding API version number. When using this library, you need to pass both your freshbooks account simple URL (espacetest.freshbooks.com) and authentication token.
FreshBooks.setup(@freshbooks_url, @freshbooks_token)
Then, library code concatenates the rest of the URL. Look at this code lines taken from freshbooks.rb:
Line 35: VERSION = '2.2' # Only works with 2.1
Line 37: SERVICE_URL = "/api/#{VERSION}/xml-in"
You will notice that the version number is "2.2" and this variable "VERSION" is used in the API url. But, no API version 2.2 yet!!
So, if you used this gem as it you will get error from freshbooks API saying "Invalid API version.". All you need to do is replacing this value with "2.1"
Line 35: VERSION = '2.1' # Only works with 2.1:
Line 37: SERVICE_URL = "/api/#{VERSION}/xml-in"
Now, enjoy accessing great online invoices service through simplified Ruby wrapper ( after patching :) ).
No comments:
Post a Comment