Class: Wikiwhat::Call

Inherits:
Object
  • Object
show all
Defined in:
lib/wikiwhat/api_call.rb

Class Method Summary collapse

Class Method Details

.call_api(title, options = {}) ⇒ Object

Make a string that is the URL for the API call for text-based requests. Call the API and parse the returning JSON object.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/wikiwhat/api_call.rb', line 9

def self.call_api(title, options={})
  title = URI::encode(title)
  options[:prop] ? prop = "&prop=#{options[:prop]}" : ''
  options[:rvprop] ? rvprop = "&rvprop=content" : rvprop = ''
  options[:img_list] ? img_list = "&generator=images" : img_list = ''
  options[:iiprop] ? iiprop = "&iiprop=url" : iiprop = ''
  options[:inprop] ? inprop = "&inprop=url" : inprop = ''
  options[:iiurlwidth] ? iiurlwidth = "&iiurlwidth=#{options[:iiurlwidth]}" : iipropwidth = ''
  options[:iiurlheight] ? iiurlheight = "&iiurlheight=#{options[:iiurlheight]}" : iipropheight = ''


  JSON.parse(RestClient.get "http://en.wikipedia.org/w/api.php?action=query#{prop}&titles=#{title}&format=json&redirects#{img_list}#{rvprop}#{iiprop}#{iiurlwidth}#{iiurlheight}#{inprop}")
end