Skip to content

Commit 47f5b72

Browse files
committed
updating ruby REST sample
1 parent c885c20 commit 47f5b72

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

ruby/Search/BingImageSearchv7.rb

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
ruby
21
require 'net/https'
32
require 'uri'
43
require 'json'
@@ -8,7 +7,7 @@
87
# **********************************************
98

109
# Replace the accessKey string value with your valid access key.
11-
accessKey = "enter key here"
10+
accessKey = "58620d3dcee1477ca2fbd886e23e545b"
1211

1312
# Verify the endpoint URI. At this writing, only one endpoint is used for Bing
1413
# search APIs. In the future, regional endpoints may be available. If you
@@ -18,7 +17,7 @@
1817
uri = "https://api.cognitive.microsoft.com"
1918
path = "/bing/v7.0/images/search"
2019

21-
term = "puppies"
20+
term = "tropical ocean"
2221

2322
if accessKey.length != 32 then
2423
puts "Invalid Bing Search API subscription key!"
@@ -37,13 +36,11 @@
3736
http.request(request)
3837
end
3938

40-
puts "\nRelevant Headers:\n\n"
41-
response.each_header do |key, value|
42-
# header names are coerced to lowercase
43-
if key.start_with?("bingapis-") or key.start_with?("x-msedge-") then
44-
puts key + ": " + value
45-
end
46-
end
47-
4839
puts "\nJSON Response:\n\n"
49-
puts JSON::pretty_generate(JSON(response.body))
40+
41+
parsed_json = JSON.parse(response.body)
42+
total_returned_images = parsed_json["totalEstimatedMatches"]
43+
first_result = parsed_json["value"][0]["thumbnailUrl"]
44+
45+
puts "total number of returned matches: #{total_returned_images}"
46+
puts "Url to the thumnail of the first returned search result: #{first_result}"

0 commit comments

Comments
 (0)