Class: Bing::Ads::API::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/bing/ads/api/http_client.rb

Overview

Bing::Ads::API::HttpClient

Constant Summary collapse

API_CALL_RETRY_COUNT =
3

Class Method Summary collapse

Class Method Details

.download(url, retry_count = API_CALL_RETRY_COUNT) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/bing/ads/api/http_client.rb', line 8

def self.download(url, retry_count = API_CALL_RETRY_COUNT)
  1.upto(retry_count + 1) do |retry_index|
    response = Net::HTTP.get_response(URI(url))
    if response.is_a?(Net::HTTPSuccess)
      break response.body
    else
      next if retry_index <= retry_count
      raise Bing::Ads::API::Errors::DownloadError, "#{response.code} #{response.msg}"
    end
  end
end