comparison 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
comparison
equal deleted inserted replaced
233:0f0cc55ff11b 245:2935c5e52a71
3 3
4 def atom_id(id) 4 def atom_id(id)
5 "tag:rsstweet@nanaya.pro,2014:#{id}" 5 "tag:rsstweet@nanaya.pro,2014:#{id}"
6 end 6 end
7 7
8 def expand_url(text, *urls) 8 def expand_url(text, urls)
9 urls.flatten! 9 text.gsub /https?:\/\/t\.co\/[A-Za-z0-9]+/ do |url|
10 expanded = urls[url]
10 11
11 urls = urls.reduce({}) do |result, u| 12 case expanded
12 if u.try(:[], :url) 13 when nil then url
13 result[u[:url]] = u[:expanded_url] 14 when Hash then expanded[:url]
15 else expanded
14 end 16 end
15
16 result
17 end
18
19 text.gsub /https?:\/\/t\.co\/[A-Za-z0-9]+/ do |url|
20 urls[url] || url
21 end 17 end
22 end 18 end
23 19
24 def status_url(tweet) 20 def status_url(tweet)
25 status_url_base tweet.user.screen_name, tweet.id 21 status_url_base tweet[:user][:username], tweet[:id]
26 end 22 end
27 23
28 def status_url_base(screen_name, tweet_id) 24 def status_url_base(username, id)
29 "https://twitter.com/#{screen_name.presence || '_'}/status/#{tweet_id}" 25 "https://twitter.com/#{username.presence || '_'}/status/#{id}"
30 end 26 end
31 end 27 end