diff --git a/lib/client/app_client.dart b/lib/client/app_client.dart new file mode 100644 index 00000000..6018b041 --- /dev/null +++ b/lib/client/app_client.dart @@ -0,0 +1,18 @@ +import 'package:doctor_app_flutter/interceptor/http_interceptor.dart'; +import 'package:http/http.dart'; + +// OWNER : Ibrahim albitar +// DATE : 22-04-2020 +// DESCRIPTION : Custom App client to pin base url for all srvices + +class AppClient { + static const String BASE_URL = "https://hmgwebservices.com/"; + + static Client client = HttpInterceptor().getClient(); + + static Future post(dynamic path, {dynamic body}) async { + String _fullUrl = BASE_URL + path; + final response = await client.post(_fullUrl, body: body); + return response; + } +} \ No newline at end of file diff --git a/lib/interceptor/http_interceptor.dart b/lib/interceptor/http_interceptor.dart index 41f7c016..c27b3cb9 100644 --- a/lib/interceptor/http_interceptor.dart +++ b/lib/interceptor/http_interceptor.dart @@ -1,3 +1,9 @@ +import 'dart:convert'; + +import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; +import 'package:doctor_app_flutter/providers/auth_provider.dart'; +import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart'; +import 'package:http/http.dart'; import 'package:http_interceptor/http_interceptor.dart'; import '../providers/auth_provider.dart'; @@ -12,6 +18,11 @@ List publicUrls = [ ]; class HttpInterceptor extends InterceptorContract { + + Client getClient(){ + return HttpClientWithInterceptor.build(interceptors: [this]); +} + Future interceptRequest({RequestData data}) async { print('RequestData ${data.body}'); try { diff --git a/lib/models/medicine_model.dart b/lib/models/medicine_model.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/providers/auth_provider.dart b/lib/providers/auth_provider.dart index 8dc10319..314dfeb0 100644 --- a/lib/providers/auth_provider.dart +++ b/lib/providers/auth_provider.dart @@ -1,34 +1,28 @@ import 'dart:convert'; - +import 'package:doctor_app_flutter/client/app_client.dart'; import 'package:flutter/cupertino.dart'; -import 'package:http/http.dart'; -import 'package:http_interceptor/http_client_with_interceptor.dart'; import '../config/config.dart'; import '../interceptor/http_interceptor.dart'; import '../models/user_model.dart'; -const LOGIN_URL = BASE_URL + 'Sentry.svc/REST/MemberLogIN_New'; +const LOGIN_URL = + 'Services/Sentry.svc/REST/MemberLogIN_New'; const INSERT_DEVICE_IMEI = - BASE_URL + 'Sentry.svc/REST/DoctorApplication_INSERTDeviceIMEI'; + 'Services/Sentry.svc/REST/DoctorApplication_INSERTDeviceIMEI'; const SELECT_DEVICE_IMEI = - BASE_URL + 'Sentry.svc/REST/DoctorApplication_SELECTDeviceIMEIbyIMEI'; - -const SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE = BASE_URL + - 'Sentry.svc/REST/DoctorApplication_SendActivationCodebyOTPNotificationType'; + 'Services/Sentry.svc/REST/DoctorApplication_SELECTDeviceIMEIbyIMEI'; -const MEMBER_CHECK_ACTIVATION_CODE_NEW = - BASE_URL + 'Sentry.svc/REST/MemberCheckActivationCode_New'; +const SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE = + 'Services/Sentry.svc/REST/DoctorApplication_SendActivationCodebyOTPNotificationType'; +const MEMBER_CHECK_ACTIVATION_CODE_NEW ='Services/Sentry.svc/REST/MemberCheckActivationCode_New'; class AuthProvider with ChangeNotifier { - Client client = - HttpClientWithInterceptor.build(interceptors: [HttpInterceptor()]); Future login(UserModel userInfo) async { const url = LOGIN_URL; try { - final response = await client.post(url, - // headers: requestHeaders, + final response = await AppClient.post(url, body: json.encode({ "UserID": userInfo.UserID, "Password": userInfo.Password, @@ -50,7 +44,7 @@ class AuthProvider with ChangeNotifier { const url = INSERT_DEVICE_IMEI; try { - final response = await client.post(url, body: json.encode(imei)); + final response = await AppClient.post(url, body: json.encode(imei)); return Future.value(json.decode(response.body)); } catch (error) { print(error); @@ -62,7 +56,7 @@ class AuthProvider with ChangeNotifier { const url = SELECT_DEVICE_IMEI; try { - final response = await client.post(url, body: json.encode(imei)); + final response = await AppClient.post(url, body: json.encode(imei)); return Future.value(json.decode(response.body)); } catch (error) { print(error); @@ -75,8 +69,7 @@ class AuthProvider with ChangeNotifier { const url = SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE; try { - final response = - await client.post(url, body: json.encode(activationCodeModel)); + final response = await AppClient.post(url, body: json.encode(activationCodeModel)); return Future.value(json.decode(response.body)); } catch (error) { print(error); @@ -88,8 +81,7 @@ class AuthProvider with ChangeNotifier { const url = MEMBER_CHECK_ACTIVATION_CODE_NEW; try { - final response = - await client.post(url, body: json.encode(activationCodeModel)); + final response = await AppClient.post(url, body: json.encode(activationCodeModel)); return Future.value(json.decode(response.body)); } catch (error) { print(error); diff --git a/lib/providers/medicine_provider.dart b/lib/providers/medicine_provider.dart new file mode 100644 index 00000000..e69de29b