Class: Oldskool::GcseHandler
- Inherits:
-
Object
- Object
- Oldskool::GcseHandler
- Defined in:
- lib/oldskool/gcse_handler.rb
Instance Method Summary collapse
- #handle_request(keyword, query) ⇒ Object
-
#initialize(params, keyword, config) ⇒ GcseHandler
constructor
A new instance of GcseHandler.
- #plugin_template(template) ⇒ Object
Constructor Details
#initialize(params, keyword, config) ⇒ GcseHandler
Returns a new instance of GcseHandler.
3 4 5 6 7 8 |
# File 'lib/oldskool/gcse_handler.rb', line 3 def initialize(params, keyword, config) @params = params @keyword = keyword @config = config self end |
Instance Method Details
#handle_request(keyword, query) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/oldskool/gcse_handler.rb', line 14 def handle_request(keyword, query) gcse = GCSE.new(@config[:google_api_key], @keyword[:cx]) if @params["page"] @params["page"] = Integer(@params["page"]) else @params["page"] = 1 end args = {:start => ((@params["page"] - 1) * 10 + 1)} gcse.search @params[:q], args escaped = URI.escape((query || keyword)) = [{:title => "Google", :url => "https://google.com/search?q=#{escaped}"}, {:title => "Images", :url => "https://google.com/search?q=#{escaped}&tbm=isch"}, {:title => "Videos", :url => "https://google.com/search?q=#{escaped}&tbm=vid"}] {:template => plugin_template(:gcse), :gcse => gcse, :sidemenu => } end |
#plugin_template(template) ⇒ Object
10 11 12 |
# File 'lib/oldskool/gcse_handler.rb', line 10 def plugin_template(template) File.read(File.("../../../views/#{template}.erb", __FILE__)) end |