I'm wrapping the Digital Ocean API. This particular response has a status, and an array of droplet sizes.
For example:
'{"status":"OK","sizes":[{"id":66,"name":"512MB","slug":"512mb","memory":512,"cpu":1,"disk":20,"cost_per_hour":0.00744,"cost_per_month":"5.0"},{"id":63,"name":"1GB","slug":"1gb","memory":1024,"cpu":1,"disk":30,"cost_per_hour":0.01488,"cost_per_month":"10.0"}]}'
As a start, I did:
reader := NeoJSONReader on: jsonString readStream.
reader for: DoResponse customDo: [ :m | m decoder: [ :dict |
DoResponse new
status: (dict at: 'status');
contents: (dict at: 'sizes') ] ].
response := reader nextAs: DoResponse.
response isOk ifFalse: [ self error: 'Query failed!' ].
^ response contents.
However, the size objects are still plain dictionaries. I'd like to convert them to DropletSize objects. And I'd rather leverage NeoJSON than implement a custom DropletSize fromDictionary: if possible.
What's the best way to handle this?
Thanks.
Cheers,
Sean