// // AUTO-GENERATED FILE, DO NOT MODIFY! // // @dart=2.0 // ignore_for_file: unused_element, unused_import // ignore_for_file: always_put_required_named_parameters_first // ignore_for_file: lines_longer_than_80_chars part of openapi.api; class ApiClient { ApiClient({this.basePath = 'http://192.168.31.140'}) { // Setup authentications (key: authentication name, value: authentication). _authentications[r'bearer'] = OAuth(); } final String basePath; var _client = Client(); /// Returns the current HTTP [Client] instance to use in this class. /// /// The return value is guaranteed to never be null. Client get client => _client; /// Requests to use a new HTTP [Client] in this class. /// /// If the [newClient] is null, an [ArgumentError] is thrown. set client(Client newClient) { if (newClient == null) { throw ArgumentError('New client instance cannot be null.'); } _client = newClient; } final _defaultHeaderMap = {}; final _authentications = {}; void addDefaultHeader(String key, String value) { _defaultHeaderMap[key] = value; } Map get defaultHeaderMap => _defaultHeaderMap; /// returns an unmodifiable view of the authentications, since none should be added /// nor deleted Map get authentications => Map.unmodifiable(_authentications); T getAuthentication(String name) { final authentication = _authentications[name]; return authentication is T ? authentication : null; } // We don’t use a Map for queryParams. // If collectionFormat is 'multi', a key might appear multiple times. Future invokeAPI( String path, String method, Iterable queryParams, Object body, Map headerParams, Map formParams, String nullableContentType, List authNames, ) async { _updateParamsForAuth(authNames, queryParams, headerParams); headerParams.addAll(_defaultHeaderMap); final urlEncodedQueryParams = queryParams .where((param) => param.value != null) .map((param) => '$param'); final queryString = urlEncodedQueryParams.isNotEmpty ? '?${urlEncodedQueryParams.join('&')}' : ''; final url = '$basePath$path$queryString'; if (nullableContentType != null) { headerParams['Content-Type'] = nullableContentType; } try { // Special case for uploading a single file which isn’t a 'multipart/form-data'. if ( body is MultipartFile && (nullableContentType == null || !nullableContentType.toLowerCase().startsWith('multipart/form-data')) ) { final request = StreamedRequest(method, Uri.parse(url)); request.headers.addAll(headerParams); request.contentLength = body.length; body.finalize().listen( request.sink.add, onDone: request.sink.close, onError: (error, trace) => request.sink.close(), cancelOnError: true, ); final response = await _client.send(request); return Response.fromStream(response); } if (body is MultipartRequest) { final request = MultipartRequest(method, Uri.parse(url)); request.fields.addAll(body.fields); request.files.addAll(body.files); request.headers.addAll(body.headers); request.headers.addAll(headerParams); final response = await _client.send(request); return Response.fromStream(response); } final msgBody = nullableContentType == 'application/x-www-form-urlencoded' ? formParams : serialize(body); final nullableHeaderParams = headerParams.isEmpty ? null : headerParams; switch(method) { case 'POST': return await _client.post(url, headers: nullableHeaderParams, body: msgBody,); case 'PUT': return await _client.put(url, headers: nullableHeaderParams, body: msgBody,); case 'DELETE': return await _client.delete(url, headers: nullableHeaderParams,); case 'PATCH': return await _client.patch(url, headers: nullableHeaderParams, body: msgBody,); case 'HEAD': return await _client.head(url, headers: nullableHeaderParams,); case 'GET': return await _client.get(url, headers: nullableHeaderParams,); } } on SocketException catch (e, trace) { throw ApiException.withInner(HttpStatus.badRequest, 'Socket operation failed: $method $path', e, trace,); } on TlsException catch (e, trace) { throw ApiException.withInner(HttpStatus.badRequest, 'TLS/SSL communication failed: $method $path', e, trace,); } on IOException catch (e, trace) { throw ApiException.withInner(HttpStatus.badRequest, 'I/O operation failed: $method $path', e, trace,); } on ClientException catch (e, trace) { throw ApiException.withInner(HttpStatus.badRequest, 'HTTP connection failed: $method $path', e, trace,); } on Exception catch (e, trace) { throw ApiException.withInner(HttpStatus.badRequest, 'Exception occurred: $method $path', e, trace,); } throw ApiException(HttpStatus.badRequest, 'Invalid HTTP operation: $method $path',); } dynamic _deserialize(dynamic value, String targetType, {bool growable}) { try { switch (targetType) { case 'String': return '$value'; case 'int': return value is int ? value : int.parse('$value'); case 'bool': if (value is bool) { return value; } final valueString = '$value'.toLowerCase(); return valueString == 'true' || valueString == '1'; break; case 'double': return value is double ? value : double.parse('$value'); case 'Action': return Action.fromJson(value); case 'ActionType': return ActionTypeTypeTransformer().decode(value); case 'Automation': return Automation.fromJson(value); case 'AutomationCreateOrUpdateDetailDTO': return AutomationCreateOrUpdateDetailDTO.fromJson(value); case 'AutomationCreateOrUpdateDetailDTOAllOf': return AutomationCreateOrUpdateDetailDTOAllOf.fromJson(value); case 'AutomationDTO': return AutomationDTO.fromJson(value); case 'AutomationDetailDTO': return AutomationDetailDTO.fromJson(value); case 'AutomationDetailDTOAllOf': return AutomationDetailDTOAllOf.fromJson(value); case 'AzureADAuthModel': return AzureADAuthModel.fromJson(value); case 'Book': return Book.fromJson(value); case 'Condition': return Condition.fromJson(value); case 'ConditionType': return ConditionTypeTypeTransformer().decode(value); case 'ConditionValue': return ConditionValueTypeTransformer().decode(value); case 'ConnectionStatus': return ConnectionStatusTypeTransformer().decode(value); case 'Device': return Device.fromJson(value); case 'DeviceDetailDTO': return DeviceDetailDTO.fromJson(value); case 'DeviceDetailDTOAllOf': return DeviceDetailDTOAllOf.fromJson(value); case 'DeviceSummaryDTO': return DeviceSummaryDTO.fromJson(value); case 'DeviceType': return DeviceTypeTypeTransformer().decode(value); case 'ElectricityProduction': return ElectricityProduction.fromJson(value); case 'FacebookAuthModel': return FacebookAuthModel.fromJson(value); case 'GoogleAuthModel': return GoogleAuthModel.fromJson(value); case 'Group': return Group.fromJson(value); case 'GroupCreateOrUpdateDetailDTO': return GroupCreateOrUpdateDetailDTO.fromJson(value); case 'GroupCreateOrUpdateDetailDTOAllOf': return GroupCreateOrUpdateDetailDTOAllOf.fromJson(value); case 'GroupDetailDTO': return GroupDetailDTO.fromJson(value); case 'GroupDetailDTOAllOf': return GroupDetailDTOAllOf.fromJson(value); case 'GroupSummaryDTO': return GroupSummaryDTO.fromJson(value); case 'LocationDTO': return LocationDTO.fromJson(value); case 'LoginDTO': return LoginDTO.fromJson(value); case 'MeansOfCommunication': return MeansOfCommunicationTypeTransformer().decode(value); case 'MqttMessageDTO': return MqttMessageDTO.fromJson(value); case 'OddH2H': return OddH2H.fromJson(value); case 'OddNice': return OddNice.fromJson(value); case 'PanelMenuItem': return PanelMenuItem.fromJson(value); case 'PanelSection': return PanelSection.fromJson(value); case 'Provider': return Provider.fromJson(value); case 'ProviderDTO': return ProviderDTO.fromJson(value); case 'RoomCreateOrUpdateDetailDTO': return RoomCreateOrUpdateDetailDTO.fromJson(value); case 'RoomDetailDTO': return RoomDetailDTO.fromJson(value); case 'RoomSummaryDTO': return RoomSummaryDTO.fromJson(value); case 'ScreenConfiguration': return ScreenConfiguration.fromJson(value); case 'ScreenDevice': return ScreenDevice.fromJson(value); case 'SmartGardenMessage': return SmartGardenMessage.fromJson(value); case 'SmartPrinterMessage': return SmartPrinterMessage.fromJson(value); case 'State': return State.fromJson(value); case 'Trigger': return Trigger.fromJson(value); case 'TriggerType': return TriggerTypeTypeTransformer().decode(value); case 'TwitterAuthModel': return TwitterAuthModel.fromJson(value); case 'User': return User.fromJson(value); case 'UserInfo': return UserInfo.fromJson(value); case 'UserInfoDetailDTO': return UserInfoDetailDTO.fromJson(value); case 'ViewBy': return ViewByTypeTransformer().decode(value); case 'Widget': return Widget.fromJson(value); default: Match match; if (value is List && (match = _regList.firstMatch(targetType)) != null) { final newTargetType = match[1]; return value .map((v) => _deserialize(v, newTargetType, growable: growable)) .toList(growable: true == growable); } if (value is Set && (match = _regSet.firstMatch(targetType)) != null) { final newTargetType = match[1]; return value .map((v) => _deserialize(v, newTargetType, growable: growable)) .toSet(); } if (value is Map && (match = _regMap.firstMatch(targetType)) != null) { final newTargetType = match[1]; return Map.fromIterables( value.keys, value.values.map((v) => _deserialize(v, newTargetType, growable: growable)), ); } break; } } on Exception catch (e, stack) { throw ApiException.withInner(HttpStatus.internalServerError, 'Exception during deserialization.', e, stack,); } throw ApiException(HttpStatus.internalServerError, 'Could not find a suitable class for deserialization',); } dynamic deserialize(String json, String targetType, {bool growable}) { // Remove all spaces. Necessary for reg expressions as well. targetType = targetType.replaceAll(' ', ''); return targetType == 'String' ? json : _deserialize(jsonDecode(json), targetType, growable: true == growable); } String serialize(Object obj) => obj == null ? '' : json.encode(obj); /// Update query and header parameters based on authentication settings. /// @param authNames The authentications to apply void _updateParamsForAuth( List authNames, List queryParams, Map headerParams, ) { authNames.forEach((authName) { final auth = _authentications[authName]; if (auth == null) { throw ArgumentError('Authentication undefined: $authName'); } auth.applyToParams(queryParams, headerParams); }); } }