From a06d7b9f64e603d388fc3e31498b2e3d6241c66d Mon Sep 17 00:00:00 2001 From: vikramsharma Date: Fri, 14 Sep 2018 15:50:20 +0530 Subject: [PATCH 1/3] added validation function for Response. --- lib/network/Github.dart | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/network/Github.dart b/lib/network/Github.dart index 9d67768..ca4cf37 100644 --- a/lib/network/Github.dart +++ b/lib/network/Github.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:LoginUI/ui/AppConstants.dart'; +import 'package:LoginUI/utils/SharedPrefs.dart'; import 'package:http/http.dart' as http; import 'package:url_launcher/url_launcher.dart'; @@ -133,4 +134,20 @@ class Github { print(fullUrl); return http.get(fullUrl); } + + static void _defaultUnAuthFunc(){} + + static bool isValidResponse(http.Response response,{Function() onUnAuthorize:_defaultUnAuthFunc,bool clearAccessToken : false} ){ + switch(response.statusCode){ + case 200 : return true; + case 401 : onUnAuthorize(); + if(clearAccessToken)SharedPrefs().saveToken(""); + return false;//UnAuthorized + case 404: return false; + } + + return true; + } + + } From b3c93ae5f5da05d8392c73bfb5a8a072768d52c1 Mon Sep 17 00:00:00 2001 From: vikramsharma Date: Fri, 14 Sep 2018 15:59:39 +0530 Subject: [PATCH 2/3] added validation function for Response. --- lib/network/Github.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/network/Github.dart b/lib/network/Github.dart index ca4cf37..f63d580 100644 --- a/lib/network/Github.dart +++ b/lib/network/Github.dart @@ -137,6 +137,11 @@ class Github { static void _defaultUnAuthFunc(){} + /** + * this method will check if response is valid or not on basis of Response code. + * Optional param [onUnAuthorize] onUnauthorize will be called when response is unAuthorized. + * returns boolean as final response. + */ static bool isValidResponse(http.Response response,{Function() onUnAuthorize:_defaultUnAuthFunc,bool clearAccessToken : false} ){ switch(response.statusCode){ case 200 : return true; From f5818e25aeb43653b1e18a13654dbab651756f7f Mon Sep 17 00:00:00 2001 From: vikramsharma Date: Fri, 14 Sep 2018 16:06:26 +0530 Subject: [PATCH 3/3] merged new code --- .idea/libraries/Dart_Packages.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml index ddde673..47617b6 100644 --- a/.idea/libraries/Dart_Packages.xml +++ b/.idea/libraries/Dart_Packages.xml @@ -75,14 +75,14 @@ - - @@ -292,7 +292,7 @@ - @@ -466,9 +466,9 @@ - - - + + +