Method: Wikiwhat::Call.call_api
- Defined in:
- lib/wikiwhat/api_call.rb
.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, ={}) title = URI::encode(title) [:prop] ? prop = "&prop=#{options[:prop]}" : '' [:rvprop] ? rvprop = "&rvprop=content" : rvprop = '' [:img_list] ? img_list = "&generator=images" : img_list = '' [:iiprop] ? iiprop = "&iiprop=url" : iiprop = '' [:inprop] ? inprop = "&inprop=url" : inprop = '' [:iiurlwidth] ? iiurlwidth = "&iiurlwidth=#{options[:iiurlwidth]}" : iipropwidth = '' [: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 |