Mercurial > rsstweet
diff app/helpers/application_helper.rb @ 245:2935c5e52a71
No more official twitter api
author | nanaya <me@nanaya.net> |
---|---|
date | Mon, 17 Jul 2023 04:23:09 +0900 |
parents | 3ac13a9e593d |
children | c6a50441a58d |
line wrap: on
line diff
--- a/app/helpers/application_helper.rb Fri Jul 14 01:45:40 2023 +0900 +++ b/app/helpers/application_helper.rb Mon Jul 17 04:23:09 2023 +0900 @@ -5,27 +5,23 @@ "tag:rsstweet@nanaya.pro,2014:#{id}" end - def expand_url(text, *urls) - urls.flatten! + def expand_url(text, urls) + text.gsub /https?:\/\/t\.co\/[A-Za-z0-9]+/ do |url| + expanded = urls[url] - urls = urls.reduce({}) do |result, u| - if u.try(:[], :url) - result[u[:url]] = u[:expanded_url] + case expanded + when nil then url + when Hash then expanded[:url] + else expanded end - - result - end - - text.gsub /https?:\/\/t\.co\/[A-Za-z0-9]+/ do |url| - urls[url] || url end end def status_url(tweet) - status_url_base tweet.user.screen_name, tweet.id + status_url_base tweet[:user][:username], tweet[:id] end - def status_url_base(screen_name, tweet_id) - "https://twitter.com/#{screen_name.presence || '_'}/status/#{tweet_id}" + def status_url_base(username, id) + "https://twitter.com/#{username.presence || '_'}/status/#{id}" end end