Last active
December 15, 2015 00:49
-
-
Save thinkphp/5176095 to your computer and use it in GitHub Desktop.
An interface that provides Bing Search using Sinatra.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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