-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.rb
55 lines (44 loc) · 1.47 KB
/
server.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
require "rubygems"
require "sinatra"
require 'restclient'
require 'report'
DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{FileUtils.pwd}/reports.db")
Report.auto_upgrade! # WARNINGS: data maybe be removed
configure do
set :pushr, ENV['SERVER_ADDRESS']
end
get "/" do
last = Report.first(:order => [:created_at.desc])
'see <a href="http://code.google.com/p/android-remote-stacktrace/">android-remote-stacktrace</a> for more details, or see the <a href="/report/' + last.id.to_s + '">last error</a>.'
end
post "/report" do
stack = params[:stacktrace]
version = params[:package_version]
package = params[:package_name]
phone = params[:phone_model]
sdk = params[:android_version]
if stack.nil? || version.nil? || package.nil?
halt "Missing required parameters!"
end
report = Report.new(:version => version,
:package => package,
:stack => stack,
:phone => phone,
:sdk => sdk,
:created_at => Time.now)
report.save
# Use Pushr to send notification
# More About Pushr: http://www.reality.hk/articles/2009/07/10/1082/
RestClient.post(options.pushr,
:title => "[ERROR][ANDROID][#{package}-#{version}] ##{report.id}",
:message => stack)
"OK"
end
get "/report/:id" do
id = params[:id]
report = Report.get(id.to_i)
halt "not found" if report.nil?
"<h1>#{report.package} (#{report.version})</h1>" +
"<h2>#{report.phone} (#{report.sdk}) #{report.created_at}</h2>" +
"<hr/><pre>#{report.stack}</pre>"
end