From aac1e5d24137fc5ee94301302512a1dde26d9eb2 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 22 Apr 2020 18:24:49 +0300 Subject: [PATCH 1/3] App client + Base URL --- lib/client/app_client.dart | 14 ++++++++++++++ lib/interceptor/http_interceptor.dart | 6 ++++++ lib/models/medicine_model.dart | 0 lib/providers/auth_provider.dart | 28 +++++++++++---------------- lib/providers/medicine_provider.dart | 0 5 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 lib/client/app_client.dart create mode 100644 lib/models/medicine_model.dart create mode 100644 lib/providers/medicine_provider.dart diff --git a/lib/client/app_client.dart b/lib/client/app_client.dart new file mode 100644 index 00000000..1c37995f --- /dev/null +++ b/lib/client/app_client.dart @@ -0,0 +1,14 @@ +import 'package:doctor_app_flutter/interceptor/http_interceptor.dart'; +import 'package:http/http.dart'; + +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 009fd345..99f82d21 100644 --- a/lib/interceptor/http_interceptor.dart +++ b/lib/interceptor/http_interceptor.dart @@ -3,6 +3,7 @@ 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'; DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); @@ -14,6 +15,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 7af750ca..d7a470e2 100644 --- a/lib/providers/auth_provider.dart +++ b/lib/providers/auth_provider.dart @@ -1,32 +1,26 @@ import 'dart:convert'; - -import 'package:doctor_app_flutter/interceptor/http_interceptor.dart'; +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 '../models/user_model.dart'; const LOGIN_URL = - 'https://hmgwebservices.com/Services/Sentry.svc/REST/MemberLogIN_New'; + 'Services/Sentry.svc/REST/MemberLogIN_New'; const INSERT_DEVICE_IMEI = - 'https://hmgwebservices.com/Services/Sentry.svc/REST/DoctorApplication_INSERTDeviceIMEI'; + 'Services/Sentry.svc/REST/DoctorApplication_INSERTDeviceIMEI'; const SELECT_DEVICE_IMEI = - 'https://hmgwebservices.com/Services/Sentry.svc/REST/DoctorApplication_SELECTDeviceIMEIbyIMEI'; + 'Services/Sentry.svc/REST/DoctorApplication_SELECTDeviceIMEIbyIMEI'; const SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE = - 'https://hmgwebservices.com/Services/Sentry.svc/REST/DoctorApplication_SendActivationCodebyOTPNotificationType'; + 'Services/Sentry.svc/REST/DoctorApplication_SendActivationCodebyOTPNotificationType'; -const MEMBER_CHECK_ACTIVATION_CODE_NEW ='https://hmgwebservices.com/Services/Sentry.svc/REST/MemberCheckActivationCode_New'; +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, @@ -48,7 +42,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); @@ -60,7 +54,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); @@ -72,7 +66,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); @@ -84,7 +78,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 From 25b7f9a7456fa76b0a84e1cb5329d4378a4d77af Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 22 Apr 2020 18:31:02 +0300 Subject: [PATCH 2/3] add comment and move intercepter to client packege --- lib/client/app_client.dart | 4 ++++ lib/{interceptor => client}/http_interceptor.dart | 0 2 files changed, 4 insertions(+) rename lib/{interceptor => client}/http_interceptor.dart (100%) diff --git a/lib/client/app_client.dart b/lib/client/app_client.dart index 1c37995f..6018b041 100644 --- a/lib/client/app_client.dart +++ b/lib/client/app_client.dart @@ -1,6 +1,10 @@ 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/"; diff --git a/lib/interceptor/http_interceptor.dart b/lib/client/http_interceptor.dart similarity index 100% rename from lib/interceptor/http_interceptor.dart rename to lib/client/http_interceptor.dart From 586c41fe96ea64e136a8d486f5212e5cc991a9b4 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 22 Apr 2020 18:50:04 +0300 Subject: [PATCH 3/3] fix --- lib/{client => interceptor}/http_interceptor.dart | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib/{client => interceptor}/http_interceptor.dart (100%) diff --git a/lib/client/http_interceptor.dart b/lib/interceptor/http_interceptor.dart similarity index 100% rename from lib/client/http_interceptor.dart rename to lib/interceptor/http_interceptor.dart