import method

Future<Map<String, dynamic>> import(
  1. dynamic data,
  2. {ImportType type = ImportType.auto,
  3. OnDuplicateType onDuplicate,
  4. String fromPrefix,
  5. String toPrefix,
  6. bool overwrite,
  7. bool waitForSync,
  8. bool complete,
  9. bool details}
)

Implementation

Future<Map<String, dynamic>> import(
  dynamic data, {
  ImportType type = ImportType.auto,
  OnDuplicateType onDuplicate,
  String fromPrefix,
  String toPrefix,
  bool overwrite,
  bool waitForSync,
  bool complete,
  bool details,
}) async {
  if (data is List) {
    data = data.map(json.encode).join('\r\n') + '\r\n';
  }

  final resp = await _connection.request(
    method: 'POST',
    path: '/_api/import',
    body: data,
    isBinary: true,
    queries: {
      if (type != null) 'type': type.toString(),
      if (fromPrefix != null) 'fromPrefix': fromPrefix,
      if (toPrefix != null) 'toPrefix': toPrefix,
      if (overwrite != null) 'overwrite': overwrite.toString(),
      if (waitForSync != null) 'waitForSync': waitForSync.toString(),
      if (onDuplicate != null) 'onDuplicate': onDuplicate.toString(),
      if (complete != null) 'complete': complete.toString(),
      if (details != null) 'details': details.toString(),
      'collection': name
    },
  );

  return resp.body;
}