searchbing 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +12 -2
- data/lib/searchbing.rb +11 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTE3Y2VmNDhmM2M1MmNhMDZiZDgwYjc5ODYyNzE1NWY3YjgyMzg3OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
N2Q4ZTFiMTRkOTA2ODBjOTI5MWJlZTdlODgzNDkzODE1N2NlZmZkOA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTZkZmQ2MmFmNzAzMWEwOTkxMWU4N2RiNzMxMjY0ZjNlNDVhNDEzOTVjZWEy
|
10
|
+
NDUyOTY0ZTIxYjIxNjg3ZTkzMGYyZGYyNjFiNDE1ZGQ2NGY1ODllNDFhM2M1
|
11
|
+
YjlmZGVjOThmZDU0ZmM5NzA1Mjc4ZDQxMTg2ODBiYzlmNTNjM2U=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTNjZDFhZjgwNzdlZjQ2MWJkOThkNTY5NTVlMGMwNzU5ZjhiNDg2ZmQ3MTNm
|
14
|
+
ZWEzNTc0ZTkxYjliNzE4MGFjMjQzMmIyOGQ2MTFiMDRkMDhlZTFiMTk1MGYz
|
15
|
+
NDViYWEzMmI2NmNiOWI3YzE0NmVmY2MyY2UwZGU4ZmY5ZDM2MDg=
|
data/README.md
CHANGED
@@ -9,6 +9,16 @@ Usage
|
|
9
9
|
|
10
10
|
Example
|
11
11
|
===============
|
12
|
-
1.
|
12
|
+
1. Create a new search object
|
13
|
+
|
14
|
+
animals = Bing.new('your_account_key_goes_here', 10, 'Image')
|
15
|
+
|
16
|
+
2. Retrieve the results for a given term
|
17
|
+
|
18
|
+
bing_results = animals.search("lion")
|
19
|
+
|
20
|
+
3. parse the result set depending on what you would like to retrive
|
21
|
+
|
22
|
+
puts result_set[0]["MediaUrl"] # puts url of fullsize image
|
23
|
+
puts result_set[0]["Thumbnail"]["MediaUrl"] # puts url of thumbnail
|
13
24
|
|
14
|
-
2. animals.search("lion")
|
data/lib/searchbing.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'net/http'
|
4
|
+
|
1
5
|
# The Bing Class provides the ability to connect to the bing search api hosted on the windows azure marketplace.
|
2
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
|
3
7
|
class Bing
|
@@ -14,13 +18,15 @@ class Bing
|
|
14
18
|
@account_key = account_key
|
15
19
|
@num_results = num_results
|
16
20
|
@type = type
|
21
|
+
|
22
|
+
|
17
23
|
end
|
18
24
|
|
19
25
|
attr_accessor :account_key, :num_results, :type
|
20
26
|
|
21
|
-
# Search for a term
|
27
|
+
# Search for a term, the result is an array of hashes with the result data
|
22
28
|
# >> animals.search("lion")
|
23
|
-
# =>
|
29
|
+
# => [{"__metadata"=>{"uri"=>"https://api.datamarket.azure.com/Data.ashx/Bing/Search/Image?Query='lion'&$skip=0&$top=1", "type"=>"Image
|
24
30
|
# Arguments:
|
25
31
|
# search_term: (String)
|
26
32
|
|
@@ -40,7 +46,7 @@ class Bing
|
|
40
46
|
http.request(req)
|
41
47
|
}
|
42
48
|
|
43
|
-
res.body
|
44
|
-
|
49
|
+
body = JSON.parse(res.body)
|
50
|
+
result_set = body["d"]["results"]
|
45
51
|
end
|
46
|
-
end
|
52
|
+
end
|