-
Notifications
You must be signed in to change notification settings - Fork 0
/
rssrelay.rb
37 lines (28 loc) · 951 Bytes
/
rssrelay.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
class RSSRelay < Sinatra::Application
get "/v3/streams/contents" do
content_type :json
if ENV["ALLOW_ALL_ORIGINS"] && ENV["ALLOW_ALL_ORIGINS"].downcase == "true"
cross_origin
elsif ENV["ORIGINS"] && ENV["ORIGINS"].split(",")
cross_origin :allow_origin => origins
end
client = Feedlr::Client.new
if ENV["API_KEY"] && params[:key] != ENV["API_KEY"]
halt 401, {:error => "Invalid key"}.to_json
end
if !params[:url] && !params[:stream_id]
halt 422, {:error => "A URL or stream ID is required"}.to_json
end
stream_id = (params[:url] && ("feed/" + params[:url])) || params[:stream_id]
count = params[:count] || ENV["DEFAULT_COUNT"] || 10
client.stream_entries_contents(
stream_id,
{
count: count,
ranked: params[:ranked],
newerThan: params[:newerThan],
continuation: params[:continuation]
}
).to_json
end
end