1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-25 22:39:22 +00:00
comunicmobile/lib/models/api_request.dart

40 lines
1.1 KiB
Dart

import 'dart:io';
import 'package:comunic/helpers/api_helper.dart';
import 'package:comunic/models/api_response.dart';
import 'package:meta/meta.dart';
/// API Request model
///
/// Contains all the information associated to an API request
///
/// @author Pierre HUBERT
class APIRequest {
final String uri;
final bool needLogin;
Map<String, String> args;
Map<String, File> files = Map();
APIRequest({@required this.uri, this.needLogin = false, this.args})
: assert(uri != null),
assert(needLogin != null) {
if (this.args == null) this.args = Map();
}
void addString(String name, String value) => args[name] = value;
void addInt(String name, int value) => args[name] = value.toString();
void addBool(String name, bool value) =>
args[name] = value ? "true" : "false";
void addFile(String name, File file) => files[name] = file;
/// Execute the request
Future<APIResponse> exec() async => APIHelper().exec(this);
/// Execute the request with files
Future<APIResponse> execWithFiles() async => APIHelper().execWithFiles(this);
}