Go back to the main page

Getting Started With The Xero Api Gem

 

Why Another Ruby Xero Gem?

I am slated to begin a Xero integration soon and I took a preliminary look-see. There is quite a bit in common with QuickBooks Online with regards to resources and entities, however, when I started looking closely at the Ruby-Xero gems the current crop of de facto ones were very old, being written at a time when the Xero API was XML only.

This is the same kind of thing that plagued the quickbooks-ruby gem. When constructing an API client to a XML-only endpoint a lot of "cruft" can start to accumulate depending on how you approach building the XML payloads.

Therefore, I built a new Ruby-Xero client that is pure JSON-in, JSON-out and certified to be 100% anti-cruft. Ok, maybe 95% 😇

How Much Anit-Cruft?

Here are the line count totals (of .rb files):

Get Started Hacking Xero With xero-api

This section is at the 1:30 mark of the screencast. 🎥
  1. Follow and do all in Step 1 from the Getting Started Guide.
  2. git clone git://github.com/minimul/xero-api && cd xero-api
  3. bundle
  4. Create a .env file
    1. cp .env.example_app.oauth1 .env
    2. Edit the .env file values with consumer_key and consumer_secret.
  5. Start up the example app => ruby example/oauth.rb
  6. In browser go to http://localhost:9393.
  7. Use the Connect to Xero button to connect to your Xero account.
  8. After successfully connecting click on the displayed link => View All Customers
  9. Checkout example/oauth.rb to see what is going on under the hood.
    • Important: In the /auth/xero/callback route there is code there that will automatically update your .env file.

Once your .env file is completely filled out you can use the bin/console test to play around

This section is at the 5:29 mark of the screencast. 🎥
bin/console test
>> @xero_api.get :contacts, id: '5345-as543-4-afgafadsafsad-45334'
  • Pushed on 11/02/2018 by Christian