File: search.rb

package info (click to toggle)
mikutter 3.5.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 10,256 kB
  • ctags: 2,165
  • sloc: ruby: 19,079; sh: 205; makefile: 20
file content (24 lines) | stat: -rw-r--r-- 711 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
      Retriever::URI.new("https://twitter.com/search?q=#{CGI.escape(self.query)}")
    end
  end
end