Blinksale API 5

Posted by Daniel Wanja Mon, 02 Oct 2006 21:52:00 GMT

Today Blinksale published it’s data API. See http://www.blinksale.com/api for the details.

It’s good news for time.onrails.org as now we can use the api to generate a draft Blinksale invoice with one click. I have started coding the integration and expect to release it once I have completed extensive testing.

In short, time.onrails.org interacts in the following way with Blinksale:

  1. get list of client names
  2. get highest invoice number
  3. create invoice

Let’s have a peek at how this is implemented.

Accessing Blinksale

A Blinksale class is provided to interact with your Blinksale data. You need to provide your blinksale id, username, and password.

@blinksale = Blinksale.new 'blinksaleid', 'username', 'password'

In time.onrails.org we will let you define your Blinksale credentials once to avoid having to retype them each time you create an invoice. Storing the password is optional, and if not provided it will be prompted each time. A use_ssl flag can also be specified if you have a paid Blinksale subscription. This is of course recommended for security reasons.

Get the list of clients

clients = @blinksale.clients
names = clients.collect { |c| c.name }

Get the highest invoice number

invoices = @blinksale.invoices
invoices.collect{|invoice| invoice.number}.max  

Create An Invoice

invoice_data =  BlinksaleGenerator.to_xml(INVOICE)
new_invoice = @blinksale.invoices.new invoice_data
new_invoice.save

BlinksaleGenerator is a time.onrails.org class that helps creating the following ‘invoice’ xml.

<?xml version="1.0" encoding="UTF-8"?>
<invoice>
   <client>http://#{blinksaleid}.blinksale.com/clients/#{@client_id}</client>
   <number>34</number>
   <date>2006-09-27</date>
   <terms>30</terms>
   <currency>USD</currency>
   <lines>
     <line>
       <name>Consulting</name>
       <quantity>2.0</quantity>
       <kind>Hours</kind>
       <unit_price>150.00</unit_price>
       <taxed>false</taxed>
     </line>
   </lines>
 </invoice>

The integration is pretty straight forward. Don’t you think? Thanks Scott and your team for this cool application. To find out more on the blinksale api see the online documentation at http://www.blinksale.com/api

Comments

Leave a response

  1. Dr Nic Mon, 31 Dec 2007 23:37:36 GMT

    Have you published the BlinksaleGenerator code anywhere?

    Happy New Year.

  2. Sierra Tue, 12 Feb 2008 17:36:38 GMT

    Dr Nic i think he did it last week but i don’t remeber it where :)

  3. Vital Tue, 19 Feb 2008 01:06:24 GMT

    The integration is pretty straight forward. Don’t you think? I agree it is made simple and easy to forward :)

  4. Sharp Wed, 28 May 2008 10:29:45 GMT

    Pretty neat

  5. Natalia Wed, 11 Jun 2008 17:14:13 GMT

    This is simple. I like it.

Comments