-
Notifications
You must be signed in to change notification settings - Fork 4
/
application.rb
41 lines (31 loc) · 880 Bytes
/
application.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
require 'sinatra'
require 'bundler'
require 'bundler/setup'
# Require gems
Bundler.require :default, (ENV['RACK_ENV'] || :development).to_sym
Dir.glob('./{models,services}/**/*.rb').each do |file|
autoload File.basename(file, '.rb').camelize.to_sym, file
end
# Initiate Settings
class Settings < Settingslogic
source './config/settings.yml'
end
set :bind, '0.0.0.0'
set :public_folder, 'public'
before do
content_type 'application/json'
end
get '/api' do
param :ip, String
param :location, Hash
param :country, String, scope: :location
param :city, String, scope: :location
param :region, String, scope: :location
location = ByIpGetter.perform(params[:ip]) ||
ByLocationGetter.perform(params[:location])
status(404) and return {}.to_json unless location
location.to_json
end
get '/doc' do
redirect '/doc/index.html'
end