bgeek.net

Behaviour Driven Development

Posted by Owen Evans on Thursday, October 22nd, 2009

Last night I had a lot of fun presenting at the Wellington .net User Group on Behaviour Driven Development.

Below are the slides from the talk.

Bahaviour Driven DevelopmentView more presentations from buildmaster. Sphere: Related Content

continue reading

TechEd 2009 Day 2

Posted by Owen Evans on Tuesday, September 15th, 2009

Day 2 seems a bit thinner on the ground for dev talks.

Challenging the role of Software Architect by Kevin Fancis Not so much challenging as saying we need them more, which I disagree with, had personal disagreements with the content of the talk and for the first time at TechEd I felt compelled to leave the [...]

continue reading

TechEd 2009 Day 1

Posted by Owen Evans on Monday, September 14th, 2009

Well day one is coming to a close, so before I forget I need to get my thought’s down on paper…. well virtual paper..

keynote

I really think MS need to rethink inviting politicians to TechEd, it really adds very little value for people in the audience, in the end it’s a gathering of IT professionals and [...]

continue reading

Xero API + Ruby Revisited

Posted by Owen Evans on Thursday, July 31st, 2008

Oh my, thanks very much to Tim Haines for pointing out HTTParty, this little gem makes writing an API for the Xero code really, really easy:

here’s all the methods for getting info out of Xero:

require 'HTTParty'
require 'pp'
class Xero
  include HTTParty
  format :XML
  def initialize(url,apikey)
    Xero.baseuri(url)
    Xero.defaultparams({:apiKey=>apikey})
  end
  def contacts(customerKey)
    Xero.get("/contacts",:query=>{:xeroKey=>customerKey})["Response"]
  end
  def contact(customerKey,opts)
    opts = {:xeroKey=>customerKey}.merge(opts)
    Xero.get("/contact",:query=>opts)["Response"]
  end
  def accounts(customerKey)
    Xero.get("/accounts",:query=>{:xeroKey=>customerKey})["Response"]
  end
  def tracking(customerKey)
    Xero.get("/tracking",:query=>{:xeroKey=>customerKey})["Response"]
  end
   def invoice(customerKey,opts)
    opts = {:xeroKey=>customerKey}.merge(opts)
    Xero.get("/invoice",:query=>opts)["Response"]
  end
end
that’s it…. that’s all there is to it. IT’s EASY AS PIE, Xero effort as I like to call it.

With this class I can then do:

Xero.new(”http://xeronetworkurl”,”MyAPIKey”).accounts(”MyCustomerKey”) and I get a hash of all my accounts

contacts can be selected by contactNumber or contactID

just add the option:

Xero.new(”http://xeronetworkurl”,”MyAPIKey”).contact(“MyCustomerKey”,{:contactID => “contactid”})

Xero.new(”http://xeronetworkurl”,”MyAPIKey”).contact(“MyCustomerKey”,{:contactNumber=> “contactNumber”})

Invoices the same.

It’s a breeze

as promised I will be doing some posting examples, but I’m so glad I found HTTParty it’s going to make my life sooo much easier.

Sphere: Related Content

Posted in: [|||].

kick it on DotNetKicks.com

Shout it

  • Sweet... have you also see ROXML (http://roxml.rubyforge.org/)?

    I'm about to start my own REST API for a side project, and ROXML sounds the business - it provides easy marsheling "Using simple annotations, it enables Ruby classes to be custom-mapped to XML."
  • Thomas B
    Being a rails noob this looks like even I could use HTTParty. Maybe a stupid question but would the code above be in a new class file "Xero.rb" just as above ? How would the methods be referenced from other Rails controllers ?
  • Hey bohtho,
    sorry for my tardiness in replying.

    simply just put a require in to the top of the class file. Just copy the code into ruby.rb and as long as their is an include statment that tells ruby where to load the file from ie if it's in the same directory: include 'xero.rb'
    then you can create a new instance of the Xero object using Xero.new(”http://xeronetworkurl”,”MyAPIKey”);

    and use the methods as described.

    There are other ways to use it too. you can include it on a base controller to stop you having to include it with every class etc.

    It's not quite plugin ready, but there might be a good reason to start distributing it as a gem, i'll have to think about it.

    Cheers
    Owen
blog comments powered by Disqus