def import(csv, type, block_until_completed = false)
      csv = File.open(csv, 'rb') unless csv.respond_to?(:path) && csv.respond_to?(:read)
      data, headers = Itrp::Multipart::Post.prepare_query(type: type, file: csv)
      request = Net::HTTP::Post.new(expand_path('/import'), expand_header(headers))
      request.body = data
      response = _send(request)
      @logger.info { "Import file '#{csv.path}' successfully uploaded with token '#{response[:token]}'." } if response.valid?

      if block_until_completed
        raise ::Itrp::UploadFailed.new("Failed to queue #{type} import. #{response.message}") unless response.valid?
        token = response[:token]
        while true
          response = get("/import/#{token}")
          unless response.valid?
            sleep(5)
            response = get("/import/#{token}") # single retry to recover from a network error
            raise ::Itrp::Exception.new("Unable to monitor progress for #{type} import. #{response.message}") unless response.valid?
          end
          # wait 30 seconds while the response is OK and import is still busy
          break unless ['queued', 'processing'].include?(response[:state])
          @logger.debug { "Import of '#{csv.path}' is #{response[:state]}. Checking again in 30 seconds." }
          sleep(30)
        end
      end

      response
    end
def import(csv, type, block_until_completed = false)
      csv = File.open(csv, 'rb') unless csv.respond_to?(:path) && csv.respond_to?(:read)
      data, headers = Itrp::Multipart::Post.prepare_query(type: type, file: csv)
      request = Net::HTTP::Post.new(expand_path('/import'), expand_header(headers))
      request.body = data
      response = _send(request)
      @logger.info { "Import file '#{csv.path}' successfully uploaded with token '#{response[:token]}'." } if response.valid?

      if block_until_completed
        raise ::Itrp::UploadFailed.new("Failed to queue #{type} import. #{response.message}") unless response.valid?
        token = response[:token]
        while true
          response = get("/import/#{token}")
          unless response.valid?
            sleep(5)
            response = get("/import/#{token}") # single retry to recover from a network error
            raise ::Itrp::Exception.new("Unable to monitor progress for #{type} import. #{response.message}") unless response.valid?
          end
          # wait 30 seconds while the response is OK and import is still busy
          break unless ['queued', 'processing'].include?(response[:state])
          @logger.debug { "Import of '#{csv.path}' is #{response[:state]}. Checking again in 30 seconds." }
          sleep(30)
        end
      end

      response
    end
upload a CSV file to import
 @param csv: The CSV File or the location of the CSV file
 @param type: The type, e.g. person, organization, people_contact_details
 @raise Itrp::UploadFailed in case the file could was not accepted by ITRP and +block_until_completed+ is +true+
 @raise Itrp::Exception in case the import progress could not be monitored