Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Places ActiveResource

I'm trying to write an ActiveResources model to interact with the Google Places API - https://developers.google.com/places/web-service/search#PlaceSearchRequests

I see the API requires a key and some parameters in order to fetch results. So my question is: how do I properly add the API key to the request, because right now I have no idea if it is actually going through and also how do I set up the model in order to pass the parameters when later I want to do something like:

GooglePlace.where(query: 'whatever')

What I have so far is just the default boilerplate for an ActiveResource, with no clue as how to add the missing information:

class GooglePlace < ActiveResource::Base
  self.site = 'https://maps.googleapis.com/maps/api/place/textsearch/json?query=pool'
  @key = API_KEY
end

And my index action method in the controller looks like this:

def index
  @users = GooglePlace.where(query: 'pool')
end

In the console, all I get is this:

Started GET "/google_places" for ::1 at 2016-02-27 16:41:11 -0300
Processing by GooglePlacesController#index as HTML
  Rendered google_places/index.html.erb within layouts/application (61.0ms)
Completed 500 Internal Server Error in 2027ms (ActiveRecord: 0.0ms)

Any help will be much appreciated. Thank you for your time!

like image 712
Diogo Schneider Avatar asked Aug 10 '26 02:08

Diogo Schneider


1 Answers

According to this piece of code, one must override a lot of ActiveResource's methods in order to make it even work with a plain non-Rails REST API. I sincerely don't think it's worth it, so maybe ActiveResource is really for Rails-to-Rails communication. Thanks to everybody who tried to help me.

like image 53
Diogo Schneider Avatar answered Aug 12 '26 17:08

Diogo Schneider



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!