Hi,
I’m building an adapter for a specific API on top of rom-http. I’ve got it working to the point of making requests, but now I hit the proverbial wall.
The API implements a simple paging mechanism. On > 60 results a __next key is added in with a url to the next page.
This is an example of the returned json:
{
"d": {
"__next": "https://start.exactonline.nl/api/v1/123456/cashflow/Receivables?$skiptoken=guid'b74c1ad9-b2bd-4e54-a028-55d66b5063d2'",
"results": [
// ... List of up to 60 results
]
}
}
In my ResponseHandler I process and return the contents of [d][results]. What is the best way to implement this paging mechanism in ROM?
My thinking was that I’d set the next page uri in the dataset. Calling dataset.response uses next_page_uri if present or else the standard resource uri.
First I tried adding next_page_uri as on option to Dataset, and set it in the ResponseHandler. The problem is I’d only replace the dataset instance in the ResponseHandler itself and not the dataset instance of the relation.
I could end up with adding an attr_accessor :next_page_uri in Dataset, but I’m not sure this is safe since the dataset seems to be instantiated at boot (I’m using dry-web-roda). I don’t want to accidentaly share the next page uri for different users (not sure if this is the case though).
On top of this the token refresh mechanism I added suffers from the same problem. I’ve added option :access_token to Dataset. When the token is expired the RequestHandler replaces its dataset instance with a new one with the new access_token, but the dataset instance that’s injected in ResponseHandler is not updated and still has the expired token offcourse. Because of this it’s not possible to perform a next_page request in ResponseHandler.
Using attr_accessor instead of option could solve this, permitting me to change the state of the shared dataset instance. But I’d rather avoid changing the state this way, it doesn’t feel very ROM-ish 
I hope this all makes sense, thanks for helping! 
Additional input -if any- would be much appreciated. Cheers!