<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>OnRails.org: Blinksale API</title>
    <link>http://onrails.org/articles/2006/10/02/blinksale-api</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Ruby On Rails and related matters.</description>
    <item>
      <title>Blinksale API</title>
      <description>&lt;p&gt;Today Blinksale published it&amp;#8217;s data &lt;span class="caps"&gt;API&lt;/span&gt;. See &lt;a href="http://www.blinksale.com/api/"&gt;http://www.blinksale.com/api&lt;/a&gt; for the details.&lt;/p&gt;


	&lt;p&gt;It&amp;#8217;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.&lt;/p&gt;


	&lt;p&gt;In short, time.onrails.org interacts in the following way with Blinksale:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;get list of client names&lt;/li&gt;
		&lt;li&gt;get highest invoice number &lt;/li&gt;
		&lt;li&gt;create invoice&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;Let&amp;#8217;s have a peek at how this is implemented.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Accessing Blinksale&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;A &lt;em&gt;Blinksale&lt;/em&gt; class is provided to interact with your Blinksale data. You need to provide your blinksale id, username, and password.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;@blinksale = Blinksale.new 'blinksaleid', 'username', 'password'&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;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 &lt;em&gt;use_ssl&lt;/em&gt; flag can also be specified if you have a paid Blinksale subscription. This is of course recommended for security reasons.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Get the list of clients&lt;/strong&gt;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;clients = @blinksale.clients
names = clients.collect { |c| c.name }&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;&lt;strong&gt;Get the highest invoice number&lt;/strong&gt;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;invoices = @blinksale.invoices
invoices.collect{|invoice| invoice.number}.max  &lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;&lt;strong&gt;Create An Invoice&lt;/strong&gt;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;invoice_data =  BlinksaleGenerator.to_xml(INVOICE)
new_invoice = @blinksale.invoices.new invoice_data
new_invoice.save&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;BlinksaleGenerator is a time.onrails.org class that helps creating the following &amp;#8216;invoice&amp;#8217; xml.&lt;/p&gt;


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

	&lt;p&gt;The integration is pretty straight forward. Don&amp;#8217;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 &lt;a href="http://www.blinksale.com/api"&gt;http://www.blinksale.com/api&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Mon, 02 Oct 2006 21:52:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:2504c872-1bfc-4236-8603-5e9b804daf5c</guid>
      <author>Daniel Wanja</author>
      <link>http://onrails.org/articles/2006/10/02/blinksale-api</link>
      <category>Time.OnRails.org</category>
      <category>API</category>
      <category>Blinksale</category>
    </item>
    <item>
      <title>"Blinksale API" by Natalia</title>
      <description>&lt;p&gt;This is simple. I like it.&lt;/p&gt;</description>
      <pubDate>Wed, 11 Jun 2008 17:14:13 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:03ad9245-0b52-4528-92c7-59cf4e094bf0</guid>
      <link>http://onrails.org/articles/2006/10/02/blinksale-api#comment-3701</link>
    </item>
    <item>
      <title>"Blinksale API" by Sharp</title>
      <description>&lt;p&gt;Pretty neat&lt;/p&gt;</description>
      <pubDate>Wed, 28 May 2008 10:29:45 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:9ad29278-0c1d-42cc-92c8-7e75d7f0587d</guid>
      <link>http://onrails.org/articles/2006/10/02/blinksale-api#comment-3571</link>
    </item>
    <item>
      <title>"Blinksale API" by Vital</title>
      <description>&lt;p&gt;The integration is pretty straight forward. Don’t you think? I agree it is made simple and easy to forward :)&lt;/p&gt;</description>
      <pubDate>Tue, 19 Feb 2008 01:06:24 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:d047f444-5857-4a7d-8b94-77f97cd065f9</guid>
      <link>http://onrails.org/articles/2006/10/02/blinksale-api#comment-3266</link>
    </item>
    <item>
      <title>"Blinksale API" by Sierra</title>
      <description>&lt;p&gt;Dr Nic i think he did it last week but i don&amp;#8217;t remeber it where :)&lt;/p&gt;</description>
      <pubDate>Tue, 12 Feb 2008 17:36:38 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:c571768d-5f32-4c7b-a85b-4760357fa3c8</guid>
      <link>http://onrails.org/articles/2006/10/02/blinksale-api#comment-3257</link>
    </item>
    <item>
      <title>"Blinksale API" by Dr Nic</title>
      <description>&lt;p&gt;Have you published the BlinksaleGenerator code anywhere?&lt;/p&gt;


	&lt;p&gt;Happy New Year.&lt;/p&gt;</description>
      <pubDate>Mon, 31 Dec 2007 23:37:36 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:35866c0e-25ca-4790-a1bf-d1e360c894a9</guid>
      <link>http://onrails.org/articles/2006/10/02/blinksale-api#comment-3187</link>
    </item>
  </channel>
</rss>
