-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
39 lines (34 loc) · 952 Bytes
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require 'sinatra'
require 'sinatra/assetpack'
require_relative 'lib/google_maps'
require_relative 'lib/google_maps_position_finder'
require_relative 'lib/weather_forecast'
register Sinatra::AssetPack
assets {
css :app, ['/css/*.css']
js :app, ['/js/*.js']
css_compression :simple
}
get "/" do
erb :shorts_weather
end
get "/shorts-weather" do
content_type :json
halt 400 unless params[:lat] && params[:long]
maps = GoogleMaps.new(params[:lat], params[:long])
weather = WeatherForecast.new(params[:lat], params[:long])
{
address: maps.formatted_address,
is_it_shorts_weather: weather.shorts_weather?,
}.to_json
end
get "/shorts-weather/get-position" do
content_type :json
halt 400 unless params[:address]
position_finder = GoogleMapsPositionFinder.new(params[:address])
{
latitude: position_finder.latitude,
longitude: position_finder.longitude,
address: position_finder.address
}.to_json
end