Created
November 6, 2013 02:38
-
-
Save masaki925/7330015 to your computer and use it in GitHub Desktop.
see spot search result for Google and Facebook and Foursquare using Place API with location.
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'net/https' | |
require 'uri' | |
require 'pry' | |
require 'json' | |
require 'logger' | |
require 'pp' | |
SSL_CERT_FILE = "/path/to/cacert.pem" | |
URL_BASE_GOOGLE = "https://maps.googleapis.com/maps/api/place/search/json?location=LAT_LNG&radius=1000&key=API_KEY&sensor=false&language=ja" | |
KEY_GOOGLE = "xxx" | |
URL_BASE_FACEBOOK = "https://graph.facebook.com/search?center=LAT_LNG&distance=1000&type=place&access_token=API_KEY&locale=ja_JP" | |
KEY_FACEBOOK = "xxx" | |
URL_BASE_FSQ = "https://api.foursquare.com/v2/venues/search?ll=LAT_LNG&oauth_token=API_KEY&v=20131105" | |
KEY_FSQ = "xxx" | |
@logger = Logger.new( STDOUT ) | |
def get_result_json( lat_lng, base_url, key ) | |
url = base_url.sub( "LAT_LNG", lat_lng ).sub( "API_KEY", key ) | |
uri = URI.parse(url) | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_PEER | |
http.ca_file = SSL_CERT_FILE | |
request = Net::HTTP::Get.new(uri.request_uri,initheader = {'Content-Type' =>'application/json'}) | |
response = http.request(request) | |
JSON.parse response.body | |
rescue => ex | |
raise ex.message | |
end | |
# main //////////////////////// | |
abort "USAGE: LL=22.316096,113.937786 ruby #{__FILE__}" unless ENV["LL"] | |
lat_lng = ENV["LL"] | |
puts "* Google //////////////////////////" | |
result_json = get_result_json lat_lng, URL_BASE_GOOGLE, KEY_GOOGLE | |
pp result_json["results"].map {|d| d["name"]} | |
puts "* Facebook //////////////////////////" | |
result_json = get_result_json lat_lng, URL_BASE_FACEBOOK, KEY_FACEBOOK | |
pp result_json["data"].take(20).map {|d| d["name"] } | |
puts "* Foursquare //////////////////////////" | |
result_json = get_result_json lat_lng, URL_BASE_FSQ, KEY_FSQ | |
pp result_json["response"]["venues"].map {|v| v["name"]} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
binding.pry しながら各API の結果に合わせて出力。