Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to store result sets for future use? #119

Closed
josh-m-sharpe opened this issue Jun 18, 2019 · 2 comments
Closed

how to store result sets for future use? #119

josh-m-sharpe opened this issue Jun 18, 2019 · 2 comments

Comments

@josh-m-sharpe
Copy link
Contributor

I tried to marshal a result set so that I could store it in a DB with Marshal.dump(GOOGLE_PLACES.spots_by_query(my_query)) - but that resulted in: ArgumentError (string contains null byte)

So, after poking around GooglePlaces::Spot.initialize I see that json_result_object isn't stored on the Spot anywhere, which I suppose, if it were available, could be used to reconstitute the object later on, along with the api key. e.g. GooglePlaces::Spot.new(result_json_object_from_database, my_api_key)

I could submit a PR to make the raw results a bit more accessible, but curious to get the maintainers thoughts first.

Thanks!

@edwinwills
Copy link
Collaborator

edwinwills commented Jun 18, 2019

Ah interesting, so you're thinking it would be handy to keep the json_result_object instance as an attribute on the GooglePlaces::Spot class, rather than just assigning out the instance variables for each individual attribute.

This sounds like a handy API method to me - maybe having a method like attributes or to_h on the Spot object, that returns the complete set of attributes. Only question from me would be whether you'd want to return the raw response from Google, or only the attributes that are being set within the spot class - unsure which I'd prefer, but slightly edging towards the attributes that are assigned in the Spot class, so they're whitelisted.

@josh-m-sharpe
Copy link
Contributor Author

Well, I think if you expose json_result_object then you can reimport it with the already existing method new without having to create something new.
So, something like this should work:

spots = client.spots_by_query(query)
recreated_spot = GooglePlaces::Spot.new(spots[0].raw_json, api_key)

Truthfully, that feels a little bit hacky since I'm actually trying to cache the requests to Google in order to minimize api usage... and that feels like something that would be an extension of the gem instead of punting it to the application. Or maybe just an extension of HTTParty. Seems like there's a bunch of unmaintained httparty cache gems dry_ice cachebar

All that say, I think exposing json_result_object is probably sufficient - gonna give that a shot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants