postOccupant method
Future<Response<Occupant> >
postOccupant({
- required String xKeyclicApp,
- required OccupantData occupantData,
- String? acceptLanguage,
- DateTime? xDateTime,
- String? xKeyclicAppPlatform,
- String? xKeyclicAppVersion,
- CancelToken? cancelToken,
- Map<
String, dynamic> ? headers, - Map<
String, dynamic> ? extra, - ValidateStatus? validateStatus,
- ProgressCallback? onSendProgress,
- ProgressCallback? onReceiveProgress,
Create one Occupant resource.
Parameters:
xKeyclicApp
occupantData
acceptLanguage
xDateTime
xKeyclicAppPlatform
xKeyclicAppVersion
cancelToken
- ACancelToken
that can be used to cancel the operationheaders
- Can be used to add additional headers to the requestextras
- Can be used to add flags to the requestvalidateStatus
- AValidateStatus
callback that can be used to determine request success based on the HTTP status of the responseonSendProgress
- AProgressCallback
that can be used to get the send progressonReceiveProgress
- AProgressCallback
that can be used to get the receive progress
Returns a Future containing a Response
with a Occupant as data
Throws DioError
if API call or serialization fails
Keyclic API documentation.
Also see Create one Occupant resource. Documentation
Implementation
Future<Response<Occupant>> postOccupant({
required String xKeyclicApp,
required OccupantData occupantData,
String? acceptLanguage,
DateTime? xDateTime,
String? xKeyclicAppPlatform,
String? xKeyclicAppVersion,
CancelToken? cancelToken,
Map<String, dynamic>? headers,
Map<String, dynamic>? extra,
ValidateStatus? validateStatus,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
}) async {
final String path = r'/occupants';
final options = Options(
method: r'POST',
headers: <String, dynamic>{
// to string ??
if (acceptLanguage != null) r'accept-language': acceptLanguage,
if (xDateTime != null) r'x-date-time': xDateTime,
r'x-keyclic-app': xKeyclicApp,
if (xKeyclicAppPlatform != null)
r'x-keyclic-app-platform': xKeyclicAppPlatform,
if (xKeyclicAppVersion != null)
r'x-keyclic-app-version': xKeyclicAppVersion,
...?headers,
},
extra: <String, dynamic>{
'secure': <Map<String, String>>[
{
'type': 'apiKey',
'name': 'bearer',
'keyName': 'Authorization',
'where': 'header',
},
],
...?extra,
},
contentType: 'application/json;charset=UTF-8',
validateStatus: validateStatus,
);
dynamic bodyData;
try {
bodyData = occupantData.toJson();
// bodyData = jsonEncode(occupantData);
// bodyData = jsonDecode(jsonEncode(occupantData));
} catch (error, stackTrace) {
throw DioError(
requestOptions: options.compose(
_apiClient.dio.options,
path,
),
type: DioErrorType.other,
error: error,
)..stackTrace = stackTrace;
}
final response = await _apiClient.dio.request<Object>(
path,
data: bodyData,
options: options,
cancelToken: cancelToken,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);
Occupant responseData;
try {
responseData = await _apiClient.deserializeAsync<Occupant>(
response.data!, 'Occupant');
} catch (error, stackTrace) {
throw DioError(
requestOptions: response.requestOptions,
response: response,
type: DioErrorType.other,
error: error,
)..stackTrace = stackTrace;
}
return Response<Occupant>(
data: responseData,
headers: response.headers,
isRedirect: response.isRedirect,
requestOptions: response.requestOptions,
redirects: response.redirects,
statusCode: response.statusCode,
statusMessage: response.statusMessage,
extra: response.extra,
);
}