skyfall icon indicating copy to clipboard operation
skyfall copied to clipboard

Return records parsed into proper objects instead of hashes

Open mackuba opened this issue 2 years ago • 2 comments

mackuba avatar Jun 15 '23 14:06 mackuba

ASAP pls

kawayuta avatar Jul 20 '23 05:07 kawayuta

Hey, I don't think I will be changing this soon, to be honest… My focus right now is on performance - the websocket library I've used was struggling to keep up with the stream on some days with more traffic. I'm working on a new version with a different library on the faye branch, and then I want to optimize it some more.

Just adding some records built from JSON would be easy, but I don't know yet how to do it "right" in a way that I will be happy with. Ideally it should be somehow building record classes from the "lexicon" definitions to make it more universal. But how much of the lexicon should I cover? How to name the records? To what degree should it be automatic? Should this be in a separate library? Should I share the code with other Ruby libraries for AtProto? I was thinking about this just yesterday, but I don't have answers right now and it's not a priority. And I don't want to add a new quickly done API now and change it later.

If you want a more friendly API right now with accessing properties using dots instead of [''], you can use e.g. the Mash thing from Hashie https://github.com/hashie/hashie#mash, or do something like this using OpenStruct:

JSON.parse(op.raw_record, object_class: OpenStruct)

This builds a nested OpenStruct from JSON which can then let you do something like: record.embed.image.alt.

mackuba avatar Jul 20 '23 13:07 mackuba