forked from chaseWilliams/router
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rb
More file actions
29 lines (26 loc) · 919 Bytes
/
app.rb
File metadata and controls
29 lines (26 loc) · 919 Bytes
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
require './router/loader'
class App < Sinatra::Application
before do
content_type 'application/json'
end
get '/' do
puts ENV['OWM_URI']
Logger.new(STDOUT).warn 'hello'
begin
lat = params[:lat]
lon = params[:lon]
rescue StandardError => err
status 400
{status: 'fail', reason: err.to_s}.to_json
else
weather = JSON.parse RestClient.get ENV['OWM_URI'] + "mode=coordinates&lat=#{lat}&lon=#{lon}"
puts weather
wiki_article = JSON.parse RestClient.get ENV['WIKI_URI'] + "lat=#{lat}&lon=#{lon}"
puts wiki_article
flickr_url = JSON.parse RestClient.get ENV['FLICKR_URI'] + "temp=#{weather['data']['temp']}" +
"&id=#{weather['data']['condition_id']}"
puts flickr_url
{status: 'ok', weather: weather, article: wiki_article, pic: flickr_url}.to_json
end
end
end