Mercurial > rsstweet
comparison app/helpers/application_helper.rb @ 234:7a773720d81f legit-client
Totally legit client
author | nanaya <me@nanaya.net> |
---|---|
date | Fri, 14 Jul 2023 22:42:20 +0900 |
parents | 12287b32fbda |
children | 3ac13a9e593d |
comparison
equal
deleted
inserted
replaced
233:0f0cc55ff11b | 234:7a773720d81f |
---|---|
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! | |
10 | |
11 urls = urls.reduce({}) do |result, u| | |
12 if u.try(:[], :url) | |
13 result[u[:url]] = u[:expanded_url] | |
14 end | |
15 | |
16 result | |
17 end | |
18 | |
19 text.gsub /https?:\/\/t\.co\/[A-Za-z0-9]+/ do |url| | 9 text.gsub /https?:\/\/t\.co\/[A-Za-z0-9]+/ do |url| |
20 urls[url] || url | 10 urls[url] || url |
21 end | 11 end |
22 end | 12 end |
23 | 13 |
24 def status_url(tweet) | 14 def status_url(tweet) |
25 status_url_base tweet.user.screen_name, tweet.id | 15 status_url_base tweet[:user][:username], tweet[:id] |
26 end | 16 end |
27 | 17 |
28 def status_url_base(screen_name, tweet_id) | 18 def status_url_base(username, id) |
29 "https://twitter.com/#{screen_name.presence || '_'}/status/#{tweet_id}" | 19 "https://twitter.com/#{username.presence || '_'}/status/#{id}" |
30 end | 20 end |
31 end | 21 end |