|
|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
import 'dart:async';
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
import 'dart:developer';
|
|
|
|
|
import 'dart:io' show Platform;
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/api_consts.dart';
|
|
|
|
|
@ -10,7 +11,6 @@ import 'package:hmg_patient_app_new/services/analytics/analytics_service.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/services/logger_service.dart';
|
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abstract class ApiClient {
|
|
|
|
|
Future<void> post(
|
|
|
|
|
String endPoint, {
|
|
|
|
|
@ -75,8 +75,10 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
final _analytics = getIt<GAnalytics>();
|
|
|
|
|
|
|
|
|
|
final LoggerService loggerService;
|
|
|
|
|
|
|
|
|
|
ApiClientImp({required this.loggerService});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
post(String endPoint,
|
|
|
|
|
{required Map<String, dynamic> body,
|
|
|
|
|
required Function(dynamic response, int statusCode) onSuccess,
|
|
|
|
|
@ -98,21 +100,15 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
var user = appState.getAuthenticatedUser;
|
|
|
|
|
Map<String, String> headers = {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json'
|
|
|
|
|
};
|
|
|
|
|
Map<String, String> headers = {'Content-Type': 'application/json', 'Accept': 'application/json'};
|
|
|
|
|
if (!isExternal) {
|
|
|
|
|
String? token = appState.appAuthToken;
|
|
|
|
|
String? languageID =
|
|
|
|
|
(appState.postParamsObject?.languageID == 1 ? 'ar' : 'en') ?? 'ar';
|
|
|
|
|
String? languageID = (appState.postParamsObject?.languageID == 1 ? 'ar' : 'en') ?? 'ar';
|
|
|
|
|
if (endPoint == ApiConsts.sendActivationCode) {
|
|
|
|
|
languageID = 'en';
|
|
|
|
|
}
|
|
|
|
|
if (body.containsKey('SetupID')) {
|
|
|
|
|
body['SetupID'] = body.containsKey('SetupID')
|
|
|
|
|
? body['SetupID'] ?? body['']
|
|
|
|
|
: SETUP_ID;
|
|
|
|
|
body['SetupID'] = body.containsKey('SetupID') ? body['SetupID'] ?? body[''] : SETUP_ID;
|
|
|
|
|
} else {}
|
|
|
|
|
|
|
|
|
|
if (body.containsKey('LanguageID')) {
|
|
|
|
|
@ -127,90 +123,71 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (body.containsKey('isDentalAllowedBackend')) {
|
|
|
|
|
body['isDentalAllowedBackend'] =
|
|
|
|
|
body.containsKey('isDentalAllowedBackend')
|
|
|
|
|
? body['isDentalAllowedBackend'] ?? IS_DENTAL_ALLOWED_BACKEND
|
|
|
|
|
: IS_DENTAL_ALLOWED_BACKEND;
|
|
|
|
|
body['isDentalAllowedBackend'] = body.containsKey('isDentalAllowedBackend')
|
|
|
|
|
? body['isDentalAllowedBackend'] ?? IS_DENTAL_ALLOWED_BACKEND
|
|
|
|
|
: IS_DENTAL_ALLOWED_BACKEND;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Todo: I have converted it to string
|
|
|
|
|
body['DeviceTypeID'] = Platform.isIOS
|
|
|
|
|
? 1
|
|
|
|
|
? "1"
|
|
|
|
|
: await Utils.isGoogleServicesAvailable()
|
|
|
|
|
? 2
|
|
|
|
|
: 3;
|
|
|
|
|
? "2"
|
|
|
|
|
: "3";
|
|
|
|
|
|
|
|
|
|
if (!body.containsKey('IsPublicRequest')) {
|
|
|
|
|
// if (!body.containsKey('PatientType')) {
|
|
|
|
|
if (user != null && user.patientType != null) {
|
|
|
|
|
body['PatientType'] = user.patientType;
|
|
|
|
|
} else {
|
|
|
|
|
body['PatientType'] = PATIENT_TYPE;
|
|
|
|
|
body['PatientType'] = PATIENT_TYPE.toString();
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// body['PatientType'] = body.containsKey('PatientType')
|
|
|
|
|
// ? body['PatientType'] != null
|
|
|
|
|
// ? body['PatientType']
|
|
|
|
|
// : user['PatientType'] != null
|
|
|
|
|
// ? user['PatientType']
|
|
|
|
|
// : PATIENT_TYPE
|
|
|
|
|
// : PATIENT_TYPE;
|
|
|
|
|
|
|
|
|
|
// if (!body.containsKey('PatientTypeID')) {
|
|
|
|
|
if (user != null && user.patientType != null) {
|
|
|
|
|
body['PatientTypeID'] = user.patientType;
|
|
|
|
|
} else {
|
|
|
|
|
body['PatientType'] = PATIENT_TYPE_ID;
|
|
|
|
|
body['PatientType'] = PATIENT_TYPE_ID.toString();
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// body['PatientTypeID'] = body.containsKey('PatientTypeID')
|
|
|
|
|
// ? body['PatientTypeID'] != null
|
|
|
|
|
// ? body['PatientTypeID']
|
|
|
|
|
// : user['PatientType'] != null
|
|
|
|
|
// ? user['PatientType']
|
|
|
|
|
// : PATIENT_TYPE_ID
|
|
|
|
|
// : PATIENT_TYPE_ID;
|
|
|
|
|
|
|
|
|
|
if (user != null) {
|
|
|
|
|
body['TokenID'] = body['TokenID'] ?? token;
|
|
|
|
|
body['PatientID'] = body['PatientID'] ?? user.patientID;
|
|
|
|
|
|
|
|
|
|
body['PatientOutSA'] = body.containsKey('PatientOutSA')
|
|
|
|
|
? body['PatientOutSA'] ?? user.outSA
|
|
|
|
|
: user.outSA;
|
|
|
|
|
body['PatientOutSA'] = body.containsKey('PatientOutSA') ? body['PatientOutSA'] ?? user.outSA : user.outSA;
|
|
|
|
|
body['SessionID'] = getSessionId(body['TokenID'] ?? ""); //getSe
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
body['LanguageID'] = body['LanguageID'] ?? "1";
|
|
|
|
|
body['VersionID'] = body['VersionID'] ?? "18.7";
|
|
|
|
|
body['Channel'] = body['Channel'] ?? "3";
|
|
|
|
|
body['IPAdress'] = body['IPAdress'] ?? "10.20.10.20";
|
|
|
|
|
body['generalid'] = body['generalid'] ?? "Cs2020@2016\$2958";
|
|
|
|
|
body['Latitude'] = body['Latitude'] ?? "0.0";
|
|
|
|
|
body['Longitude'] = body['Longitude'] ?? "0.0";
|
|
|
|
|
body['DeviceTypeID'] = body['DeviceTypeID'] ??
|
|
|
|
|
(Platform.isIOS ? "1" : await Utils.isGoogleServicesAvailable() ? "2" : "3");
|
|
|
|
|
//"LanguageID":1,"VersionID":18.7,"Channel":3,"IPAdress":"10.20.10.20","generalid":"Cs2020@2016$2958","Latitude":0.0,"Longitude":0.0,"DeviceTypeID":2,"PatientType":1}
|
|
|
|
|
body.removeWhere((key, value) => value == null);
|
|
|
|
|
|
|
|
|
|
debugPrint("URL : $url");
|
|
|
|
|
final jsonBody = json.encode(body);
|
|
|
|
|
debugPrint(jsonBody);
|
|
|
|
|
// }
|
|
|
|
|
// return;
|
|
|
|
|
if (await Utils.checkConnection(
|
|
|
|
|
bypassConnectionCheck: bypassConnectionCheck)) {
|
|
|
|
|
final response = await http.post(Uri.parse(url.trim()),
|
|
|
|
|
body: json.encode(body), headers: headers);
|
|
|
|
|
log("bodi: ${json.encode(body)}");
|
|
|
|
|
log("bodi: ${Uri.parse(url.trim())}");
|
|
|
|
|
|
|
|
|
|
if (await Utils.checkConnection(bypassConnectionCheck: bypassConnectionCheck)) {
|
|
|
|
|
|
|
|
|
|
final response = await http.post(Uri.parse(url.trim()), body: json.encode(body), headers: headers);
|
|
|
|
|
|
|
|
|
|
final int statusCode = response.statusCode;
|
|
|
|
|
if (statusCode < 200 || statusCode >= 400) {
|
|
|
|
|
onFailure('Error While Fetching data', statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint, 'Error While Fetching data', statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, 'Error While Fetching data', statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
// var decoded = utf8.decode(response.bodyBytes);
|
|
|
|
|
var parsed;
|
|
|
|
|
// if (url.contains('Services/NHIC.svc/REST/GetPatientInfo')) {
|
|
|
|
|
// parsed = json.decode(sampleNHICResponse);
|
|
|
|
|
// } else {
|
|
|
|
|
parsed = json.decode(utf8.decode(response.bodyBytes));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// print("Response: $parsed");
|
|
|
|
|
var parsed = json.decode(utf8.decode(response.bodyBytes));
|
|
|
|
|
|
|
|
|
|
log("parsed: ${parsed.toString()}");
|
|
|
|
|
if (isAllowAny) {
|
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
@ -219,10 +196,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
} else {
|
|
|
|
|
if (parsed['ErrorType'] == 4) {
|
|
|
|
|
//TODO : handle app update
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
}
|
|
|
|
|
if (parsed['ErrorType'] == 2) {
|
|
|
|
|
// todo: handle Logout
|
|
|
|
|
@ -238,72 +212,42 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
} else if (parsed['Result'] == 'OK') {
|
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
// if (parsed != null) {
|
|
|
|
|
// onSuccess(parsed, statusCode);
|
|
|
|
|
// } else {
|
|
|
|
|
onFailure(
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
// logout();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
onFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} else if (parsed['MessageStatus'] == 1 ||
|
|
|
|
|
parsed['SMSLoginRequired'] == true) {
|
|
|
|
|
} else if (parsed['MessageStatus'] == 1 || parsed['SMSLoginRequired'] == true) {
|
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
|
} else if (parsed['MessageStatus'] == 2 &&
|
|
|
|
|
parsed['IsAuthenticated']) {
|
|
|
|
|
} else if (parsed['MessageStatus'] == 2 && parsed['IsAuthenticated']) {
|
|
|
|
|
if (parsed['SameClinicApptList'] != null) {
|
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
if (parsed['message'] == null &&
|
|
|
|
|
parsed['ErrorEndUserMessage'] == null) {
|
|
|
|
|
if (parsed['message'] == null && parsed['ErrorEndUserMessage'] == null) {
|
|
|
|
|
if (parsed['ErrorSearchMsg'] == null) {
|
|
|
|
|
onFailure("Server Error found with no available message",
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
"Server Error found with no available message",
|
|
|
|
|
statusCode);
|
|
|
|
|
onFailure("Server Error found with no available message", statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, "Server Error found with no available message", statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
onFailure(parsed['ErrorSearchMsg'], statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint, parsed['ErrorSearchMsg'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['ErrorSearchMsg'], statusCode);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure(
|
|
|
|
|
parsed['message'] ??
|
|
|
|
|
parsed['ErrorEndUserMessage'] ??
|
|
|
|
|
parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(endPoint,
|
|
|
|
|
parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
|
onFailure(parsed['message'] ?? parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// else if (!parsed['IsAuthenticated']) {
|
|
|
|
|
// await logout();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
if (parsed['SameClinicApptList'] != null) {
|
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
if (parsed['message'] != null) {
|
|
|
|
|
onFailure(
|
|
|
|
|
parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint,
|
|
|
|
|
parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
|
onFailure(parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
onFailure(
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
onFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -312,20 +256,17 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure('Please Check The Internet Connection 1', -1);
|
|
|
|
|
_analytics.errorTracking
|
|
|
|
|
.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
print(e);
|
|
|
|
|
loggerService.errorLogs(e.toString());
|
|
|
|
|
if (e.toString().contains("ClientException")) {
|
|
|
|
|
onFailure('Something went wrong, plase try again', -1);
|
|
|
|
|
_analytics.errorTracking
|
|
|
|
|
.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
} else {
|
|
|
|
|
onFailure(e.toString(), -1);
|
|
|
|
|
}
|
|
|
|
|
_analytics.errorTracking
|
|
|
|
|
.log(endPoint, error: "api exception: $e - API Path: $url");
|
|
|
|
|
_analytics.errorTracking.log(endPoint, error: "api exception: $e - API Path: $url");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -356,10 +297,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
if (await Utils.checkConnection()) {
|
|
|
|
|
final response = await http.get(
|
|
|
|
|
Uri.parse(url.trim()),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json'
|
|
|
|
|
},
|
|
|
|
|
headers: {'Content-Type': 'application/json', 'Accept': 'application/json'},
|
|
|
|
|
);
|
|
|
|
|
final int statusCode = response.statusCode;
|
|
|
|
|
// print("statusCode :$statusCode");
|
|
|
|
|
@ -373,8 +311,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
_analytics.errorTracking
|
|
|
|
|
.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -390,8 +327,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
// print("body: $body");
|
|
|
|
|
|
|
|
|
|
if (await Utils.checkConnection()) {
|
|
|
|
|
headers!.addAll(
|
|
|
|
|
{'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
final response = await http.post(
|
|
|
|
|
Uri.parse(url.trim()),
|
|
|
|
|
body: json.encode(body),
|
|
|
|
|
@ -400,11 +336,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
final int statusCode = response.statusCode;
|
|
|
|
|
// print("statusCode :$statusCode");
|
|
|
|
|
if (await handleUnauthorized(statusCode, forUrl: fullUrl))
|
|
|
|
|
simplePost(fullUrl,
|
|
|
|
|
onFailure: onFailure,
|
|
|
|
|
onSuccess: onSuccess,
|
|
|
|
|
body: body,
|
|
|
|
|
headers: headers);
|
|
|
|
|
simplePost(fullUrl, onFailure: onFailure, onSuccess: onSuccess, body: body, headers: headers);
|
|
|
|
|
|
|
|
|
|
// print(response.body.toString());
|
|
|
|
|
|
|
|
|
|
@ -416,8 +348,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
_analytics.errorTracking
|
|
|
|
|
.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -437,8 +368,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (await Utils.checkConnection()) {
|
|
|
|
|
headers.addAll(
|
|
|
|
|
{'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
headers.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
final response = await http.get(
|
|
|
|
|
Uri.parse(url.trim()),
|
|
|
|
|
headers: headers,
|
|
|
|
|
@ -447,11 +377,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
final int statusCode = response.statusCode;
|
|
|
|
|
// print("statusCode :$statusCode");
|
|
|
|
|
if (await handleUnauthorized(statusCode, forUrl: fullUrl))
|
|
|
|
|
simpleGet(fullUrl,
|
|
|
|
|
onFailure: onFailure,
|
|
|
|
|
onSuccess: onSuccess,
|
|
|
|
|
headers: headers,
|
|
|
|
|
queryParams: queryParams);
|
|
|
|
|
simpleGet(fullUrl, onFailure: onFailure, onSuccess: onSuccess, headers: headers, queryParams: queryParams);
|
|
|
|
|
|
|
|
|
|
if (statusCode < 200 || statusCode >= 400) {
|
|
|
|
|
onFailure!('Error While Fetching data', statusCode);
|
|
|
|
|
@ -461,8 +387,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
_analytics.errorTracking
|
|
|
|
|
.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -475,8 +400,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
// print("URL Query String: $url");
|
|
|
|
|
|
|
|
|
|
if (await Utils.checkConnection()) {
|
|
|
|
|
headers!.addAll(
|
|
|
|
|
{'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
final response = await http.put(
|
|
|
|
|
Uri.parse(url.trim()),
|
|
|
|
|
body: json.encode(body),
|
|
|
|
|
@ -486,11 +410,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
final int statusCode = response.statusCode;
|
|
|
|
|
// print("statusCode :$statusCode");
|
|
|
|
|
if (await handleUnauthorized(statusCode, forUrl: fullUrl))
|
|
|
|
|
simplePut(fullUrl,
|
|
|
|
|
onFailure: onFailure,
|
|
|
|
|
onSuccess: onSuccess,
|
|
|
|
|
headers: headers,
|
|
|
|
|
body: body);
|
|
|
|
|
simplePut(fullUrl, onFailure: onFailure, onSuccess: onSuccess, headers: headers, body: body);
|
|
|
|
|
|
|
|
|
|
if (statusCode < 200 || statusCode >= 400) {
|
|
|
|
|
onFailure!('Error While Fetching data', statusCode);
|
|
|
|
|
@ -500,8 +420,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
_analytics.errorTracking
|
|
|
|
|
.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -521,8 +440,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (await Utils.checkConnection()) {
|
|
|
|
|
headers!.addAll(
|
|
|
|
|
{'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
final response = await http.delete(
|
|
|
|
|
Uri.parse(url.trim()),
|
|
|
|
|
headers: headers,
|
|
|
|
|
@ -531,11 +449,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
final int statusCode = response.statusCode;
|
|
|
|
|
// print("statusCode :$statusCode");
|
|
|
|
|
if (await handleUnauthorized(statusCode, forUrl: fullUrl))
|
|
|
|
|
simpleDelete(fullUrl,
|
|
|
|
|
onFailure: onFailure,
|
|
|
|
|
onSuccess: onSuccess,
|
|
|
|
|
queryParams: queryParams,
|
|
|
|
|
headers: headers);
|
|
|
|
|
simpleDelete(fullUrl, onFailure: onFailure, onSuccess: onSuccess, queryParams: queryParams, headers: headers);
|
|
|
|
|
|
|
|
|
|
if (statusCode < 200 || statusCode >= 400) {
|
|
|
|
|
onFailure!('Error While Fetching data', statusCode);
|
|
|
|
|
@ -545,13 +459,11 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
_analytics.errorTracking
|
|
|
|
|
.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<bool> handleUnauthorized(int statusCode,
|
|
|
|
|
{required String forUrl}) async {
|
|
|
|
|
Future<bool> handleUnauthorized(int statusCode, {required String forUrl}) async {
|
|
|
|
|
if (forUrl.startsWith(EXA_CART_API_BASE_URL) && statusCode == 401) {
|
|
|
|
|
final token = await generatePackagesToken();
|
|
|
|
|
ApiConsts.packagesAuthHeader['Authorization'] = 'Bearer $token';
|
|
|
|
|
@ -574,8 +486,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
};
|
|
|
|
|
String? token;
|
|
|
|
|
final completer = Completer();
|
|
|
|
|
simplePost(url, body: body, headers: {},
|
|
|
|
|
onSuccess: (dynamic stringResponse, int statusCode) {
|
|
|
|
|
simplePost(url, body: body, headers: {}, onSuccess: (dynamic stringResponse, int statusCode) {
|
|
|
|
|
if (statusCode == 200) {
|
|
|
|
|
var jsonResponse = json.decode(stringResponse);
|
|
|
|
|
token = jsonResponse['auth_token'];
|
|
|
|
|
|