Sha256: 494e5670c3353010d4b45bef8abf45e0686fe6faea8e9cc9522331e807d131cd
Contents?: true
Size: 1.01 KB
Versions: 1
Compression:
Stored size: 1.01 KB
Contents
require 'open-uri' require 'rest_client' require 'json' module Wikiwhat class Call # Make a string that is the URL for the API call for text-based requests. # Call the API and parse the returning JSON object. 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 end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
wikiwhat-0.1.0 | lib/wikiwhat/api_call.rb |