-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathapp.rb
44 lines (40 loc) · 1.88 KB
/
app.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
Cuba.define do
on get do
on root do
res.write '<p>Danos un código postal y te regresamos la colonia, municipio y estado.
<p>Más información en <a href="https://rapidapi.com/acrogenesis/api/mexico-zip-codes">https://rapidapi.com/acrogenesis/api/mexico-zip-codes</a></p>'
end
on 'codigo_postal/:codigo_postal' do |codigo_postal|
env['warden'].authenticate!(:token)
res.headers['Cache-Control'] = 'max-age=525600, public'
res.headers['Content-Type'] = 'application/json; charset=utf-8'
res.headers['Access-Control-Allow-Origin'] = '*'
res.write Oj.dump(PostalCode.where(codigo_postal:)
.as_json(except: :id), mode: :object)
end
on 'buscar', param('q') do |query|
env['warden'].authenticate!(:token)
res.headers['Cache-Control'] = 'max-age=525600, public'
res.headers['Content-Type'] = 'application/json; charset=utf-8'
res.headers['Access-Control-Allow-Origin'] = '*'
res.write Oj.dump(PostalCode.select('DISTINCT codigo_postal')
.where('codigo_postal LIKE :prefix', prefix: "#{query}%")
.order('codigo_postal ASC')
.as_json(except: :id), mode: :object)
end
on 'v2/codigo_postal/:codigo_postal' do |codigo_postal|
env['warden'].authenticate!(:token)
res.headers['Cache-Control'] = 'max-age=525600, public'
res.headers['Content-Type'] = 'application/json; charset=utf-8'
res.headers['Access-Control-Allow-Origin'] = '*'
res.write PostalCodes.fetch_locations(codigo_postal)
end
on 'v2/buscar', param('codigo_postal') do |codigo_postal|
env['warden'].authenticate!(:token)
res.headers['Cache-Control'] = 'max-age=525600, public'
res.headers['Content-Type'] = 'application/json; charset=utf-8'
res.headers['Access-Control-Allow-Origin'] = '*'
res.write PostalCodes.fetch_codes(codigo_postal)
end
end
end