Class: Wikiwhat::Call
- Inherits:
-
Object
- Object
- Wikiwhat::Call
- Defined in:
- lib/wikiwhat/api_call.rb
Class Method Summary collapse
-
.call_api(title, options = {}) ⇒ Object
Make a string that is the URL for the API call for text-based requests.
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 |
# File 'lib/wikiwhat/api_call.rb', line 9 def self.call_api(title, ={}) title = URI::encode(title) [:prop] ? prop = "&prop=#{[:prop]}" : '' [:rvprop] ? rvprop = "&rvprop=content" : rvprop = '' [:img_list] ? img_list = "&generator=images" : img_list = '' [:iiprop] ? iiprop = "&iiprop=url" : iiprop = '' JSON.parse(RestClient.get "http://en.wikipedia.org/w/api.php?action=query#{prop}&titles=#{title}&format=json&redirects#{img_list}#{rvprop}#{iiprop}") end |