jquery - Create Rails Proxy for JSON -
i want asynchronously query foursquare api, not allow old $.get(). short term solution make helper gets data so:
def foursquare_info_for(venue_id) res = net::http.get_response("api.foursquare.com", "/v1/venue.json?vid=#{venue_id}") data = json.parse(res.body) info = hash.new info["mayor_name"] = "#{data['venue']['stats']['mayor']['user']['firstname']} #{data['venue']['stats']['mayor']['user']['lastname']}" info["mayor_photo_src"] = "#{data['venue']['stats']['mayor']['user']['photo']}" info["checkins"] = "#{data['venue']['stats']['checkins']}" info end
that works, i'd rather make proxy can jquery ajax request after page loads speed things bit. i'm pretty sure helper close need proxy working, i'm not sure need put proxy json on side in order able grab jquery.
am on right track creating proxy net/http?
where put proxy on side can access jquery get?
i think using net::http enough this.
i make class it. like:
class foursquareinfo < struct.new(:venue_id) def info { :mayor_name => mayour_name, :mayor_photo_src => mayor_photo_src, :checkins => checkins } end def mayor_name "#{mayor_firstname} #{mayor_lastname}" end def mayor_firstname mayor["firstname"] end def mayor stats["mayor"]["user"] end def stats data["venue"]["stats"] end def data @data ||= json.parse(response.body) end def response net::http.get_response("api.foursquare.com", "/v1/venue.json?vid=#{venue_id}") end # etc... end
and controller:
class foursquareinfoscontroller < applicationcontroller def show render :json => foursquareinfo.new(params[:id]).info end end
Comments
Post a Comment