aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorToshiaki Asai <toshi.alternative@gmail.com>2016-10-11 21:18:25 +0900
committerToshiaki Asai <toshi.alternative@gmail.com>2016-10-11 21:18:25 +0900
commitcd33b44b4d02dcaf928a43e2b58ab930f95515c5 (patch)
tree7584e5e9737d6cddac692a84c998fcfa15750029 /core
parentffeaf6d087dbbfe16f3061d30c229f6a61b86769 (diff)
downloadmikutter-cd33b44b4d02dcaf928a43e2b58ab930f95515c5.tar.gz
Twitter検索の検索キーワードを表わすModel refs #871
Diffstat (limited to 'core')
-rw-r--r--core/plugin/search/model/search.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/core/plugin/search/model/search.rb b/core/plugin/search/model/search.rb
new file mode 100644
index 00000000..3158bdd7
--- /dev/null
+++ b/core/plugin/search/model/search.rb
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+
+module Plugin::Search
+ class Search < Retriever::Model
+ register :twitter_search, name: Plugin[:search]._('Twitter検索')
+
+ field.string :query, required: true
+
+ # https://twitter.com/search?q=%23superfuckjp
+ handle ->uri{
+ uri.scheme == 'https' &&
+ uri.host == 'twitter.com' &&
+ uri.path == '/search' &&
+ uri.query.split('&').any?{|r|r.split('=', 2).first == 'q'}
+ } do |uri|
+ _, query = uri.query.split('&').lazy.map{|r| r.split('=', 2) }.find{|k,v| k == 'q' }
+ new(query: CGI.unescape(query))
+ end
+
+ memoize def perma_link
+ URI.parse("https://twitter.com/search?q=#{CGI.escape(self.query)}")
+ end
+ end
+end