Skip to content

Commit

Permalink
Imgur removed their native rss feeds. What a disappointment.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Nov 24, 2016
1 parent 24825fc commit 32ce604
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
16 changes: 14 additions & 2 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -980,10 +980,11 @@
# https://imgur.com/user/thebookofgray
elsif /imgur\.com\/a\/(?<album_id>[a-zA-Z0-9]+)/ =~ params[:q]
# https://imgur.com/a/IwyIm
elsif /imgur\.com\/r\/(?<subreddit>[a-zA-Z0-9_]+)/ =~ params[:q] or /(?:reddit\.com)?\/r\/(?<subreddit>[a-zA-Z0-9_]+)/ =~ params[:q]
elsif /(?:(?:imgur|reddit)\.com)?\/r\/(?<subreddit>[a-zA-Z0-9_]+)/ =~ params[:q]
# https://imgur.com/r/aww
# https://www.reddit.com/r/aww
redirect "https://imgur.com/r/#{subreddit}/rss"
redirect "/imgur/r/#{subreddit}"
return
elsif /(?<username>[a-zA-Z0-9]+)\.imgur\.com/ =~ params[:q] and username != "i"
# https://thebookofgray.imgur.com/
elsif /imgur\.com\/(gallery\/)?(?<image_id>[a-zA-Z0-9]+)/ =~ params[:q]
Expand Down Expand Up @@ -1019,6 +1020,17 @@
end
end

get "/imgur/r/:subreddit" do
@subreddit = params[:subreddit]

response = ImgurParty.get("/gallery/r/#{@subreddit}")
raise ImgurError.new(response) if !response.success?
@data = response.parsed_response["data"]

content_type :atom
erb :imgur_feed
end

get "/imgur/:user_id/:username" do
@user_id = params[:user_id]
@username = params[:username]
Expand Down
6 changes: 3 additions & 3 deletions views/imgur_feed.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<id>imgur:<%= @user_id %></id>
<title><%= @username %> on Imgur</title>
<id>imgur:<%= @user_id || "r:#{@subreddit}" %></id>
<title><%= @username || "r/#{@subreddit}" %> on Imgur</title>
<icon>https://s.imgur.com/images/favicon-96x96.png</icon>
<link href="<%= request.original_url.esc %>" rel="self" />
<link href="https://imgur.com/user/<%= @username %>" rel="alternate" />
<link href="https://imgur.com/<%= @username ? "user/#{@username}" : "r/#{@subreddit}" %>" rel="alternate" />
<updated><%= Time.at(@data[0]["datetime"].to_i) if @data[0] %></updated>
<%-
@data.each do |image|
Expand Down

0 comments on commit 32ce604

Please sign in to comment.