Sunday, February 28, 2010

QuickBooks Integration with Ruby is now easier than ever!

Version 1.0.4: I just now updated the QuickBooks rubygem (http://behindlogic.com) with faster speed and new features.

Speed

The xml parsing has been moved from REXML (ugh) to LibXML, and the benchmarks claim almost 3x improvement in speed! This means faster initializing time (the gem has to read the QBXML specs so that it can build your SDK on-the-fly), and faster parsing of QuickBooks responses. Where previously it took about half a second to parse and instantiate Quickbooks ruby objects for a response that contained a hundred customers (on my machine, that is); now it takes only 0.2 seconds.

Feature #1: Associations

Associations have been added to the QuickBooks gem. This means you can forget all about those CustomerRef's and ItemRef's, and just think about the objects you are associating. See the following example:
invoice = QB::Invoice.new(:Customer => QB::Customer.first)
Of course, that'll take some time to grab the customer, but you probably have to anyway. If you already have the customer's ListID or FullName, you can just set it this way too:
invoice = QB::Invoice.new(:Customer => {:FullName => "Mike Anon"})

Feature #2: IRB Development Tips

Since there are 114 object types (or Models, for ActiveRecord users) and 829 different property names, I've added a little treat: when you generate new objects in IRB, you will see a helpful message printed out that lists the properties available on the object you just created. Example:
>> c = QB::Customer.new

Customer.new -> Available properties: [:AccountNumber, :AltContact,
:AltPhone, :Balance, :BillAddress, :BillAddressBlock, :CompanyName,
:Contact, :CreditCardInfo, :CreditLimit, :CurrencyRef, :CustomerTypeRef,
:DataExt, :DeliveryMethod, :EditSequence, :Email, :ExternalGUID, :Fax,
:FirstName, :FullName, :IsActive, :IsStatementWithParent, :ItemSalesTaxRef,
:JobDesc, :JobEndDate, :JobProjectedEndDate, :JobStartDate, :JobStatus,
:JobTypeRef, :LastName, :ListID, :MiddleName, :Mobile, :Name, :Notes,
:OpenBalance, :OpenBalanceDate, :Pager, :ParentRef, :Phone,
:PreferredPaymentMethodRef, :PriceLevelRef, :PrintAs, :ResaleNumber,
:SalesRepRef, :SalesTaxCodeRef, :SalesTaxCountry, :Salutation, :ShipAddress,
:ShipAddressBlock, :Sublevel, :Suffix, :TaxRegistrationNumber, :TermsRef,
:TimeCreated, :TimeModified, :TotalBalance]

=> >
>>
More of these helpful IRB tips are on their way.

As always, head over to http://behindlogic.com to get your hands on the rubygem.

Thursday, December 31, 2009

Http Here!

Announcing httphere, a tiny ruby command line utility that simply serves files for what they're worth, from the directory where you run the command.

It's really simple to use, just change directory to the one you want to serve files from, and run "httphere". It tries to default to port 80, but you'll probably need to be sudo to do port 80. Or you can run on any port by adding the -p PORT option:

cd ~/mywebsite
httphere -p 8000
# open web browser to http://localhost:8000/,
# - assuming there's an index.html right here. :)
What do you need it for? Well, most of the time you may not need it, but you might as well install it because there's no telling when you'll want it. When you'd rather let your browser use HTTP to look at an html file on your filesystem instead of using file://... seriously, file:// will mess with your resource urls that start with a slash (/). Use httphere and you won't have that problem.

Install

sudo gem install httphere

Enjoy!

**********
Update Feb 11, 2010:

* Added default to index.* for directory requests.
* Added support for rendering *.markdown and *.textile files.

Friday, October 16, 2009

Integrating with QuickBooks from the Browser is easy now.

Just a short note...

Bet you never even thought of doing things with QuickBooks from the browser! Jon Hoyt recently approached me about working together to create a program for browsing inventory in QuickBooks from other computers within the same network. At first we were thinking about making a fully-bundled program that communicated with QuickBooks over the network through my QuickBooks Connector, and we'd work on it together one evening a week and release it just before Christmas. But we soon realized that instead of a bundled program, I already have all the tools ready to create a simple HTML + Javascript webpage that does everything we want. That brought our expected release time from Christmas all the way back to... October 27th, only a week and a half away!

The tools involved to build a webpage that communicates with QuickBooks:
1) An HTML webpage
2) Cross-domain Ajax, I've created a couple of JS libs for managing communication with QuickBooks
3) The QuickBooks Browser Connector, which is soon to be released (look for it in about a month, or if enough people really want it, could be sooner)

I'll be blogging again about it when it's ready for use! First version will be FREE, we're thinking of adding features for $1 each. :)

Tuesday, September 15, 2009

Action prerequisites in Rails

Have you ever had a series of pages (controller actions/views) that must be seen in order, because each page sets up prerequisite information for the next? Perhaps like a wizard, a series of pages with forms on them that bring you eventually to a page that does something with that data.

I've come up with a really simple and elegant solution for managing prerequisites in Rails. Since it doesn't take much code, it's easier to just plop it in your project instead of as a plugin (at least in my opinion)...


Here's how it works: Using an around_filter, I can provide a way to jump out of the action when checking the prerequisites. To specify (and check) a prerequisite, simply give it a name: "prerequisite :login". To check the prerequisite, it will call the "login?" method. If that returns true, everything's fine and we'll continue on our merry way into the action, or to the next prerequisite (if you have several). If false, it throws a :prerequisite_unmet, which means it exits the current method and continues on in our catcher method. Next order of business is simply to redirect to the :login action.

A better mategem

I've just built a nicer "mategem" command, which will open up a rubygem's root directory in textmate. It allows you to simply open the latest gem version using the same reference you use in your project to activate the gem.

You know how you can activate a gem by running the gem command (e.g. "gem 'rails'"), or also by simply requiring a library file that is provided by that gem in the root of its library (like "require 'action_controller'" will activate the 'actionpack' gem)? Well, you can use the same two ways to reference a gem when you run mategem:

  • "mategem rails" will open rails
  • "mategem initializer" will also open rails
  • "mategem action_controller" will open the actionpack gem
  • "mategem sinatra" will of course open the sinatra gem
Here is the code for the command. Basically how it works: Tries to reference it as a gem name, if that works, take the last-added load path as the gem path. If that doesn't work, try to have `gem which` find it as a gem-provided library. If that works, we have the path given to us. Parse out where the gem's root folder is, and open it up in mate!


To install, create this file, make it executable, and put it somewhere in your PATH. I would highly advise creating a ~/.bin folder and putting that in your PATH.