searchbing 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/searchbing.rb +21 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGU0NzM5ODZkNmMyOTA2YjBiZDEyMzY4OTUzMDIxZWMxYjkxNzI4NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
N2I1NzUyOWEyNzIxNGI2Y2VmMmZjOWNjNmQzMjNlODc0NjVhM2M0Yg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjlmZDY1NDE5NTM5YjRjZDNkMGRmZTQwOWQ3MTczZDUwMzFkNWU5NmI1ZTJl
|
10
|
+
ZmI0MWQwZGJiYjMwMzI2MWY2YWRkYThhZWEwZGRlOTJjNzE1YzQwZjYyY2Jj
|
11
|
+
YzYyNTJlOTNkODQzYjYyMGFkZjM5MGVjMjg1ODdjMzNmNDg2NmQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTI5NzU3NGUzNmIwZGI1MGFmOGQ0MGJmYjQ5MzY5ZWVhZjM5NWI2Mjc2OTVk
|
14
|
+
MGJjZTVjYTdjNjZjMmIwZTk1OTZmYzg5NTRmZWYzMzU3NmY5OWY1M2IxZDc1
|
15
|
+
YzBlNTQwZDU5ZWJhYjMyMWRhMzJiYThjZjlmMzg4YmFmMTNhN2M=
|
data/lib/searchbing.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
class Bing
|
2
|
+
# Create a new object of the bing class
|
3
|
+
# >> animals = Bing.new('your_account_key_goes_here', 10, 'Image')
|
4
|
+
# => #<Bing:0x9d9b9f4 @accountKey="your_account_key", @num_results=10, @type="Image">
|
5
|
+
# Arguments:
|
6
|
+
# account_key: (String)
|
7
|
+
# num_results: (Integer)
|
8
|
+
# type: (String)
|
9
|
+
|
2
10
|
def initialize(accountKey, num_results, type)
|
11
|
+
|
3
12
|
@accountKey = accountKey
|
4
13
|
@num_results = num_results
|
5
14
|
@type = type
|
@@ -7,14 +16,22 @@ class Bing
|
|
7
16
|
|
8
17
|
attr_accessor :accountKey, :num_results, :type
|
9
18
|
|
19
|
+
# Search for a term
|
20
|
+
# >> animals.search("lion")
|
21
|
+
# => #<Bing:0x9d9b9f4 @accountKey="your_account_key", @num_results=10, @type="Image">
|
22
|
+
# Arguments:
|
23
|
+
# search_term: (String)
|
24
|
+
# => "{\"d\":{\"results\":[{\"__metadata\":{\"uri\":\"https://api.datamarket....
|
25
|
+
|
10
26
|
def search(search_term)
|
27
|
+
|
11
28
|
user = ''
|
12
29
|
web_search_url = "https://api.datamarket.azure.com/Bing/Search/#{type}?$format=json&Query="
|
13
|
-
|
14
|
-
|
15
|
-
|
30
|
+
query_portion = URI.encode_www_form_component('\'' + search_term + '\'')
|
31
|
+
params = "&$top=#{@num_results}"
|
32
|
+
full_address = web_search_url + query_portion + params
|
16
33
|
|
17
|
-
uri = URI(
|
34
|
+
uri = URI(full_address)
|
18
35
|
req = Net::HTTP::Get.new(uri.request_uri)
|
19
36
|
req.basic_auth user, accountKey
|
20
37
|
|