-
Notifications
You must be signed in to change notification settings - Fork 2
/
pincodr_controller.rb
50 lines (39 loc) · 934 Bytes
/
pincodr_controller.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
class PincodrController < ApplicationController
helpers Sinatra::Jsonp
mime_type :json, "application/json"
before { content_type :json }
not_found do
jsonp({:error => "not found"})
end
helpers do
def deliver_output(pins)
if pins.nil? || pins.empty?
not_found
else
jsonp(pins.map(&:attrs))
end
end
end
get '/' do
content_type :html
erb :about
end
get "/pin/:pin" do
deliver_output(Pin.get(params[:pin], :pin))
end
get "/area/:area" do
deliver_output(Pin.get(params[:area], :area))
end
get "/taluk/:taluk" do
deliver_output(Pin.get(params[:taluk], :taluk))
end
get "/tehsil/:tehsil" do
deliver_output(Pin.get(params[:tehsil], :tehsil))
end
get "/district/:district" do
deliver_output(Pin.get(params[:district], :district))
end
get '/search/:value' do
deliver_output(Pin.find_like(params[:value]))
end
end