forked from AlexOverbeck/microservice-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.rb
More file actions
32 lines (23 loc) · 715 Bytes
/
application.rb
File metadata and controls
32 lines (23 loc) · 715 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
30
31
32
require 'json'
require 'sinatra'
require 'geocoder'
require 'httparty'
get '/' do
content_type :json
# {
# coordinates: Geocoder.search('Indianapolis').first.coordinates
# }.to_json
response = HTTParty.get("https://api.darksky.net/forecast/32751df79f6c9f93897968c0d588dd69/37.8267,-122.4233")
{
weather: JSON.parse(response.body)
}.to_json
end
get '/forecast/:location' do
content_type :json
coordinates = Geocoder.search(params[:location]).first.coordinates
url = 'https://api.darksky.net/forecast/32751df79f6c9f93897968c0d588dd69/'
response = HTTParty.get(url + coordinates.first.to_s + ',' + coordinates.last.to_s)
{
weather: JSON.parse(response.body)
}.to_json
end