Last active
October 17, 2016 13:41
-
-
Save tibastral/e2813333c8ad9044ec888eafa60ae399 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
class PlacesController < ApplicationController | |
def index | |
render json: RIP.get( | |
:gplaces, | |
'autocomplete/json', | |
input: params[:q] | |
) | |
end | |
def show | |
render json: RIP.get( | |
:gplaces, | |
'details/json', | |
placeid: params[:id] | |
) | |
end | |
def photo | |
redirect_to( | |
RIP.generate_url( | |
:gplaces, | |
'photo', | |
photoreference: params[:id], | |
maxwidth: '2048', | |
maxheight: '1536' | |
), | |
type: 'fetch' | |
) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Module to handle external rest apis Requests | |
require 'open-uri' | |
module RIP | |
def self.uri_and_params_to_url(uri, params) | |
[uri, params.to_query].join '?' | |
end | |
def self.url_and_path_to_url(url, path) | |
[url, path].join('/') | |
end | |
def self.gplaces_url(uri, params) | |
uri_and_params_to_url( | |
url_and_path_to_url("https://maps.googleapis.com/maps/api/place", uri), | |
params.merge(key: ENV['GOOGLE_API_KEY']) | |
) | |
end | |
def self.facebook_url(uri, params) | |
uri_and_params_to_url( | |
url_and_path_to_url("https://graph.facebook.com/v2.7", uri), | |
params.merge(access_token: ENV['FB_ACCESS_TOKEN']) | |
) | |
end | |
def self.generate_url(type, uri, params) | |
send(type.to_s + '_url', uri, params) | |
end | |
def self.get(type, uri, options) | |
JSON( | |
HTTParty.get( | |
generate_url(type, uri, options) | |
).body | |
) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment