class BingAdsRubySdk::HttpClient

Constants

CONNECTION_SETTINGS
HTTP_ERRORS
HTTP_INTERVAL_RETRY_COUNT_ON_TIMEOUT
HTTP_OPEN_TIMEOUT
HTTP_READ_TIMEOUT
HTTP_RETRY_COUNT_ON_TIMEOUT

Attributes

http_connections[R]

Public Class Methods

close_http_connections() click to toggle source
# File lib/bing_ads_ruby_sdk/http_client.rb, line 46
def close_http_connections
  self.http_connections.values.each do |connection|
    connection.reset
  end
end
post(request) click to toggle source
# File lib/bing_ads_ruby_sdk/http_client.rb, line 27
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

Protected Class Methods

connection(host) click to toggle source
# File lib/bing_ads_ruby_sdk/http_client.rb, line 67
def connection(host)
  self.http_connections[host] ||= Excon.new(
    host,
    connection_settings
  )
end
connection_settings() click to toggle source
# File lib/bing_ads_ruby_sdk/http_client.rb, line 60
def connection_settings
  CONNECTION_SETTINGS.tap do |args|
    instrumentor = BingAdsRubySdk.config.instrumentor
    args[:instrumentor] = instrumentor if instrumentor
  end
end
contains_error?(response) click to toggle source
# File lib/bing_ads_ruby_sdk/http_client.rb, line 56
def contains_error?(response)
  HTTP_ERRORS.any? { |http_error_class| response.class <= http_error_class }
end