xero-ruby icon indicating copy to clipboard operation
xero-ruby copied to clipboard

`last_connection` actually returns the first connection.

Open edlebert opened this issue 3 years ago • 1 comments

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

edlebert avatar Jan 10 '23 03:01 edlebert

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.

pumpkinball avatar Jan 27 '23 12:01 pumpkinball