class OrientdbClient::HttpAdapters::TyphoeusAdapter

Public Instance Methods

request(method, url, options = {}) click to toggle source
# File lib/orientdb_client/http_adapters/typhoeus_adapter.rb, line 7
def request(method, url, options = {})
  req = prepare_request(method, url, options)
  response = run_request(req)
  if response.return_message == "Couldn't connect to server".freeze
    raise ConnectionError
  elsif response.timed_out?
    timed_out!(method, url)
  else
    return response
  end
end

Private Instance Methods

authentication_string(options) click to toggle source
# File lib/orientdb_client/http_adapters/typhoeus_adapter.rb, line 45
def authentication_string(options)
  username = options[:username] || @username
  password = options[:password] || @password
  "#{username}:#{password}"
end
extract_session_id(cookies) click to toggle source
# File lib/orientdb_client/http_adapters/typhoeus_adapter.rb, line 51
def extract_session_id(cookies)
  r = Regexp.new("#{SESSION_COOKIE_NAME}=([^\s;]+)")
  if cookies.is_a?(Array)
    return cookies.detect { |cookie| cookie.match(r) != nil }.
      match(r)[1]
  else
    return cookies.match(r)[1]
  end
end
prepare_request(method, url, options) click to toggle source
# File lib/orientdb_client/http_adapters/typhoeus_adapter.rb, line 21
def prepare_request(method, url, options)
  options = {
    userpwd: authentication_string(options),
    method: method
  }.merge(options)
  if timeout = @timeout || options[:timeout]
    options[:timeout] = timeout
  end
  Typhoeus::Request.new(url, options)
end
run_request(request) click to toggle source
# File lib/orientdb_client/http_adapters/typhoeus_adapter.rb, line 32
def run_request(request)
  request.run
  response = request.response
  if cookies = response.headers['Set-Cookie']
    @session_id = extract_session_id(cookies)
  end
  # TODO hacky, replace with response adpater object probably
  def response.content_type
    headers['Content-Type']
  end
  response
end