xero-ruby
xero-ruby copied to clipboard
`last_connection` actually returns the first connection.
It sorts the connections by ascending updatedAt, and takes the first one. I confirmed the behavior using the API code on my own organization, which has three connections. It always returned the oldest connection, not the connection that was just made.
The code currently is
connections.sort { |a,b| DateTime.parse(a['updatedDateUtc']) <=> DateTime.parse(b['updatedDateUtc'])}.first
But since the timestamps are ISO format, we can just sort them as strings, and take the last, so it should/could be
connections.sort { |a,b| a['updatedDateUtc'] <=> b['updatedDateUtc']}.last
Hi @edlebert thank you for picking this up. I've tested and made the change locally, we're deploying a few things next week to the xero-ruby SDK, so this change will be added in at the same time.