simple_bing 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/simple_bing.rb +44 -0
  2. metadata +76 -0
@@ -0,0 +1,44 @@
1
+ require 'rubygems'
2
+ require 'net/http'
3
+ require 'json'
4
+ require 'uri'
5
+
6
+ # The main SimpleBing driver
7
+ class SimpleBing
8
+ attr_accessor :api_key
9
+
10
+ API = "http://api.bing.net/json.aspx"
11
+
12
+ # Create a new instance of SimpleBing with your Bing Search API key
13
+ #
14
+ # Example:
15
+ # >> require 'simple_bing'
16
+ # => true
17
+ # >> bing = SimpleBing.new('YOUR API KEY')
18
+ # => #<SimpleBing:0x0000010181aa18 @api_key="YOUR API KEY">
19
+
20
+ # Arguments:
21
+ # api_key: (String)
22
+
23
+ def initialize(api_key)
24
+ @api_key = api_key
25
+ end
26
+
27
+ # Make a web search for 'elections'
28
+ #
29
+ # Example:
30
+ # >> bing.search(query='elections', sources='web')
31
+ # => {"SearchResponse"=>{"Version"=>"2.2", "Query"=>{"SearchTerms"=>"elections"}, "Web"=>{"Total"=>327000000 etc.
32
+
33
+ # Arguments:
34
+ # query: (String)
35
+ # sources: (String)
36
+ # optional_args: (Hash)
37
+
38
+ def search(query="",sources="", optional_args=nil)
39
+ params = {"query" => query, "sources" => sources}
40
+ params.merge!(optional_args) if optional_args
41
+ params = URI.encode_www_form(params)
42
+ return JSON.parse(Net::HTTP.get(URI("#{API}?Appid=#{@api_key}&#{params}")))
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_bing
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Matthew Lagace
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-02-09 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.6.3
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: json
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - "="
33
+ - !ruby/object:Gem::Version
34
+ version: 1.6.3
35
+ type: :development
36
+ version_requirements: *id002
37
+ description: A lightweight API wrapper for the Bing Search API
38
+ email: matthewlagace@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - lib/simple_bing.rb
47
+ homepage: http://rubygems.org/gems/simple_bing
48
+ licenses:
49
+ - MIT
50
+ post_install_message:
51
+ rdoc_options: []
52
+
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ requirements: []
68
+
69
+ rubyforge_project:
70
+ rubygems_version: 1.8.12
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: SimpleBing
74
+ test_files: []
75
+
76
+ has_rdoc: