Last active
April 19, 2016 20:13
-
-
Save kevinzen/36c289bace83c08d39fc958f8287fc5f to your computer and use it in GitHub Desktop.
Revisions
-
kevinzen revised this gist
Apr 19, 2016 . 1 changed file with 8 additions and 13 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ require 'csv' class String def remove_non_ascii(replacement="") self.gsub(/[\u0080-\u00ff]/, replacement) @@ -8,7 +10,6 @@ def remove_non_ascii(replacement="") desc "fetch addresses from google" task google_geocode: :environment do # google api key # AIzaSyBL86-TdZkNYwnpP4xRJAYImogE9NVzwjg # Google endpoint call @@ -19,30 +20,24 @@ def remove_non_ascii(replacement="") API_KEY = 'TdZkNYwnpP4xRJAYImogE9NVzwjg' camps = Camp.limit(10) camps.each do | camp | # these lines create an 'address' based on fields I have. The fields may be blank. add1 = camp.address_1.remove_non_ascii city = camp.city.remove_non_ascii state = camp.state.remove_non_ascii zip = camp.zip.remove_non_ascii address_string = "#{add1},+#{city},+#{state}" decoder_endpoint = "#{BASE_URL}#{ENDPOINT}?address=#{address_string}&KEY=#{API_KEY}" begin res = RestClient.get decoder_endpoint data = JSON.parse(res.body) puts data.inspect end # end begin / rescue block end # end camp loop end # end task end # -
kevinzen renamed this gist
Apr 19, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
kevinzen created this gist
Apr 19, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ class String def remove_non_ascii(replacement="") self.gsub(/[\u0080-\u00ff]/, replacement) end end namespace :test do desc "fetch addresses from google" task google_geocode: :environment do # google api key # AIzaSyBL86-TdZkNYwnpP4xRJAYImogE9NVzwjg # Google endpoint call # https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY BASE_URL = "https://maps.googleapis.com" ENDPOINT = "/maps/api/geocode/json" API_KEY = 'TdZkNYwnpP4xRJAYImogE9NVzwjg' camps = Camp.limit(10) camps.each do | camp | # these lines create an 'address' based on fields I have. The fields may be blank. add1 = camp.address_1.remove_non_ascii city = camp.city.remove_non_ascii state = camp.state.remove_non_ascii zip = camp.zip.remove_non_ascii address_string = "#{add1},+#{city},+#{state}" decoder_endpoint = "#{BASE_URL}#{ENDPOINT}?address=#{address_string}&KEY=#{API_KEY}" begin res = RestClient.get decoder_endpoint data = JSON.parse(res.body) puts data.inspect end # end begin / rescue block end # end camp loop end # end task