-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.rb
52 lines (40 loc) · 1.15 KB
/
Server.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
# encoding: utf-8
require 'sinatra'
require_relative 'APIs/Weather'
require_relative 'APIs/Instagram'
require_relative 'APIs/Wikipedia'
require_relative 'APIs/Twitter'
class Server < Sinatra::Base
set :show_exceptions, false
error Exception do
content_type :json, 'charset' => 'utf-8'
headers 'Access-Control-Allow-Origin' => '*'
status 500
'{"Error": "' + env['sinatra.error'].message + '"}'
end
not_found do
content_type :json, 'charset' => 'utf-8'
headers 'Access-Control-Allow-Origin' => '*'
status 404
'{"Error": "404 - Page not found"}'
end
before do
content_type :json, 'charset' => 'utf-8'
headers 'Access-Control-Allow-Origin' => '*'
end
get '/' do
'API: This is our API! The client is at https://livecity.vlntn.pw !'
end
get '/weather/:city' do
Weather.getWeather(params['city'].to_s).to_json
end
get '/wikipedia/:city,:departement' do
Wikipedia.getWikiInfo(params['city'].to_s,params['departement'].to_s).to_json
end
get '/instagram/:city' do
Instagrame.getMediaInsta(params['city'].to_s).to_json
end
get '/twitter/:lat,:long' do
TwitterAPI.getTweets(params['lat'].to_s,params['long'].to_s).to_json
end
end