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):
- Total LOC count of :
- minimul/xero-api => 910! 🚀
- waynerobinson/xeroizer => 6019
- xero-gateway/xero_gateway => 5545
Get Started Hacking Xero With xero-api
This section is at the 1:30 mark of the screencast. 🎥
- Follow and do all in Step 1 from the Getting Started Guide.
git clone git://github.com/minimul/xero-api && cd xero-api
bundle
- Create a
.env
filecp .env.example_app.oauth1 .env
- Edit the
.env
file values withconsumer_key
andconsumer_secret
.
- Start up the example app =>
ruby example/oauth.rb
- In browser go to
http://localhost:9393
. - Use the
Connect to Xero
button to connect to your Xero account. - After successfully connecting click on the displayed link =>
View All Customers
- 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.
- Important: In the
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