From 7f5e9d6af24a2116e21c5a09ab630aa42c4a72e6 Mon Sep 17 00:00:00 2001 From: Tatsuya Koishi Date: Mon, 11 Mar 2019 21:26:01 +0900 Subject: [PATCH 1/2] #127 --- config/application.yaml | 2 +- lib/mulukhiya_toot_proxy/server.rb | 10 +++++++--- test/server.rb | 12 ++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/config/application.yaml b/config/application.yaml index b264a8fd9..702f9be4a 100644 --- a/config/application.yaml +++ b/config/application.yaml @@ -1,5 +1,5 @@ package: - version: 2.1.13 + version: 2.1.14 url: https://github.com/pooza/mulukhiya-toot-proxy authors: - Tatsuya Koishi diff --git a/lib/mulukhiya_toot_proxy/server.rb b/lib/mulukhiya_toot_proxy/server.rb index f12095ecc..e7a95359d 100644 --- a/lib/mulukhiya_toot_proxy/server.rb +++ b/lib/mulukhiya_toot_proxy/server.rb @@ -14,9 +14,7 @@ def before_post end post '/api/v1/statuses' do - tags = params['status'].scan( - Regexp.new(@config['/mastodon/hashtag/pattern'], Regexp::IGNORECASE), - ) + tags = params['status'].scan(tag_pattern).map{|v| v.first} results = [] Handler.all do |handler| Timeout.timeout(handler.timeout) do @@ -71,5 +69,11 @@ def before_post @logger.error(e.to_h) return @renderer.to_s end + + private + + def tag_pattern + return Regexp.new(@config['/mastodon/hashtag/pattern'], Regexp::IGNORECASE) + end end end diff --git a/test/server.rb b/test/server.rb index 52e5e0e94..b49dd51d4 100644 --- a/test/server.rb +++ b/test/server.rb @@ -1,4 +1,5 @@ require 'rack/test' +require 'json' module MulukhiyaTootProxy class ServerTest < Test::Unit::TestCase @@ -45,6 +46,17 @@ def test_toot assert_equal(last_response.status, 422) end + def test_toot_response + return unless @config['/handlers'].include?('itunes_url_nowplaying') + header 'Authorization', "Bearer #{@config['/test/token']}" + header 'Content-Type', 'application/json' + post '/api/v1/statuses', {'status' => '#nowplaying https://itunes.apple.com/jp/album//1447931442?i=1447931444&uo=4 #日本語のタグ', 'visibility' => 'private'}.to_json + assert(last_response.ok?) + tags = JSON.parse(last_response.body)['tags'] + assert_equal(tags[0]['name'], 'nowplaying') + assert_equal(tags[1]['name'], '日本語のタグ') + end + def test_hook_toot account = Mastodon.lookup_token_owner(@config['/test/token']) assert(account.is_a?(Hash)) From 2a37393d1daa7d33203c775f5399f400ddc24046 Mon Sep 17 00:00:00 2001 From: Tatsuya Koishi Date: Mon, 11 Mar 2019 21:28:26 +0900 Subject: [PATCH 2/2] #127 --- lib/mulukhiya_toot_proxy/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mulukhiya_toot_proxy/server.rb b/lib/mulukhiya_toot_proxy/server.rb index e7a95359d..ac54c7ca9 100644 --- a/lib/mulukhiya_toot_proxy/server.rb +++ b/lib/mulukhiya_toot_proxy/server.rb @@ -14,7 +14,7 @@ def before_post end post '/api/v1/statuses' do - tags = params['status'].scan(tag_pattern).map{|v| v.first} + tags = params['status'].scan(tag_pattern).map(&:first) results = [] Handler.all do |handler| Timeout.timeout(handler.timeout) do