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

Google Maps Integration #30

Open
wants to merge 5 commits 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
6 changes: 6 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
override:
- bundle install
test:
override:
- ruby tests/app_test.rb
15 changes: 14 additions & 1 deletion app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,18 @@
require 'httparty'

get '/' do
erb :index, :locals => {result: nil}
if params[:url] then
if params[:url] == '' then
erb :index, :locals => {result: nil, error: 'Endereço Inválido'}
else
escaped = URI.escape(params[:url])
url = "http://maps.google.com/maps/api/geocode/json?address=#{escaped}"
response = HTTParty.get(url)
parsed = JSON.parse(response.body)['results']
erb :index, :locals => {result: parsed.first, error: nil}
end
else
erb :index, :locals => {result: nil, error: nil}
end

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

def test_home_busca_de_endereco_information
get '/?url=Avenida+Mato+Grosso+1010'
assert_match /Avenida Mato Grosso/, last_response.body
end

def test_home_busca_invalida
get '/?url='
assert_match /Endereço Inválido/, last_response.body
end

end
18 changes: 17 additions & 1 deletion views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,23 @@
</form>

<div>
<%= result %>
<%if result != nil%>
<h2><%= result["formatted_address"] %></h2>
<ul>
<% result["address_components"].each do |component| %>
<li><%= component["long_name"]%></li>
<li><%= component["short_name"]%></li>
<%end%>
</ul>
<h3>Geometry</h3>
<ul>
<li>LAT: <%= result["geometry"]["location"]["lat"] %></li>
<li>LNG: <%= result["geometry"]["location"]["lng"] %></li>
</ul>
<p><b>Place Id:</b> <%= result["place_id"]%></p>
<%else%>
<h2><%= error %></h2>
<%end%>
</div>
</body>
</html>