class OpenRTB::Client::Queue

Public Class Methods

new(client, hydra) click to toggle source
# File lib/openrtb/client.rb, line 16
def initialize(client, hydra)
  @client = client
  @hydra  = hydra
end

Public Instance Methods

post(endpoint, body = {}) click to toggle source
# File lib/openrtb/client.rb, line 25
def post(endpoint, body = {})
  req = request(endpoint, :post, OpenRTB::Request.new(body))
  req.on_complete { |res| responses << res }

  @hydra.queue req
end
responses() click to toggle source
# File lib/openrtb/client.rb, line 21
def responses
  @responses ||= []
end

Private Instance Methods

options(hash = {}) click to toggle source
# File lib/openrtb/client.rb, line 42
def options(hash = {})
  hash[:proxy] = @client.proxy
  hash[:headers] ||= {}
  hash[:headers]['Content-Type'] = 'application/json'
  hash[:headers]['User-Agent']   = @client.user_agent
  hash[:headers]['x-openrtb-version'] = @client.version
  hash[:timeout] = 1
  hash[:connecttimeout]  = 1
  hash[:followlocation]  = false
  hash[:accept_encoding] = 'gzip'
  hash[:ssl_verifypeer]  = false
  hash[:ssl_verifyhost]  = 0
  hash
end
request(endpoint, method, body) click to toggle source
# File lib/openrtb/client.rb, line 34
def request(endpoint, method, body)
  uri = Addressable::URI.parse(Just(endpoint))
  opt = {body: MultiJson.dump(body), method: method}
  opt.merge!(userpwd: uri.userinfo) if uri.userinfo

  Typhoeus::Request.new(uri.omit(:userinfo).to_s, options(opt))
end