diff --git a/ruby/Search/BingImageSearchv7.rb b/ruby/Search/BingImageSearchv7.rb index 7bc1ad6..04f0bec 100644 --- a/ruby/Search/BingImageSearchv7.rb +++ b/ruby/Search/BingImageSearchv7.rb @@ -14,7 +14,7 @@ # encounter unexpected authorization errors, double-check this value against # the endpoint for your Bing Search instance in your Azure dashboard. -uri = "https://api.cognitive.microsoft.com" +uri = URI("https://api.cognitive.microsoft.com") path = "/bing/v7.0/images/search" term = "tropical ocean" @@ -25,16 +25,14 @@ abort end -uri = URI(uri + path + "?q=" + URI.escape(term)) - +uri = URI(uri + path + "?q=" + URI::Escape.escape(term)) + puts "Searching images for: " + term request = Net::HTTP::Get.new(uri) request['Ocp-Apim-Subscription-Key'] = accessKey -response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| - http.request(request) -end +response = Net::HTTP.get_response(uri) puts "\nJSON Response:\n\n" @@ -43,4 +41,4 @@ first_result = parsed_json["value"][0]["thumbnailUrl"] puts "total number of returned matches: #{total_returned_images}" -puts "Url to the thumnail of the first returned search result: #{first_result}" \ No newline at end of file +puts "Url to the thumnail of the first returned search result: #{first_result}"