Module: UrlFormatter

Defined in:
lib/wiki_fetch/url_formatter.rb

Class Method Summary collapse

Class Method Details

.create_url(options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/wiki_fetch/url_formatter.rb', line 4

def self.create_url(options)
  format = options[:format] || "json"
  case options[:method]
  when "search_title"
    query = options[:options][:action] || "query"
    extracts = options[:options][:prop] || "extracts"
    exsentences = (options[:options][:exsentences] || 10).to_i
    return "#{$wiki_base_url}?format=#{format}&action=#{query}&prop=#{extracts}&exsentences=#{exsentences}&titles=#{options[:name]}"  
  when "search_suggestions"
    query = options[:options][:action] || "opensearch"
    limit = (options[:options][:limit] || 10).to_i
    namespace = (options[:options][:namespace] || 0).to_i
    return "#{$wiki_base_url}?action=#{query}&search=#{options[:name]}&limit=#{limit}&namespace=#{namespace}&format=#{format}"
  else
    puts "You gave me -- I have no idea what to do with that."
  end
end