-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.rb
86 lines (69 loc) · 1.71 KB
/
index.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
83
84
85
86
require "bundler/setup"
require 'sinatra'
require 'sinatra/config_file'
require './partials'
require 'haml'
require 'json'
require 'hashie'
require 'pony'
config_file 'iodoctor.yml'
configure :development do
Pony.options = {
:via => :smtp,
:via_options => {
:address => 'localhost',
:port => '2525',
:domain => 'iodoctor.net'
}
}
end
configure :production do
Pony.options = {
:via => :smtp,
:via_options => {
:address => 'smtp.sendgrid.net',
:port => '587',
:domain => 'iodoctor.net',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => :plain,
:enable_starttls_auto => true
}
}
end
helpers Sinatra::Partials
get '/' do
haml :start, :format => :html5
end
post '/' do
@version = settings.version
@show_bottom_bar = true
unless params[:file] &&
(tmpfile = params[:file][:tempfile]) &&
(name = params[:file][:filename])
if params[:load]
return haml :start
end
@result = Hash.new
@result["endpoints"] = Hash.new
return haml(:endpoints)
end
contents = tmpfile.read
result = JSON(contents)
@result = Hashie::Mash.new(result)
haml :endpoints
end
post '/email' do
json = params[:json]
body = "Thanks for using I/O Doctor. Your .json file is attached."
Pony.mail(:to => params[:to_address],
:from => "[email protected]",
:subject => "I/O Doctor JSON Output",
:body => "Thanks for using I/O Doctor. Your .json file is attached.",
:attachments => {"iodoctor.json" => json})
end
post '/file' do
content_type 'application/json'
attachment 'config.json'
response.write params[:json]
end