Class: Wikian::Search

Inherits:
Subcommand show all
Defined in:
lib/wikian/search.rb

Instance Attribute Summary

Attributes inherited from Subcommand

#api_url, #args, #config, #debug, #output_file, #query, #res, #res_body, #title

Instance Method Summary collapse

Methods inherited from Subcommand

#doit, #make_template, #non_opt_args, #response_file, #write_response

Constructor Details

#initialize(args) ⇒ Search

Returns a new instance of Search.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/wikian/search.rb', line 6

def initialize(args)
  super

  srsearch =  non_opt_args.join(' ')

  raise MissingSearchTermError if srsearch.empty?

  @params.merge!('srsearch' => srsearch, 'format' => Wikian::RESPONSE_FORMAT)

  @output_file = srsearch

  @query = @params.to_query

  @api_url = URI("https://#{config['meta']['site']}/w/api.php?#{query}")
rescue => e
  puts "#{e.class} in #{__FILE__}", e.message
  exit
end

Instance Method Details

#templateObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/wikian/search.rb', line 25

def template
  <<~eos
    # for a list of parameters to use here see: https://www.mediawiki.org/wiki/API:Search
    meta:
      site: en.wikipedia.org
      headers:
        user-agent: Wikian
    api:
      action:
        - query
      list:
        - search
      #srsearch: # text to search for. You can use multiple
      #  - Mr. Fixit
      #  - Term 2
  eos
end