def send!(method, json, max_retry=3)
    if max_retry == 0
      raise SugarCRM::RetryLimitExceeded, "SugarCRM::Connection Errors: \n#{@errors.reverse.join "\n\s\s"}"
    end
    @request  = SugarCRM::Request.new(@url, method, json, @options[:debug])
    # Send Ze Request
    begin
      if @request.length > 3900
        @response = @connection.post(@url.path, @request)
      else
        @response = @connection.get(@url.path.dup + "?" + @request.to_s)
      end
      return handle_response
    # Timeouts are usually a server side issue
    rescue Timeout::Error => error
      @errors << error
      send!(method, json, max_retry.pred)
    # Lower level errors requiring a reconnect
    rescue Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE, EOFError => error
      @errors << error
      reconnect!
      send!(method, json, max_retry.pred)
    # Handle invalid sessions
    rescue SugarCRM::InvalidSession => error
      @errors << error
      old_session = @sugar_session_id.dup
      login!
      # Update the session id in the request that we want to retry.
      json.gsub!(old_session, @sugar_session_id)
      send!(method, json, max_retry.pred)
    end    
  end
def send!(method, json, max_retry=3)
    if max_retry == 0
      raise SugarCRM::RetryLimitExceeded, "SugarCRM::Connection Errors: \n#{@errors.reverse.join "\n\s\s"}"
    end
    @request  = SugarCRM::Request.new(@url, method, json, @options[:debug])
    # Send Ze Request
    begin
      if @request.length > 3900
        @response = @connection.post(@url.path, @request)
      else
        @response = @connection.get(@url.path.dup + "?" + @request.to_s)
      end
      return handle_response
    # Timeouts are usually a server side issue
    rescue Timeout::Error => error
      @errors << error
      send!(method, json, max_retry.pred)
    # Lower level errors requiring a reconnect
    rescue Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE, EOFError => error
      @errors << error
      reconnect!
      send!(method, json, max_retry.pred)
    # Handle invalid sessions
    rescue SugarCRM::InvalidSession => error
      @errors << error
      old_session = @sugar_session_id.dup
      login!
      # Update the session id in the request that we want to retry.
      json.gsub!(old_session, @sugar_session_id)
      send!(method, json, max_retry.pred)
    end    
  end
Send a request to the Sugar Instance