|
|
|
@ -2,21 +2,25 @@ import 'dart:async';
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:developer';
|
|
|
|
import 'dart:developer';
|
|
|
|
import 'dart:io' show Platform;
|
|
|
|
import 'dart:io' show Platform;
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:hmg_patient_app_new/core/api_consts.dart';
|
|
|
|
import 'package:hmg_patient_app_new/core/api_consts.dart';
|
|
|
|
import 'package:hmg_patient_app_new/core/app_state.dart';
|
|
|
|
import 'package:hmg_patient_app_new/core/app_state.dart';
|
|
|
|
import 'package:hmg_patient_app_new/core/dependencies.dart';
|
|
|
|
import 'package:hmg_patient_app_new/core/dependencies.dart';
|
|
|
|
import 'package:hmg_patient_app_new/core/utils/utils.dart';
|
|
|
|
import 'package:hmg_patient_app_new/core/utils/utils.dart';
|
|
|
|
import 'package:hmg_patient_app_new/services/analytics/analytics_service.dart';
|
|
|
|
import 'package:hmg_patient_app_new/services/analytics/analytics_service.dart';
|
|
|
|
|
|
|
|
import 'package:hmg_patient_app_new/services/dialog_service.dart';
|
|
|
|
import 'package:hmg_patient_app_new/services/logger_service.dart';
|
|
|
|
import 'package:hmg_patient_app_new/services/logger_service.dart';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import '../exceptions/api_failure.dart';
|
|
|
|
|
|
|
|
|
|
|
|
abstract class ApiClient {
|
|
|
|
abstract class ApiClient {
|
|
|
|
Future<void> post(
|
|
|
|
Future<void> post(
|
|
|
|
String endPoint, {
|
|
|
|
String endPoint, {
|
|
|
|
required Map<String, dynamic> body,
|
|
|
|
required Map<String, dynamic> body,
|
|
|
|
required Function(dynamic response, int statusCode) onSuccess,
|
|
|
|
required Function(dynamic response, int statusCode, {int? messageStatus}) onSuccess,
|
|
|
|
required Function(String error, int statusCode) onFailure,
|
|
|
|
required Function(String error, int statusCode, {int? messageStatus, Failure? failureType}) onFailure,
|
|
|
|
bool isAllowAny,
|
|
|
|
bool isAllowAny,
|
|
|
|
bool isExternal,
|
|
|
|
bool isExternal,
|
|
|
|
bool isRCService,
|
|
|
|
bool isRCService,
|
|
|
|
@ -32,61 +36,69 @@ abstract class ApiClient {
|
|
|
|
bool isRCService,
|
|
|
|
bool isRCService,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> simplePost(
|
|
|
|
|
|
|
|
String fullUrl, {
|
|
|
|
|
|
|
|
required Map<dynamic, dynamic> body,
|
|
|
|
|
|
|
|
required Map<String, String> headers,
|
|
|
|
|
|
|
|
required Function(dynamic response, int statusCode) onSuccess,
|
|
|
|
|
|
|
|
required Function(String error, int statusCode) onFailure,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> simpleGet(
|
|
|
|
|
|
|
|
String fullUrl, {
|
|
|
|
|
|
|
|
Function(dynamic response, int statusCode)? onSuccess,
|
|
|
|
|
|
|
|
Function(String error, int statusCode)? onFailure,
|
|
|
|
|
|
|
|
Map<String, dynamic>? queryParams,
|
|
|
|
|
|
|
|
Map<String, String>? headers,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> simplePut(
|
|
|
|
|
|
|
|
String fullUrl, {
|
|
|
|
|
|
|
|
Map<String, dynamic>? body,
|
|
|
|
|
|
|
|
Map<String, String>? headers,
|
|
|
|
|
|
|
|
Function(dynamic response, int statusCode)? onSuccess,
|
|
|
|
|
|
|
|
Function(String error, int statusCode)? onFailure,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> simpleDelete(
|
|
|
|
|
|
|
|
String fullUrl, {
|
|
|
|
|
|
|
|
Function(dynamic response, int statusCode)? onSuccess,
|
|
|
|
|
|
|
|
Function(String error, int statusCode)? onFailure,
|
|
|
|
|
|
|
|
Map<String, String>? queryParams,
|
|
|
|
|
|
|
|
Map<String, String>? headers,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<bool> handleUnauthorized(int statusCode, {required String forUrl});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String getSessionId(String id);
|
|
|
|
String getSessionId(String id);
|
|
|
|
|
|
|
|
|
|
|
|
Future<String> generatePackagesToken();
|
|
|
|
// Future<void> simplePost(
|
|
|
|
|
|
|
|
// String fullUrl, {
|
|
|
|
|
|
|
|
// required Map<dynamic, dynamic> body,
|
|
|
|
|
|
|
|
// required Map<String, String> headers,
|
|
|
|
|
|
|
|
// required Function(dynamic response, int statusCode) onSuccess,
|
|
|
|
|
|
|
|
// required Function(String error, int statusCode) onFailure,
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Future<void> simpleGet(
|
|
|
|
|
|
|
|
// String fullUrl, {
|
|
|
|
|
|
|
|
// Function(dynamic response, int statusCode)? onSuccess,
|
|
|
|
|
|
|
|
// Function(String error, int statusCode)? onFailure,
|
|
|
|
|
|
|
|
// Map<String, dynamic>? queryParams,
|
|
|
|
|
|
|
|
// Map<String, String>? headers,
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Future<void> simplePut(
|
|
|
|
|
|
|
|
// String fullUrl, {
|
|
|
|
|
|
|
|
// Map<String, dynamic>? body,
|
|
|
|
|
|
|
|
// Map<String, String>? headers,
|
|
|
|
|
|
|
|
// Function(dynamic response, int statusCode)? onSuccess,
|
|
|
|
|
|
|
|
// Function(String error, int statusCode)? onFailure,
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Future<void> simpleDelete(
|
|
|
|
|
|
|
|
// String fullUrl, {
|
|
|
|
|
|
|
|
// Function(dynamic response, int statusCode)? onSuccess,
|
|
|
|
|
|
|
|
// Function(String error, int statusCode)? onFailure,
|
|
|
|
|
|
|
|
// Map<String, String>? queryParams,
|
|
|
|
|
|
|
|
// Map<String, String>? headers,
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Future<bool> handleUnauthorized(int statusCode, {required String forUrl});
|
|
|
|
|
|
|
|
// Future<String> generatePackagesToken();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class ApiClientImp implements ApiClient {
|
|
|
|
class ApiClientImp implements ApiClient {
|
|
|
|
final _analytics = getIt<GAnalytics>();
|
|
|
|
final _analytics = getIt<GAnalytics>();
|
|
|
|
|
|
|
|
|
|
|
|
final LoggerService loggerService;
|
|
|
|
final LoggerService loggerService;
|
|
|
|
|
|
|
|
final AppState appState;
|
|
|
|
|
|
|
|
final DialogService dialogService;
|
|
|
|
|
|
|
|
|
|
|
|
ApiClientImp({required this.loggerService});
|
|
|
|
ApiClientImp({
|
|
|
|
|
|
|
|
required this.loggerService,
|
|
|
|
|
|
|
|
required this.dialogService,
|
|
|
|
|
|
|
|
required this.appState,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
post(String endPoint,
|
|
|
|
post(
|
|
|
|
{required Map<String, dynamic> body,
|
|
|
|
String endPoint, {
|
|
|
|
required Function(dynamic response, int statusCode) onSuccess,
|
|
|
|
required Map<String, dynamic> body,
|
|
|
|
required Function(String error, int statusCode) onFailure,
|
|
|
|
required Function(dynamic response, int statusCode, {int? messageStatus}) onSuccess,
|
|
|
|
|
|
|
|
required Function(String error, int statusCode, {int? messageStatus, Failure? failureType}) onFailure,
|
|
|
|
bool isAllowAny = false,
|
|
|
|
bool isAllowAny = false,
|
|
|
|
bool isExternal = false,
|
|
|
|
bool isExternal = false,
|
|
|
|
bool isRCService = false,
|
|
|
|
bool isRCService = false,
|
|
|
|
bool bypassConnectionCheck = false}) async {
|
|
|
|
bool bypassConnectionCheck = false,
|
|
|
|
|
|
|
|
}) async {
|
|
|
|
AppState appState = getIt.get<AppState>();
|
|
|
|
AppState appState = getIt.get<AppState>();
|
|
|
|
String url;
|
|
|
|
String url;
|
|
|
|
if (isExternal) {
|
|
|
|
if (isExternal) {
|
|
|
|
@ -103,7 +115,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
Map<String, String> headers = {'Content-Type': 'application/json', 'Accept': 'application/json'};
|
|
|
|
Map<String, String> headers = {'Content-Type': 'application/json', 'Accept': 'application/json'};
|
|
|
|
if (!isExternal) {
|
|
|
|
if (!isExternal) {
|
|
|
|
String? token = appState.appAuthToken;
|
|
|
|
String? token = appState.appAuthToken;
|
|
|
|
String? languageID = (appState.postParamsObject?.languageID == 1 ? 'ar' : 'en') ?? 'ar';
|
|
|
|
String? languageID = (appState.postParamsObject?.languageID == 1 ? 'ar' : 'en');
|
|
|
|
if (endPoint == ApiConsts.sendActivationCode) {
|
|
|
|
if (endPoint == ApiConsts.sendActivationCode) {
|
|
|
|
languageID = 'en';
|
|
|
|
languageID = 'en';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -113,7 +125,6 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
|
|
|
|
|
|
|
if (body.containsKey('LanguageID')) {
|
|
|
|
if (body.containsKey('LanguageID')) {
|
|
|
|
if (body['LanguageID'] != null) {
|
|
|
|
if (body['LanguageID'] != null) {
|
|
|
|
//change this line because language issue happened on dental
|
|
|
|
|
|
|
|
body['LanguageID'] = body['LanguageID'] == 'ar'
|
|
|
|
body['LanguageID'] = body['LanguageID'] == 'ar'
|
|
|
|
? 1
|
|
|
|
? 1
|
|
|
|
: body['LanguageID'] == 'en'
|
|
|
|
: body['LanguageID'] == 'en'
|
|
|
|
@ -128,7 +139,6 @@ class ApiClientImp implements ApiClient {
|
|
|
|
: IS_DENTAL_ALLOWED_BACKEND;
|
|
|
|
: IS_DENTAL_ALLOWED_BACKEND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Todo: I have converted it to string
|
|
|
|
//Todo: I have converted it to string
|
|
|
|
body['DeviceTypeID'] = Platform.isIOS
|
|
|
|
body['DeviceTypeID'] = Platform.isIOS
|
|
|
|
? "1"
|
|
|
|
? "1"
|
|
|
|
@ -160,7 +170,6 @@ class ApiClientImp implements ApiClient {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
body['LanguageID'] = body['LanguageID'] ?? "2";
|
|
|
|
body['LanguageID'] = body['LanguageID'] ?? "2";
|
|
|
|
body['VersionID'] = body['VersionID'] ?? "18.7";
|
|
|
|
body['VersionID'] = body['VersionID'] ?? "18.7";
|
|
|
|
body['Channel'] = body['Channel'] ?? "3";
|
|
|
|
body['Channel'] = body['Channel'] ?? "3";
|
|
|
|
@ -169,22 +178,21 @@ class ApiClientImp implements ApiClient {
|
|
|
|
body['Latitude'] = body['Latitude'] ?? "0.0";
|
|
|
|
body['Latitude'] = body['Latitude'] ?? "0.0";
|
|
|
|
body['Longitude'] = body['Longitude'] ?? "0.0";
|
|
|
|
body['Longitude'] = body['Longitude'] ?? "0.0";
|
|
|
|
body['DeviceTypeID'] = body['DeviceTypeID'] ??
|
|
|
|
body['DeviceTypeID'] = body['DeviceTypeID'] ??
|
|
|
|
|
|
|
|
(Platform.isIOS
|
|
|
|
|
|
|
|
? "1"
|
|
|
|
(Platform.isIOS ? "1" : await Utils.isGoogleServicesAvailable() ? "2" : "3");
|
|
|
|
: await Utils.isGoogleServicesAvailable()
|
|
|
|
//"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}
|
|
|
|
? "2"
|
|
|
|
|
|
|
|
: "3");
|
|
|
|
body.removeWhere((key, value) => value == null);
|
|
|
|
body.removeWhere((key, value) => value == null);
|
|
|
|
|
|
|
|
log("body: ${json.encode(body)}");
|
|
|
|
log("bodi: ${json.encode(body)}");
|
|
|
|
log("uri: ${Uri.parse(url.trim())}");
|
|
|
|
log("bodi: ${Uri.parse(url.trim())}");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (await Utils.checkConnection(bypassConnectionCheck: bypassConnectionCheck)) {
|
|
|
|
if (await Utils.checkConnection(bypassConnectionCheck: bypassConnectionCheck)) {
|
|
|
|
|
|
|
|
|
|
|
|
final response = await http.post(Uri.parse(url.trim()), body: json.encode(body), headers: headers);
|
|
|
|
final response = await http.post(Uri.parse(url.trim()), body: json.encode(body), headers: headers);
|
|
|
|
|
|
|
|
|
|
|
|
final int statusCode = response.statusCode;
|
|
|
|
final int statusCode = response.statusCode;
|
|
|
|
if (statusCode < 200 || statusCode >= 400) {
|
|
|
|
if (statusCode < 200 || statusCode >= 400) {
|
|
|
|
onFailure('Error While Fetching data', statusCode);
|
|
|
|
onFailure('Error While Fetching data', statusCode, failureType: ServerFailure("Error While Fetching data"));
|
|
|
|
logApiEndpointError(endPoint, 'Error While Fetching data', statusCode);
|
|
|
|
logApiEndpointError(endPoint, 'Error While Fetching data', statusCode);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
var parsed = json.decode(utf8.decode(response.bodyBytes));
|
|
|
|
var parsed = json.decode(utf8.decode(response.bodyBytes));
|
|
|
|
@ -193,7 +201,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (parsed['Response_Message'] != null) {
|
|
|
|
if (parsed['Response_Message'] != null) {
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
onSuccess(parsed, statusCode, messageStatus: parsed['MessageStatus']);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (parsed['ErrorType'] == 4) {
|
|
|
|
if (parsed['ErrorType'] == 4) {
|
|
|
|
//TODO : handle app update
|
|
|
|
//TODO : handle app update
|
|
|
|
@ -204,19 +212,18 @@ class ApiClientImp implements ApiClient {
|
|
|
|
logApiEndpointError(endPoint, "session logged out", statusCode);
|
|
|
|
logApiEndpointError(endPoint, "session logged out", statusCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isAllowAny) {
|
|
|
|
if (isAllowAny) {
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
onSuccess(parsed, statusCode, messageStatus: parsed['MessageStatus']);
|
|
|
|
} else if (parsed['IsAuthenticated'] == null) {
|
|
|
|
} else if (parsed['IsAuthenticated'] == null) {
|
|
|
|
if (parsed['isSMSSent'] == true) {
|
|
|
|
if (parsed['isSMSSent'] == true) {
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
onSuccess(parsed, statusCode, messageStatus: parsed['MessageStatus']);
|
|
|
|
} else if (parsed['MessageStatus'] == 1) {
|
|
|
|
} else if (parsed['MessageStatus'] == 1) {
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
} else if (parsed['Result'] == 'OK') {
|
|
|
|
} else if (parsed['Result'] == 'OK') {
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
onFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode,
|
|
|
|
onFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
failureType: ServerFailure("Error While Fetching data"));
|
|
|
|
logApiEndpointError(endPoint, 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);
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
@ -226,28 +233,46 @@ class ApiClientImp implements ApiClient {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (parsed['message'] == null && parsed['ErrorEndUserMessage'] == null) {
|
|
|
|
if (parsed['message'] == null && parsed['ErrorEndUserMessage'] == null) {
|
|
|
|
if (parsed['ErrorSearchMsg'] == null) {
|
|
|
|
if (parsed['ErrorSearchMsg'] == null) {
|
|
|
|
onFailure("Server Error found with no available message", statusCode);
|
|
|
|
onFailure(
|
|
|
|
|
|
|
|
"Server Error found with no available message",
|
|
|
|
|
|
|
|
statusCode,
|
|
|
|
|
|
|
|
failureType: ServerFailure("Error While Fetching data"),
|
|
|
|
|
|
|
|
);
|
|
|
|
logApiEndpointError(endPoint, "Server Error found with no available message", statusCode);
|
|
|
|
logApiEndpointError(endPoint, "Server Error found with no available message", statusCode);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
onFailure(parsed['ErrorSearchMsg'], statusCode);
|
|
|
|
onFailure(
|
|
|
|
|
|
|
|
parsed['ErrorSearchMsg'],
|
|
|
|
|
|
|
|
statusCode,
|
|
|
|
|
|
|
|
failureType: ServerFailure("Error While Fetching data"),
|
|
|
|
|
|
|
|
);
|
|
|
|
logApiEndpointError(endPoint, parsed['ErrorSearchMsg'], statusCode);
|
|
|
|
logApiEndpointError(endPoint, parsed['ErrorSearchMsg'], statusCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
onFailure(parsed['message'] ?? parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
onFailure(
|
|
|
|
|
|
|
|
parsed['message'] ?? parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
|
|
|
statusCode,
|
|
|
|
|
|
|
|
failureType: ServerFailure("Error While Fetching data"),
|
|
|
|
|
|
|
|
);
|
|
|
|
logApiEndpointError(endPoint, parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
logApiEndpointError(endPoint, parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
if (parsed['SameClinicApptList'] != null) {
|
|
|
|
if (parsed['SameClinicApptList'] != null) {
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (parsed['message'] != null) {
|
|
|
|
if (parsed['message'] != null) {
|
|
|
|
onFailure(parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
onFailure(
|
|
|
|
|
|
|
|
parsed['message'] ?? parsed['message'],
|
|
|
|
|
|
|
|
statusCode,
|
|
|
|
|
|
|
|
failureType: ServerFailure("Error While Fetching data"),
|
|
|
|
|
|
|
|
);
|
|
|
|
logApiEndpointError(endPoint, parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
logApiEndpointError(endPoint, parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
onFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
onFailure(
|
|
|
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
|
|
|
statusCode,
|
|
|
|
|
|
|
|
failureType: ServerFailure("Error While Fetching data"),
|
|
|
|
|
|
|
|
);
|
|
|
|
logApiEndpointError(endPoint, parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
logApiEndpointError(endPoint, parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -256,13 +281,17 @@ class ApiClientImp implements ApiClient {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
onFailure('Please Check The Internet Connection 1', -1);
|
|
|
|
onFailure(
|
|
|
|
|
|
|
|
'Please Check The Internet Connection 1',
|
|
|
|
|
|
|
|
-1,
|
|
|
|
|
|
|
|
failureType: ConnectivityFailure("Error While Fetching data"),
|
|
|
|
|
|
|
|
);
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
loggerService.errorLogs(e.toString());
|
|
|
|
loggerService.errorLogs(e.toString());
|
|
|
|
if (e.toString().contains("ClientException")) {
|
|
|
|
if (e.toString().contains("ClientException")) {
|
|
|
|
onFailure('Something went wrong, plase try again', -1);
|
|
|
|
onFailure('Something went wrong, plase try again', -1, failureType: InvalidCredentials('Something went wrong, plase try again'));
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
onFailure(e.toString(), -1);
|
|
|
|
onFailure(e.toString(), -1);
|
|
|
|
@ -271,6 +300,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
get(String endPoint,
|
|
|
|
get(String endPoint,
|
|
|
|
{required Function(dynamic response, int statusCode) onSuccess,
|
|
|
|
{required Function(dynamic response, int statusCode) onSuccess,
|
|
|
|
required Function(String error, int statusCode) onFailure,
|
|
|
|
required Function(String error, int statusCode) onFailure,
|
|
|
|
@ -304,203 +334,173 @@ class ApiClientImp implements ApiClient {
|
|
|
|
// print("statusCode :$statusCode");
|
|
|
|
// print("statusCode :$statusCode");
|
|
|
|
|
|
|
|
|
|
|
|
if (statusCode < 200 || statusCode >= 400) {
|
|
|
|
if (statusCode < 200 || statusCode >= 400) {
|
|
|
|
onFailure!('Error While Fetching data', statusCode);
|
|
|
|
onFailure('Error While Fetching data', statusCode);
|
|
|
|
logApiEndpointError(endPoint, 'Error While Fetching data', statusCode);
|
|
|
|
logApiEndpointError(endPoint, 'Error While Fetching data', statusCode);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
var parsed = json.decode(utf8.decode(response.bodyBytes));
|
|
|
|
var parsed = json.decode(utf8.decode(response.bodyBytes));
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
simplePost(
|
|
|
|
|
|
|
|
String fullUrl, {
|
|
|
|
|
|
|
|
required Map<dynamic, dynamic> body,
|
|
|
|
|
|
|
|
required Map<String, String> headers,
|
|
|
|
|
|
|
|
required Function(dynamic response, int statusCode) onSuccess,
|
|
|
|
|
|
|
|
required Function(String error, int statusCode) onFailure,
|
|
|
|
|
|
|
|
}) async {
|
|
|
|
|
|
|
|
String url = fullUrl;
|
|
|
|
|
|
|
|
// print("URL Query String: $url");
|
|
|
|
|
|
|
|
// print("body: $body");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (await Utils.checkConnection()) {
|
|
|
|
|
|
|
|
headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
|
|
|
final response = await http.post(
|
|
|
|
|
|
|
|
Uri.parse(url.trim()),
|
|
|
|
|
|
|
|
body: json.encode(body),
|
|
|
|
|
|
|
|
headers: headers,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
final int statusCode = response.statusCode;
|
|
|
|
|
|
|
|
// print("statusCode :$statusCode");
|
|
|
|
|
|
|
|
if (await handleUnauthorized(statusCode, forUrl: fullUrl))
|
|
|
|
|
|
|
|
simplePost(fullUrl, onFailure: onFailure, onSuccess: onSuccess, body: body, headers: headers);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// print(response.body.toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (statusCode < 200 || statusCode >= 400) {
|
|
|
|
|
|
|
|
onFailure!('Error While Fetching data', statusCode);
|
|
|
|
|
|
|
|
logApiFullUrlError(fullUrl, 'Error While Fetching data', statusCode);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
onSuccess!(response.body.toString(), statusCode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
simpleGet(String fullUrl,
|
|
|
|
|
|
|
|
{Function(dynamic response, int statusCode)? onSuccess,
|
|
|
|
|
|
|
|
Function(String error, int statusCode)? onFailure,
|
|
|
|
|
|
|
|
Map<String, dynamic>? queryParams,
|
|
|
|
|
|
|
|
Map<String, String>? headers}) async {
|
|
|
|
|
|
|
|
headers = headers ?? {};
|
|
|
|
|
|
|
|
String url = fullUrl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var haveParams = (queryParams != null);
|
|
|
|
|
|
|
|
if (haveParams) {
|
|
|
|
|
|
|
|
String queryString = Uri(queryParameters: queryParams).query;
|
|
|
|
|
|
|
|
url += '?$queryString';
|
|
|
|
|
|
|
|
// print("URL Query String: $url");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (await Utils.checkConnection()) {
|
|
|
|
|
|
|
|
headers.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
|
|
|
final response = await http.get(
|
|
|
|
|
|
|
|
Uri.parse(url.trim()),
|
|
|
|
|
|
|
|
headers: headers,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final int statusCode = response.statusCode;
|
|
|
|
|
|
|
|
// print("statusCode :$statusCode");
|
|
|
|
|
|
|
|
if (await handleUnauthorized(statusCode, forUrl: fullUrl))
|
|
|
|
|
|
|
|
simpleGet(fullUrl, onFailure: onFailure, onSuccess: onSuccess, headers: headers, queryParams: queryParams);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (statusCode < 200 || statusCode >= 400) {
|
|
|
|
|
|
|
|
onFailure!('Error While Fetching data', statusCode);
|
|
|
|
|
|
|
|
logApiFullUrlError(fullUrl, 'Error While Fetching data', statusCode);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
onSuccess!(response.body.toString(), statusCode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
simplePut(String fullUrl,
|
|
|
|
|
|
|
|
{Map<String, dynamic>? body,
|
|
|
|
|
|
|
|
Map<String, String>? headers,
|
|
|
|
|
|
|
|
Function(dynamic response, int statusCode)? onSuccess,
|
|
|
|
|
|
|
|
Function(String error, int statusCode)? onFailure}) async {
|
|
|
|
|
|
|
|
String url = fullUrl;
|
|
|
|
|
|
|
|
// print("URL Query String: $url");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (await Utils.checkConnection()) {
|
|
|
|
|
|
|
|
headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
|
|
|
final response = await http.put(
|
|
|
|
|
|
|
|
Uri.parse(url.trim()),
|
|
|
|
|
|
|
|
body: json.encode(body),
|
|
|
|
|
|
|
|
headers: headers,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final int statusCode = response.statusCode;
|
|
|
|
|
|
|
|
// print("statusCode :$statusCode");
|
|
|
|
|
|
|
|
if (await handleUnauthorized(statusCode, forUrl: fullUrl))
|
|
|
|
|
|
|
|
simplePut(fullUrl, onFailure: onFailure, onSuccess: onSuccess, headers: headers, body: body);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (statusCode < 200 || statusCode >= 400) {
|
|
|
|
|
|
|
|
onFailure!('Error While Fetching data', statusCode);
|
|
|
|
|
|
|
|
logApiFullUrlError(fullUrl, 'Error While Fetching data', statusCode);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
onSuccess!(response.body.toString(), statusCode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
simpleDelete(String fullUrl,
|
|
|
|
|
|
|
|
{Function(dynamic response, int statusCode)? onSuccess,
|
|
|
|
|
|
|
|
Function(String error, int statusCode)? onFailure,
|
|
|
|
|
|
|
|
Map<String, String>? queryParams,
|
|
|
|
|
|
|
|
Map<String, String>? headers}) async {
|
|
|
|
|
|
|
|
String url = fullUrl;
|
|
|
|
|
|
|
|
// print("URL Query String: $url");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var haveParams = (queryParams != null);
|
|
|
|
|
|
|
|
if (haveParams) {
|
|
|
|
|
|
|
|
String queryString = Uri(queryParameters: queryParams).query;
|
|
|
|
|
|
|
|
url += '?$queryString';
|
|
|
|
|
|
|
|
// print("URL Query String: $url");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (await Utils.checkConnection()) {
|
|
|
|
|
|
|
|
headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
|
|
|
final response = await http.delete(
|
|
|
|
|
|
|
|
Uri.parse(url.trim()),
|
|
|
|
|
|
|
|
headers: headers,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final int statusCode = response.statusCode;
|
|
|
|
|
|
|
|
// print("statusCode :$statusCode");
|
|
|
|
|
|
|
|
if (await handleUnauthorized(statusCode, forUrl: fullUrl))
|
|
|
|
|
|
|
|
simpleDelete(fullUrl, onFailure: onFailure, onSuccess: onSuccess, queryParams: queryParams, headers: headers);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (statusCode < 200 || statusCode >= 400) {
|
|
|
|
|
|
|
|
onFailure!('Error While Fetching data', statusCode);
|
|
|
|
|
|
|
|
logApiFullUrlError(fullUrl, 'Error While Fetching data', statusCode);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
onSuccess!(response.body.toString(), statusCode);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
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 {
|
|
|
|
// @override
|
|
|
|
if (forUrl.startsWith(EXA_CART_API_BASE_URL) && statusCode == 401) {
|
|
|
|
// simplePost(
|
|
|
|
final token = await generatePackagesToken();
|
|
|
|
// String fullUrl, {
|
|
|
|
ApiConsts.packagesAuthHeader['Authorization'] = 'Bearer $token';
|
|
|
|
// required Map<dynamic, dynamic> body,
|
|
|
|
return (token is String);
|
|
|
|
// required Map<String, String> headers,
|
|
|
|
}
|
|
|
|
// required Function(dynamic response, int statusCode) onSuccess,
|
|
|
|
return false;
|
|
|
|
// required Function(String error, int statusCode) onFailure,
|
|
|
|
}
|
|
|
|
// }) async {
|
|
|
|
|
|
|
|
// String url = fullUrl;
|
|
|
|
|
|
|
|
// // print("URL Query String: $url");
|
|
|
|
|
|
|
|
// // print("body: $body");
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (await Utils.checkConnection()) {
|
|
|
|
|
|
|
|
// headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
|
|
|
// final response = await http.post(
|
|
|
|
|
|
|
|
// Uri.parse(url.trim()),
|
|
|
|
|
|
|
|
// body: json.encode(body),
|
|
|
|
|
|
|
|
// headers: headers,
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// final int statusCode = response.statusCode;
|
|
|
|
|
|
|
|
// // print("statusCode :$statusCode");
|
|
|
|
|
|
|
|
// if (await handleUnauthorized(statusCode, forUrl: fullUrl)) {
|
|
|
|
|
|
|
|
// simplePost(fullUrl, onFailure: onFailure, onSuccess: onSuccess, body: body, headers: headers);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // print(response.body.toString());
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (statusCode < 200 || statusCode >= 400) {
|
|
|
|
|
|
|
|
// onFailure!('Error While Fetching data', statusCode);
|
|
|
|
|
|
|
|
// logApiFullUrlError(fullUrl, 'Error While Fetching data', statusCode);
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// onSuccess!(response.body.toString(), statusCode);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
|
|
|
// _analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// simpleGet(String fullUrl,
|
|
|
|
|
|
|
|
// {Function(dynamic response, int statusCode)? onSuccess,
|
|
|
|
|
|
|
|
// Function(String error, int statusCode)? onFailure,
|
|
|
|
|
|
|
|
// Map<String, dynamic>? queryParams,
|
|
|
|
|
|
|
|
// Map<String, String>? headers}) async {
|
|
|
|
|
|
|
|
// headers = headers ?? {};
|
|
|
|
|
|
|
|
// String url = fullUrl;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// var haveParams = (queryParams != null);
|
|
|
|
|
|
|
|
// if (haveParams) {
|
|
|
|
|
|
|
|
// String queryString = Uri(queryParameters: queryParams).query;
|
|
|
|
|
|
|
|
// url += '?$queryString';
|
|
|
|
|
|
|
|
// // print("URL Query String: $url");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (await Utils.checkConnection()) {
|
|
|
|
|
|
|
|
// headers.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
|
|
|
// final response = await http.get(
|
|
|
|
|
|
|
|
// Uri.parse(url.trim()),
|
|
|
|
|
|
|
|
// headers: headers,
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// final int statusCode = response.statusCode;
|
|
|
|
|
|
|
|
// // print("statusCode :$statusCode");
|
|
|
|
|
|
|
|
// if (await handleUnauthorized(statusCode, forUrl: fullUrl))
|
|
|
|
|
|
|
|
// simpleGet(fullUrl, onFailure: onFailure, onSuccess: onSuccess, headers: headers, queryParams: queryParams);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (statusCode < 200 || statusCode >= 400) {
|
|
|
|
|
|
|
|
// onFailure!('Error While Fetching data', statusCode);
|
|
|
|
|
|
|
|
// logApiFullUrlError(fullUrl, 'Error While Fetching data', statusCode);
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// onSuccess!(response.body.toString(), statusCode);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
|
|
|
// _analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// simplePut(String fullUrl,
|
|
|
|
|
|
|
|
// {Map<String, dynamic>? body,
|
|
|
|
|
|
|
|
// Map<String, String>? headers,
|
|
|
|
|
|
|
|
// Function(dynamic response, int statusCode)? onSuccess,
|
|
|
|
|
|
|
|
// Function(String error, int statusCode)? onFailure}) async {
|
|
|
|
|
|
|
|
// String url = fullUrl;
|
|
|
|
|
|
|
|
// // print("URL Query String: $url");
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (await Utils.checkConnection()) {
|
|
|
|
|
|
|
|
// headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
|
|
|
// final response = await http.put(
|
|
|
|
|
|
|
|
// Uri.parse(url.trim()),
|
|
|
|
|
|
|
|
// body: json.encode(body),
|
|
|
|
|
|
|
|
// headers: headers,
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// final int statusCode = response.statusCode;
|
|
|
|
|
|
|
|
// // print("statusCode :$statusCode");
|
|
|
|
|
|
|
|
// if (await handleUnauthorized(statusCode, forUrl: fullUrl))
|
|
|
|
|
|
|
|
// simplePut(fullUrl, onFailure: onFailure, onSuccess: onSuccess, headers: headers, body: body);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (statusCode < 200 || statusCode >= 400) {
|
|
|
|
|
|
|
|
// onFailure!('Error While Fetching data', statusCode);
|
|
|
|
|
|
|
|
// logApiFullUrlError(fullUrl, 'Error While Fetching data', statusCode);
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// onSuccess!(response.body.toString(), statusCode);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
|
|
|
// _analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// simpleDelete(String fullUrl,
|
|
|
|
|
|
|
|
// {Function(dynamic response, int statusCode)? onSuccess,
|
|
|
|
|
|
|
|
// Function(String error, int statusCode)? onFailure,
|
|
|
|
|
|
|
|
// Map<String, String>? queryParams,
|
|
|
|
|
|
|
|
// Map<String, String>? headers}) async {
|
|
|
|
|
|
|
|
// String url = fullUrl;
|
|
|
|
|
|
|
|
// // print("URL Query String: $url");
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// var haveParams = (queryParams != null);
|
|
|
|
|
|
|
|
// if (haveParams) {
|
|
|
|
|
|
|
|
// String queryString = Uri(queryParameters: queryParams).query;
|
|
|
|
|
|
|
|
// url += '?$queryString';
|
|
|
|
|
|
|
|
// // print("URL Query String: $url");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (await Utils.checkConnection()) {
|
|
|
|
|
|
|
|
// headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
|
|
|
// final response = await http.delete(
|
|
|
|
|
|
|
|
// Uri.parse(url.trim()),
|
|
|
|
|
|
|
|
// headers: headers,
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// final int statusCode = response.statusCode;
|
|
|
|
|
|
|
|
// // print("statusCode :$statusCode");
|
|
|
|
|
|
|
|
// if (await handleUnauthorized(statusCode, forUrl: fullUrl))
|
|
|
|
|
|
|
|
// simpleDelete(fullUrl, onFailure: onFailure, onSuccess: onSuccess, queryParams: queryParams, headers: headers);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (statusCode < 200 || statusCode >= 400) {
|
|
|
|
|
|
|
|
// onFailure!('Error While Fetching data', statusCode);
|
|
|
|
|
|
|
|
// logApiFullUrlError(fullUrl, 'Error While Fetching data', statusCode);
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// onSuccess!(response.body.toString(), statusCode);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
|
|
|
// _analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
String getSessionId(String id) {
|
|
|
|
String getSessionId(String id) {
|
|
|
|
return id.replaceAll(RegExp('/[^a-zA-Z]'), '');
|
|
|
|
return id.replaceAll(RegExp('/[^a-zA-Z]'), '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<String> generatePackagesToken() async {
|
|
|
|
|
|
|
|
var url = EXA_CART_API_BASE_URL + PACKAGES_TOKEN;
|
|
|
|
|
|
|
|
var body = {
|
|
|
|
|
|
|
|
"api_client": {
|
|
|
|
|
|
|
|
"client_id": "a4ab6be4-424f-4836-b032-46caed88e184",
|
|
|
|
|
|
|
|
"client_secret": "3c1a3e07-4a40-4510-9fb0-ee5f0a72752c"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
String? token;
|
|
|
|
|
|
|
|
final completer = Completer();
|
|
|
|
|
|
|
|
simplePost(url, body: body, headers: {}, onSuccess: (dynamic stringResponse, int statusCode) {
|
|
|
|
|
|
|
|
if (statusCode == 200) {
|
|
|
|
|
|
|
|
var jsonResponse = json.decode(stringResponse);
|
|
|
|
|
|
|
|
token = jsonResponse['auth_token'];
|
|
|
|
|
|
|
|
completer.complete();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, onFailure: (String error, int statusCode) {
|
|
|
|
|
|
|
|
completer.complete();
|
|
|
|
|
|
|
|
logApiFullUrlError(url, error, statusCode);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
await completer.future;
|
|
|
|
|
|
|
|
return token!;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logApiFullUrlError(String fullUrl, error, code) {
|
|
|
|
logApiFullUrlError(String fullUrl, error, code) {
|
|
|
|
final endpoint = Uri.parse(fullUrl).pathSegments.last;
|
|
|
|
final endpoint = Uri.parse(fullUrl).pathSegments.last;
|
|
|
|
logApiEndpointError(endpoint, error, code);
|
|
|
|
logApiEndpointError(endpoint, error, code);
|
|
|
|
|