Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding g maps int #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ GEM

PLATFORMS
ruby
x64-mingw32

DEPENDENCIES
httparty
Expand All @@ -26,4 +27,4 @@ DEPENDENCIES
sinatra

BUNDLED WITH
1.14.3
1.14.6
14 changes: 13 additions & 1 deletion app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,17 @@
require 'httparty'

get '/' do
erb :index, :locals => {result: nil}

endereco = params["url"]

if endereco
endereco_escapado = URI.escape(endereco)
url = "http://maps.google.com/maps/api/geocode/json?address=#{endereco_escapado}"
response = HTTParty.get(url)
parsed = JSON.parse(response.body)['results']
erb :index, :locals => {result: parsed}
else
erb :index, :locals => {result: nil}
end

end
5 changes: 5 additions & 0 deletions tests/app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@ def app
def test_home_busca_de_endereco
get '/'
assert_match /Busca de Endereço/, last_response.body
end

def test_busca_endereco
get '/?url=avenida+paulista+2002'
assert_match /Avenida Paulista/, last_response.body
end
end