MJMortimer/elixero

Usage instructions

Closed this issue · 4 comments

Dumb question: how do you access the fields after you do something like:
result = EliXero.CoreApi.Invoices.find client
If I want to look at the subtotal for a particular invoice, how do I do that? I'm new to Elixir and can't figure this out :(

I've tried
result.Invoices

result.__struct__.Invoices

result[:Invoices]

None of them work :(

Hey @jeznag

The Xero API returns json/xml with capitalized properties/elements and so I've built the structs the same way to make the serialization easy.

A side effect of this is that the atoms that make up the keys in the structs are capitalized as well and so when trying to access them like result.Invoices, Elixir interprets that as a module call to an Invocies module which doesn't exist.
When the atom keys are capitalized like this you need to add quotations around the accessor.

You should be able to access the Invoices collection like this result."Invoices"

@MJMortimer Just to weigh in, while I realize that using camel case keys makes serialization easy, it makes use from within Elixir less than ergonomic, which sort of takes away from the point of having an Elixir wrapper around the API. Converting camelized keys to snake case keys isn't super difficult, and I feel like it would significantly improve the experience of using the library.

I'm happy to accept pull requests

It's worth noting that I built this wrapper as a learning project with no prior elixir experience, so things like this along with I'm sure many other parts of the wrapper could be improved for usability