Skip to content

Commit

Permalink
Revert "Update endpoint in news.dart"
Browse files Browse the repository at this point in the history
  • Loading branch information
c3bryant authored Nov 22, 2021
1 parent 84224fe commit 528e11a
Showing 1 changed file with 2 additions and 33 deletions.
35 changes: 2 additions & 33 deletions lib/core/services/news.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ class NewsService {
String? _error;

final NetworkHelper _networkHelper = NetworkHelper();
final Map<String, String> headers = {
"accept": "application/json",
};

final String endpoint =
"https://api-qa.ucsd.edu:8243/qa/campusnews/v1/ucsdnewsaggregator";
'https://s3-us-west-2.amazonaws.com/ucsd-its-wts/now_ucsandiego/v1/allstories.json';

NewsModel _newsModels = NewsModel();

Expand All @@ -23,46 +19,19 @@ class NewsService {
_isLoading = true;
try {
/// fetch data
String _response =
await (_networkHelper.authorizedFetch(endpoint, headers));
String _response = await _networkHelper.fetchData(endpoint);

/// parse data
_newsModels = newsModelFromJson(_response);
_isLoading = false;
return true;
} catch (e) {
if (e.toString().contains("401")) {
if (await getNewToken()) {
return await fetchData();
}
}

_error = e.toString();
_isLoading = false;
return false;
}
}

Future<bool> getNewToken() async {
final String tokenEndpoint = "https://api-qa.ucsd.edu:8243/token";
final Map<String, String> tokenHeaders = {
"content-type": 'application/x-www-form-urlencoded',
"Authorization":
"Basic djJlNEpYa0NJUHZ5akFWT0VRXzRqZmZUdDkwYTp2emNBZGFzZWpmaWZiUDc2VUJjNDNNVDExclVh"
};
try {
var response = await _networkHelper.authorizedPost(
tokenEndpoint, tokenHeaders, "grant_type=client_credentials");

headers["Authorization"] = "Bearer " + response["access_token"];

return true;
} catch (e) {
_error = e.toString();
return false;
}
}

String? get error => _error;
NewsModel get newsModels => _newsModels;
bool get isLoading => _isLoading;
Expand Down

0 comments on commit 528e11a

Please sign in to comment.