-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
78 lines (56 loc) · 1.67 KB
/
main.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Ruby dependencies
require 'sinatra'
require 'sinatra/reloader' if development?
require 'json'
require 'net/http'
require 'open-uri'
# sinatra configuration
set :show_exceptions, :after_handler
before do
# allow CORS
content_type :json
status 200
headers \
'Allow' => 'OPTIONS, GET',
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Methods' => ['OPTIONS', 'GET']
end
not_found do
body ({ error: 'Ooops, this route does not seem exist'}.to_json)
end
error do
body ({ error: 'Sorry there was a nasty error - ' + env['sinatra.error'].message }.to_json)
end
get '/' do
remote_ip = open('http://ipecho.net/plain').read
body ({ public_ip: remote_ip, client_ip: request.ip, date: Time.now(), puma_config: env['puma.config'].options }.to_json)
end
# API endpoints
IP_EP = 'http://ip-api.com/json'
TRANSPORT_EP = 'http://transport.opendata.ch/v1'
WEATHER_EP = 'http://api.openweathermap.org/data/2.5'
# start coding below
get '/ip' do
body ({ errors: [{ message: 'not yet implemented' }]}.to_json)
end
get '/locations' do
body ({ errors: [{ message: 'not yet implemented' }]}.to_json)
end
get '/connections' do
body ({ errors: [{ message: 'not yet implemented' }]}.to_json)
end
get '/stationboard' do
body ({ errors: [{ message: 'not yet implemented' }]}.to_json)
end
get '/weather' do
body ({ errors: [{ message: 'not yet implemented' }]}.to_json)
end
get '/stations' do
body ({ errors: [{ message: 'not yet implemented' }]}.to_json)
end
get '/weathers' do
body ({ errors: [{ message: 'not yet implemented' }]}.to_json)
end
get '/future_weathers' do
body ({ errors: [{ message: 'not yet implemented' }]}.to_json)
end