-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpummel.rb
54 lines (45 loc) · 1.35 KB
/
pummel.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
require 'logger'
require 'sinatra'
require 'faraday'
require 'faraday-http-cache'
require 'slim'
require 'onebox'
require 'feedjira'
set :slim, pretty: true
# The global application log. Send to STDOUT.
system_log = Logger.new(STDOUT)
system_log.level = Logger::DEBUG
# Rack::CommonLogger uses a slightly different API for sending log messages.
# rack.errors uses puts, which is private in Logger.
Logger.class_eval { alias :write :'<<'; alias :puts :error }
configure do
# Point CommonLogger to my Logger instance
use Rack::CommonLogger, system_log
end
before {
# Point Rack middleware that logs to whatever error console
env["rack.errors"] = system_log
}
# The faraday connector
faraday = Faraday.new do |fara|
fara.request :url_encoded # Make all requests URL-encoded
fara.response :logger, system_log # Log responses to standard out
fara.response :raise_error # Raise in Ruby for any 400 or 500 error
fara.use :http_cache, logger: system_log
fara.adapter Faraday.default_adapter
end
faraday.headers[:user_agent] = 'Pummel v0.4.1'
get '/' do
slim :index
end
get '/:user' do
@user = params[:user]
@rss_url = "https://feeds.pinboard.in/rss/u:#@user/"
@result = faraday.get(@rss_url)
@rss = Feedjira::Feed.parse(@result.body.force_encoding('UTF-8'))
if params[:details]
slim :details
else
slim :user
end
end