I find EmbedlyObject's behaviour to return nil for non-existent members convenient. It would be even more convenient if (hash and) array members would return an object that behaves in a similar way, so that for example response.images.first.name doesn't give an error when there are no associated images. I would have expected response.images to be something like an EmbedlyObject.
Right now I'm wrapping the response in an object containing something like
classMyEmbedly < SimpleDelegatordefinitialize(url)super(url)enddefimages(super || []).map &OpenStruct.method(:new)endprivatedefdata(url)@embedly ||= Embedly::API.newkey: ENV['EMBEDLY_KEY']@data ||= @embedly.extract(url: url).firstendend
but believe it could better be solved here.
I find
EmbedlyObject's behaviour to returnnilfor non-existent members convenient. It would be even more convenient if (hash and) array members would return an object that behaves in a similar way, so that for exampleresponse.images.first.namedoesn't give an error when there are no associated images. I would have expectedresponse.imagesto be something like anEmbedlyObject.Right now I'm wrapping the response in an object containing something like
but believe it could better be solved here.