Skip to content

Commit

Permalink
Resolve urls at the very end.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Oct 20, 2018
1 parent c430c06 commit 69db787
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,6 @@
@username = CGI.unescape(username)
end

@data.map do |t|
t = t["retweeted_status"] if t.has_key?("retweeted_status")
for entity in t["entities"]["urls"]
t["full_text"].gsub!(entity["url"], entity["expanded_url"])
end
t["full_text"].grep_urls
end.flatten.tap { |urls| URL.resolve(urls) }

if params[:with_media] == "video"
@data.select! { |t| t["extended_entities"] && t["extended_entities"]["media"].any? { |m| m.has_key?("video_info") } }
elsif params[:with_media] == "picture"
Expand All @@ -152,6 +144,14 @@
@data.select! { |t| t["extended_entities"] }
end

@data.map do |t|
t = t["retweeted_status"] if t.has_key?("retweeted_status")
for entity in t["entities"]["urls"]
t["full_text"].gsub!(entity["url"], entity["expanded_url"])
end
t["full_text"].grep_urls
end.flatten.tap { |urls| URL.resolve(urls) }

erb :twitter_feed
end

Expand Down Expand Up @@ -267,15 +267,15 @@
# The YouTube API can bug out and return videos from other channels even though "channelId" is used, so make doubly sure
@data.select! { |v| v["snippet"]["channelId"] == @channel_id }

@data.map do |video|
video["snippet"]["description"].grep_urls
end.flatten.tap { |urls| URL.resolve(urls) }

if params[:q]
q = params[:q].downcase
@data.select! { |v| v["snippet"]["title"].downcase[q] }
end

@data.map do |video|
video["snippet"]["description"].grep_urls
end.flatten.tap { |urls| URL.resolve(urls) }

erb :youtube_feed
end

Expand Down Expand Up @@ -314,17 +314,17 @@
raise(GoogleError, response) if !response.success?
@data = response.json

@data["items"].map do |post|
post["object"]["body"] = CGI.unescapeHTML(post["object"]["content"]).gsub("<br />", "\n").strip_tags
post["object"]["body"].grep_urls
end.flatten.tap { |urls| URL.resolve(urls) }

@user = if @data["items"][0]
@data["items"][0]["actor"]["displayName"]
else
CGI.unescape(username)
end

@data["items"].map do |post|
post["object"]["body"] = CGI.unescapeHTML(post["object"]["content"]).gsub("<br />", "\n").strip_tags
post["object"]["body"].grep_urls
end.flatten.tap { |urls| URL.resolve(urls) }

erb :googleplus_feed
end

Expand Down Expand Up @@ -550,10 +550,6 @@
@data.select! { |post| post["live_status"] != "LIVE" }
end

@data.map do |post|
post.slice("message", "description", "link").values.map(&:grep_urls)
end.flatten.tap { |urls| URL.resolve(urls) }

@user = @data[0]["from"]["name"] rescue CGI.unescape(username)
@title = @user
if @type == "live"
Expand All @@ -563,6 +559,10 @@
end
@title += " on Facebook"

@data.map do |post|
post.slice("message", "description", "link").values.map(&:grep_urls)
end.flatten.tap { |urls| URL.resolve(urls) }

erb :facebook_feed
end

Expand Down Expand Up @@ -693,16 +693,16 @@
@data["edge_owner_to_timeline_media"]["edges"].select! { |post| !post["node"]["is_video"] }
end

@title = @user
@title += "'s #{type}" if type != "posts"
@title += " on Instagram"

@data["edge_owner_to_timeline_media"]["edges"].select do |post|
post["node"]["edge_media_to_caption"]["edges"][0]
end.map do |post|
post["node"]["edge_media_to_caption"]["edges"][0]["node"]["text"].grep_urls
end.flatten.tap { |urls| URL.resolve(urls) }

@title = @user
@title += "'s #{type}" if type != "posts"
@title += " on Instagram"

erb :instagram_feed
end

Expand Down Expand Up @@ -1026,14 +1026,14 @@
@data = response.json["data"]
@user = @data[0]["user_name"] || CGI.unescape(user)

@data.map do |video|
video["description"]
end.compact.map(&:grep_urls).flatten.tap { |urls| URL.resolve(urls) }

@title = @user
@title += "'s highlights" if type == "highlight"
@title += " on Twitch"

@data.map do |video|
video["description"]
end.compact.map(&:grep_urls).flatten.tap { |urls| URL.resolve(urls) }

erb :twitch_feed
end

Expand Down

0 comments on commit 69db787

Please sign in to comment.