Sha256: 73e6d948ae7c6e38f52d359501205d52175b29a361d0b625a8932d3d1fd30bfa
Contents?: true
Size: 1.92 KB
Versions: 7
Compression:
Stored size: 1.92 KB
Contents
# Google ajax feed api reference: # http://code.google.com/apis/ajaxfeeds/documentation/reference.html # # Google code playground: # http://code.google.com/apis/ajax/playground/?exp=search#load_feed # class GoogleFeedRequest include HTTParty format :json # Initialize Google Request. # Parameters: # api_key_id: Valid Google access key (optional) def initialize(api_key_id = nil) @api_key_id = api_key_id end def self.lookup_feed(uri) get('http://ajax.googleapis.com/ajax/services/feed/lookup', :query => build_google_query({:q => uri})) end def self.load_feed(uri) get('http://ajax.googleapis.com/ajax/services/feed/load', :query => build_google_query({:q => uri})) end # Search for feeds using google. This will return # a collection of 'Feed' objects def self.find_feeds(query) query = query.join('+') if query.is_a?(Array) feed_response = find_google_feeds(query) if 200 == feed_response['responseStatus'] convert_google_json_to_feeds(feed_response) else [] end end # Search for feeds using google. This will return # a hash with the results def self.find_google_feeds(query) get('http://ajax.googleapis.com/ajax/services/feed/find', :query => build_google_query({:q => query})) end # convert the result of a google query to 'Feed' objects def self.convert_google_json_to_feeds(google_feeds) google_feeds['responseData']['entries'].collect do |google_feed| Feed.new( :uri => google_feed['url'], :display_uri => google_feed['link'], :title => google_feed['title'], :service_id => Service.find_service_by_uri(google_feed['link']).id) end end # Add standard items to the google query def self.build_google_query(query_options) query_options[:v] = '1.0' query_options[:key] = GlobalConfig.google_ajax_api_key if GlobalConfig.google_ajax_api_key query_options end end
Version data entries
7 entries across 7 versions & 1 rubygems