searchbing 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +2 -2
- data/lib/searchbing.rb +12 -6
- metadata +2 -2
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
searchbing [](https://travis-ci.org/rcullito/searchbing)
|
1
|
+
searchbing [](https://travis-ci.org/rcullito/searchbing) [](http://badge.fury.io/rb/searchbing)
|
2
2
|
=========
|
3
3
|
|
4
4
|
|
@@ -21,7 +21,7 @@ An account key is needed to use the Bing Search API. You can create a new accoun
|
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
-
- valid search types include: Image, Web, or Video. The first letter must be capitalized
|
24
|
+
- valid search types include: Image, Web, News or Video. The first letter must be capitalized
|
25
25
|
|
26
26
|
- this gem relies on the open-uri, net/http, and json gems.
|
27
27
|
|
data/lib/searchbing.rb
CHANGED
@@ -6,23 +6,25 @@ require 'net/http'
|
|
6
6
|
# Before proceeding you will need an account key, which can be obtained by registering an accout at http://windows.microsoft.com/en-US/windows-live/sign-in-what-is-microsoft-account
|
7
7
|
class Bing
|
8
8
|
# Create a new object of the bing class
|
9
|
-
# >> bing_image = Bing.new('your_account_key_goes_here', 10, 'Image')
|
10
|
-
# => #<Bing:0x9d9b9f4 @account_key="your_account_key", @num_results=10, @type="Image">
|
9
|
+
# >> bing_image = Bing.new('your_account_key_goes_here', 10, 'Image', {:Adult => 'Strict'})
|
10
|
+
# => #<Bing:0x9d9b9f4 @account_key="your_account_key", @num_results=10, @type="Image", @params={:Adult => 'Strict'}>
|
11
11
|
# Arguments:
|
12
12
|
# account_key: (String)
|
13
13
|
# num_results: (Integer)
|
14
14
|
# type: (String)
|
15
|
+
# params: (Hash)
|
15
16
|
|
16
|
-
def initialize(account_key, num_results, type)
|
17
|
+
def initialize(account_key, num_results, type, params = {})
|
17
18
|
|
18
19
|
@account_key = account_key
|
19
20
|
@num_results = num_results
|
20
21
|
@type = type
|
22
|
+
@params = params
|
21
23
|
|
22
24
|
|
23
25
|
end
|
24
26
|
|
25
|
-
attr_accessor :account_key, :num_results, :type
|
27
|
+
attr_accessor :account_key, :num_results, :type, :params
|
26
28
|
|
27
29
|
# Search for a term, the result is an array of hashes with the result data
|
28
30
|
# >> bing_image.search("puffin", 25)
|
@@ -32,13 +34,17 @@ class Bing
|
|
32
34
|
# offset: (Integer)
|
33
35
|
|
34
36
|
def search(search_term, offset = 0)
|
35
|
-
|
37
|
+
|
36
38
|
user = ''
|
37
39
|
web_search_url = "https://api.datamarket.azure.com/Bing/Search/v1/Composite?Sources="
|
38
40
|
sources_portion = URI.encode_www_form_component('\'' + @type + '\'')
|
39
41
|
query_string = '&$format=json&Query='
|
40
42
|
query_portion = URI.encode_www_form_component('\'' + search_term + '\'')
|
41
43
|
params = "&$top=#{@num_results}&$skip=#{offset}"
|
44
|
+
@params.each do |k,v|
|
45
|
+
params << "&#{k.to_s}=\'#{v.to_s}\'"
|
46
|
+
end
|
47
|
+
|
42
48
|
full_address = web_search_url + sources_portion + query_string + query_portion + params
|
43
49
|
|
44
50
|
uri = URI(full_address)
|
@@ -46,7 +52,7 @@ class Bing
|
|
46
52
|
req.basic_auth user, account_key
|
47
53
|
|
48
54
|
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https'){|http|
|
49
|
-
|
55
|
+
http.request(req)
|
50
56
|
}
|
51
57
|
|
52
58
|
body = JSON.parse(res.body, :symbolize_names => true)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: searchbing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -41,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
41
|
version: '0'
|
42
42
|
requirements: []
|
43
43
|
rubyforge_project:
|
44
|
-
rubygems_version: 1.8.
|
44
|
+
rubygems_version: 1.8.23
|
45
45
|
signing_key:
|
46
46
|
specification_version: 3
|
47
47
|
summary: compatible with the recent azure migration,use bing's search api in your
|