Permalink
Browse files

Initial Commit

  • Loading branch information...
0 parents commit 1fa91585b4bf2374f6569e94d833d3c580ea8aaf @mikedemers mikedemers committed Jun 9, 2009
Showing with 511 additions and 0 deletions.
  1. +6 −0 .gitignore
  2. +20 −0 LICENSE
  3. +92 −0 README.rdoc
  4. +59 −0 Rakefile
  5. 0 TODO
  6. +29 −0 bin/rbing
  7. +192 −0 lib/rbing.rb
  8. +35 −0 rbing.gemspec
  9. +14 −0 script/destroy
  10. +14 −0 script/generate
  11. +48 −0 spec/rbing_spec.rb
  12. +2 −0 spec/spec_helper.rb
@@ -0,0 +1,6 @@
+.DS_Store
+doc/
+tmp/
+log/
+pkg/
+*.swp
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 Mike Demers <mike_(at)_9astronauts.com>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,92 @@
+
+== RBing
+
+A gem that provides an interface to Microsoft's Bing search API.
+
+
+== Usage
+
+Get a App ID at: <http://www.bing.com/developers/createapp.aspx>
+
+ require 'rubygems'
+ require 'rbing'
+ bing = RBing.new("YOURAPPID")
+
+ rsp = bing.web("ruby")
+ puts rsp.web.results[0].title
+ => "Ruby (programming language) - Wikipedia, the free encyclopedia"
+
+ rsp = bing.web("ruby", :site => "github.com")
+ puts rsp.web.results[0].url
+ => "http://github.com/vim-ruby/vim-ruby/tree/master"
+
+ rsp = bing.web("ruby", :site => ["github.com", "rubyforge.org"])
+ puts rsp.web.results[0].url
+ => "http://rubyforge.org/"
+
+ rsp = bing.news("search engines")
+ puts rsp.web.results[0].title
+ => "Microsoft Bing more popular than Yahoo"
+
+ rsp = bing.spell("coincidance")
+ puts rsp.spell.results[0].value
+ => "coincidence"
+
+ rsp = bing.instant_answer("How many rods in a furlong?")
+ puts rsp.instant_answer.results[0].instant_answer_specific_data.encarta.value
+ => "1 furlong = 40 rods"
+
+
+== Command Line Utility
+
+RBing also has a simple command line interface.
+
+Put your App Id into $HOME/.rbing_app_id and you can use rbing:
+
+ $> rbing "ruby gems"
+ [{"Url"=>"http://rubygems.org/",
+ "Title"=>"RubyGems Manuals",
+ "CacheUrl"=>
+ "http://cc.bingj.com/cache.aspx?q=ruby+gems&d=76167709461212&w=39b024d8,55a87382",
+ "DisplayUrl"=>"rubygems.org",
+ "DateTime"=>Wed Jun 03 11:25:29 UTC 2009,
+ "Description"=>
+ "The Gem::Specification object controls the data..."},
+ ...
+ ]
+
+The default source is "web" but you can specify another:
+
+ $> rbing news "revolutionary technology"
+ [{"BreakingNews"=>0,
+ "Url"=>
+ "http://www.tmcnet.com/usubmit/-bt-successfully-completes-exchange-exchange-cisco-telepresence-call-/2009/06/04/4211245.htm",
+ "Source"=>"TMCnet",
+ "Title"=>
+ "BT Successfully Completes Exchange to Exchange Cisco TelePresence Call ... ",
+ "Snippet"=>
+ "BT Successfully Completes Exchange to Exchange Cisco TelePresence Call; Revolutionary...",
+ "Date"=>Thu Jun 04 13:33:09 UTC 2009},
+ ...
+ ]
+
+
+== Dependencies
+
+ * HTTParty: <http://httparty.rubyforge.org/>
+
+
+== Resources
+
+RBing:
+
+ * Source Code: <http://github.com/mikedemers/rbing/tree>
+ * Support: <http://github.com/mikedemers/rbing/issues>
+
+Bing:
+
+ * Bing API: <http://www.bing.com/developers>
+ * Register for App Id: <http://www.bing.com/developers/createapp.aspx>
+ * Bing API Reference: <http://msdn.microsoft.com/en-us/library/dd251056.aspx>
+ * Query Keywords: <http://help.live.com/help.aspx?project=wl_searchv1&market=en-US&querytype=keyword&query=redliub&tmt=&domain=www.bing.com:80>
+
@@ -0,0 +1,59 @@
+require 'rubygems' unless ENV['NO_RUBYGEMS']
+require 'rake/gempackagetask'
+require 'rubygems/specification'
+require 'date'
+require 'spec/rake/spectask'
+
+GEM = "rbing"
+GEM_VERSION = "1.0.0"
+AUTHOR = "Mike Demers"
+EMAIL = "mike@9astronauts.com"
+HOMEPAGE = "http://9astronauts.com/code/ruby/rbing"
+SUMMARY = "A gem that provides an interface to Microsoft's Bing search API"
+
+spec = Gem::Specification.new do |s|
+ s.name = GEM
+ s.version = GEM_VERSION
+ s.platform = Gem::Platform::RUBY
+ s.has_rdoc = true
+ s.extra_rdoc_files = ["README.rdoc", "LICENSE", 'TODO']
+ s.summary = SUMMARY
+ s.description = s.summary
+ s.author = AUTHOR
+ s.email = EMAIL
+ s.homepage = HOMEPAGE
+ s.rdoc_options = ["--main", "README.rdoc"]
+
+ s.add_dependency("httparty", [">= 0.4.0"])
+
+ s.require_path = 'lib'
+ s.autorequire = GEM
+ s.files = %w(LICENSE README.rdoc Rakefile TODO) + Dir.glob("{bin,lib,spec}/**/*")
+
+ s.executables = ["rbing"]
+end
+
+task :default => :spec
+
+desc "Run specs"
+Spec::Rake::SpecTask.new do |t|
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ t.spec_opts = %w(-fs --color)
+end
+
+
+Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.gem_spec = spec
+end
+
+desc "install the gem locally"
+task :install => [:package] do
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
+end
+
+desc "create a gemspec file"
+task :make_spec do
+ File.open("#{GEM}.gemspec", "w") do |file|
+ file.puts spec.to_ruby
+ end
+end
0 TODO
No changes.
@@ -0,0 +1,29 @@
+#!/usr/bin/env ruby
+
+require 'pp'
+require 'rubygems'
+require 'rbing'
+
+bing = RBing.new
+
+if query = ARGV[1]
+ source = ARGV[0]
+elsif query = ARGV[0]
+ source = "web"
+else
+ STDERR.puts "Usage: #{$0} [source] query"
+ STDERR.puts ""
+ STDERR.puts "Also, don't forget to put your App Id in $HOME/.rbing_app_id"
+ STDERR.puts ""
+ STDERR.puts "If you don't have an App Id, get one here: http://www.bing.com/developers"
+ STDERR.puts ""
+ exit
+end
+
+rsp = bing.search(source, query)
+
+begin
+ pp rsp.send(source).results
+rescue
+ pp rsp
+end
Oops, something went wrong.

0 comments on commit 1fa9158

Please sign in to comment.