Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Last active December 15, 2015 00:49
Show Gist options
  • Select an option

  • Save thinkphp/5176095 to your computer and use it in GitHub Desktop.

Select an option

Save thinkphp/5176095 to your computer and use it in GitHub Desktop.
An interface that provides Bing Search using Sinatra.
class MyApp < Sinatra::Base
get '/' do
@title = "Home"
erb:index
end
get '/search' do
@title = "search"
erb:search
end
get '/search/:n' do
@q = params[:n]
bing = Bing.new('49EB4B94127F7C7836C96DEB3F2CD8A6D12BDB71')
results = bing.search(q=@q,sources='web')
@title = "Bing"
out = '<ol>'
results['SearchResponse']['Web']['Results'].each do |item|
out = out + '<li><h4><a target="_blank" href="'+ item['Url'] +'">' + item['Title'] + '</a></h4><p>'+ item['Description'] +'</p></li>'
end
out = out + '</ol>'
@what = out;
erb:search
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment