-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.rb
82 lines (74 loc) · 1.55 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
79
80
81
82
require 'sinatra'
require 'whois'
require 'haml'
require 'json'
require 'ostruct'
require "sinatra/reloader" if development?
# ruby crimes
class Whois::Record
def to_h
who_dat_hash = {}
self.properties.each_pair do |k, v|
if v.is_a?(Array)
who_dat_hash[k.to_s] = []
v.each do |m|
if m.respond_to?(:members)
who_dat_hash[k.to_s].push( Hash[m.members.zip(m.to_a)] )
else
if m.split(' ').length > 1
who_dat_hash[k.to_s].push( [m.split(' ')].to_h )
else
who_dat_hash[k.to_s].push(m)
end
end
end
elsif v.respond_to?(:members)
who_dat_hash[k.to_s] = Hash[v.members.zip(v.to_a)]
else
who_dat_hash[k.to_s] = v
end
end
who_dat_hash
end
end
before do
response['Access-Control-Allow-Origin'] = '*'
end
helpers do
def whois_structs_hash(whois)
who_dat_is = whois.clone
who_dat_is.properties.each do |p|
# if
end
end
def cache_for_day
response['Cache-Control'] = 'public, max-age=86400'
end
def whois_lookup
lookup_info = Whois.query(params[:url])
end
end
get '/' do
cache_for_day
haml :index
end
get '/lookup' do
begin
cache_for_day
@whois = whois_lookup
haml :lookup
rescue Exception => e
@error = e
haml :error
end
end
get '/lookup.json' do
content_type 'application/json'
begin
cache_for_day
JSON.pretty_generate(whois_lookup.to_h)
rescue Exception => e
@error = e
{ :error => @error }.to_json
end
end