Class: BingAdsRubySdk::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/bing_ads_ruby_sdk/http_client.rb

Constant Summary collapse

HTTP_OPEN_TIMEOUT =
10
HTTP_READ_TIMEOUT =
20
HTTP_RETRY_COUNT_ON_TIMEOUT =
2
HTTP_INTERVAL_RETRY_COUNT_ON_TIMEOUT =
1
HTTP_ERRORS =
[ Net::HTTPServerError, Net::HTTPClientError ]

Class Method Summary collapse

Class Method Details

.close_http_connectionsObject



35
36
37
38
39
# File 'lib/bing_ads_ruby_sdk/http_client.rb', line 35

def close_http_connections
  self.http_connections.values.each do |connection|
    connection.reset
  end
end

.post(request) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bing_ads_ruby_sdk/http_client.rb', line 16

def post(request)
  uri = URI(request.url)
  conn = self.connection(request.url)
  raw_response = conn.post(
    path: uri.path,
    body: request.content,
    headers: request.headers,
  )

  if contains_error?(raw_response)
    BingAdsRubySdk.log(:warn) { BingAdsRubySdk::LogMessage.new(raw_response.body).to_s }
    raise BingAdsRubySdk::Errors::ServerError, raw_response.body
  else
    BingAdsRubySdk.log(:debug) { BingAdsRubySdk::LogMessage.new(raw_response.body).to_s }
  end

  raw_response.body
end