From 128e655aeff0754c6919f9daae394206fbcfa718 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 17 Jun 2017 16:12:45 -0500 Subject: [PATCH] twitter: fetch hashtags for translated tags (fixes #3171). --- app/logical/sources/strategies/twitter.rb | 7 +++---- test/unit/sources/twitter_test.rb | 9 +++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/logical/sources/strategies/twitter.rb b/app/logical/sources/strategies/twitter.rb index 4d284bdbb..338456b61 100644 --- a/app/logical/sources/strategies/twitter.rb +++ b/app/logical/sources/strategies/twitter.rb @@ -12,10 +12,6 @@ module Sources::Strategies end end - def tags - [] - end - def site_name "Twitter" end @@ -32,6 +28,9 @@ module Sources::Strategies @image_url = image_urls.first @artist_commentary_title = "" @artist_commentary_desc = attrs[:text] + @tags = attrs[:entities][:hashtags].map do |text:, indices:| + [text, "https://twitter.com/hashtag/#{text}"] + end end def image_urls diff --git a/test/unit/sources/twitter_test.rb b/test/unit/sources/twitter_test.rb index 41e8543dc..519b31992 100644 --- a/test/unit/sources/twitter_test.rb +++ b/test/unit/sources/twitter_test.rb @@ -100,6 +100,15 @@ module Sources desc = 'test "#foo":[https://twitter.com/hashtag/foo] "#ホワイトデー":[https://twitter.com/hashtag/ホワイトデー] "@noizave":[https://twitter.com/noizave]\'s blah http://www.example.com <>& 😀' assert_equal(desc, @site.dtext_artist_commentary_desc) end + + should "get the tags" do + tags = [ + %w[foo https://twitter.com/hashtag/foo], + %w[ホワイトデー https://twitter.com/hashtag/ホワイトデー], + ] + + assert_equal(tags, @site.tags) + end end end end