overlord¶ ↑
Talk to the Google ajax apis and render the results. This gem contains several method calls and partials to call out to the Google Ajax Apis (code.google.com/apis/ajax/). This gem is designed to work in Ruby on Rails and currently won’t work outside that framework.
Usage¶ ↑
Installation¶ ↑
Installing the gem should install the dependencies
sudo gem install overlord
In case it doesn’t install dependencies:
sudo gem install httparty sudo gem install crack
Settings¶ ↑
This gem requires some configuration before it will work in your Rails application: You will need an initializer file with ‘google_ajax_api_key’ and ‘request_referer’ defined. You can set it up thus:
In initializers/overlord.rb
Overlord.configure do |config| config.google_ajax_api_key = '' # A google ajax api key - http://code.google.com/apis/ajaxsearch/signup.html config.request_referer = '' # The url of the site making the request. config.show_google_search = true # Determines whether or not a google search is displayed on the topic page config.load_feeds_on_server = false # Determines whether feeds on a topic page are loaded on the server or the client. Loading on the server can take a while config.combine_feeds_on_server = false # Combines feeds loaded on the server config.google_ad_partner_pub # Ad partner id (optional) used for 'searchControl.enableAds' end
Models¶ ↑
If you want to use the methods ‘convert_google_feed_json_to_feed’, ‘convert_google_find_feeds_json_to_feeds’, and ‘convert_google_feed_json_to_entries’ you will also need a Feed, Service and Entry class with specific attributes. See the rails application inside of the test directory for more information on how to create these classes.
# Required attributes: # :uri, :service_id, :display_uri, :title, :service class Feed < ActiveRecord::Base end # tag_list can be from one of the various acts_as_taggable gems. # Required attributes: # :permalink, :author, :title, :description, :content, :published_at, :tag_list, :direct_link, :feed class Entry < ActiveRecord::Base end class Service < ActiveRecord::Base # Selects and caches all services from the database. # # refresh_services: By default all tag services are cached. Setting this value to true # will result in the values being repopulated from the database def self.get_services(refresh_services = false) @all_services = nil if refresh_services @all_services ||= Service.all end # Attempts to find a service object using a uri # # uri: Uri to search for. This method will attempt to all services for any part of the provided uri. # refresh_services: Forces a refresh of the services. By default the services are cached for the duration of the request. def self.find_service_by_uri(uri, refresh_services = false) service = get_services(refresh_services).detect { |service| service.uri && service.uri.length > 0 && (uri.include?(service.uri) || service.uri.include?(uri)) } service ||= default_service service end end create_table "entries", :force => true do |t| t.integer "feed_id", :null => false t.string "permalink", :limit => 2083, :default => "", :null => false t.string "author", :limit => 2083 t.text "title", :null => false t.text "description" t.text "content" t.datetime "published_at", :null => false t.string "direct_link", :limit => 2083 end create_table "feeds", :force => true do |t| t.string "uri", :limit => 2083 t.string "display_uri", :limit => 2083 t.string "title", :limit => 1000 t.integer "service_id", :default => 0 t.string "login" end create_table "services", :force => true do |t| t.string "uri", :limit => 2083, :default => "" t.string "name", :limit => 1000, :default => "" t.string "api_uri", :limit => 2083, :default => "" t.string "uri_key" end
Testing¶ ↑
If you want to run the test application you will need to add a file with your google credentials Create a file ‘test/rails_test/config.googl.yml’
default: &DEFAULT google_ajax_api_key: 'YOUR GOOGLE AJAX API KEY from http://code.google.com/apis/ajaxsearch/signup.html' request_referer: 'www.example.com' development: <<: *DEFAULT test: <<: *DEFAULT
Copyright¶ ↑
Copyright © 2009-2010 Tatemae.com. See LICENSE for details.