Sha256: 2eb656fe5f81ff6d70de63c9c88aee7e046f2814ec31b19c3d8e1c43d2573133
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
require 'cgi' require 'open-uri' require 'ostruct' require 'rubygems' require 'json' require 'google_ajax/feed' require 'google_ajax/language' require 'google_ajax/parser' require 'google_ajax/search' require 'google_ajax/version' class GoogleAjax API_BASE = 'http://ajax.googleapis.com/ajax/services/' @@api_key = @@referer = nil def self.api_key @@api_key end def self.api_key=(key) @@api_key = key end def self.referer @@referer end def self.referer=(referer) @@referer = referer end # TODO: Pass query to parser, so it knows where it came from. Needed for search paging and useful in general. def self.get(api, method, query, args = nil) raise "You must assign a value to GoogleAjax.referer" unless @@referer url = "#{API_BASE}#{api}/" url += "#{method}?" url += "&q=#{CGI::escape(query)}" url += "&key=" if @@api_key url += "&" + args.collect {|key, value| "#{key}=#{value}"}.join('&') if args && !args.empty? data = open(url, "Referer" => @@referer).read Parser.parse(api, method, data) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
googleajax-0.1.0 | lib/google_ajax.rb |