Skip to content

Commit

Permalink
Merge pull request #360 from pooza/2_1_14
Browse files Browse the repository at this point in the history
2.1.14
  • Loading branch information
pooza committed Mar 11, 2019
2 parents 0a63889 + 2a37393 commit 6533b84
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion 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
Expand Down
10 changes: 7 additions & 3 deletions lib/mulukhiya_toot_proxy/server.rb
Expand Up @@ -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(&:first)
results = []
Handler.all do |handler|
Timeout.timeout(handler.timeout) do
Expand Down Expand Up @@ -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
12 changes: 12 additions & 0 deletions test/server.rb
@@ -1,4 +1,5 @@
require 'rack/test'
require 'json'

module MulukhiyaTootProxy
class ServerTest < Test::Unit::TestCase
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 6533b84

Please sign in to comment.