<commit_before>import 'dart:async';

import 'package:campus_mobile_experimental/app_networking.dart';
import 'package:campus_mobile_experimental/core/models/cards.dart';

class CardsService {
  bool _isLoading = false;
  DateTime? _lastUpdated;
  String? _error;

  Map<String, CardsModel>? _cardsModel;

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

  Future<bool> fetchCards(String? ucsdAffiliation) async {
    _error = null;
    _isLoading = true;

    if (ucsdAffiliation == null) ucsdAffiliation = "";

    /// API Manager Service
    try {
      String cardListEndpoint =
          "https://api-qa.ucsd.edu:8243/defaultcards/v7.0.0/defaultcards?ucsdaffiliation=" +
              ucsdAffiliation;
      String _response =
          await _networkHelper.authorizedFetch(cardListEndpoint, headers);
      _cardsModel = cardsModelFromJson(_response);
      _isLoading = false;
      return true;
    } catch (e) {
      if (e.toString().contains("401")) {
        if (await getNewToken()) {
          return await fetchCards(ucsdAffiliation);
        }
      }
      _error = e.toString();
      _isLoading = false;
      return false;
    }

    /// Card Prototyping Service
    // try {
    //   String cardPrototypeEndpoint =
    //       "https://mobile.ucsd.edu/replatform/v1/qa/cards/prototypes/card-prototype--copy-me.json";
    //   String _response = await _networkHelper.fetchData(cardPrototypeEndpoint);
    //   _cardsModel = cardsModelFromJson(_response);
    //   _isLoading = false;
    //   return true;
    // } catch (e) {
    //   print(e);
    //   _error = e.toString();
    //   _isLoading = false;<commit_msg>Refactor default cards api for dynamic versioning<commit_after>import 'dart:async';

import 'package:campus_mobile_experimental/app_networking.dart';
import 'package:campus_mobile_experimental/core/models/cards.dart';

class CardsService {
  bool _isLoading = false;
  DateTime? _lastUpdated;
  String? _error;

  Map<String, CardsModel>? _cardsModel;

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

  Future<bool> fetchCards(String? ucsdAffiliation) async {
    _error = null;
    _isLoading = true;

    if (ucsdAffiliation == null) ucsdAffiliation = "";

    /// API Manager Service
    try {
      String cardListEndpoint =
          "https://api-qa.ucsd.edu:8243/mobilecardsservice/v1.0.0/mobilecardslist?version=7&ucsdaffiliation=" +
              ucsdAffiliation;
      String _response =
          await _networkHelper.authorizedFetch(cardListEndpoint, headers);
      _cardsModel = cardsModelFromJson(_response);
      _isLoading = false;
      return true;
    } catch (e) {
      if (e.toString().contains("401")) {
        if (await getNewToken()) {
          return await fetchCards(ucsdAffiliation);
        }
      }
      _error = e.toString();
      _isLoading = false;
      return false;
    }

    /// Card Prototyping Service
    // try {
    //   String cardPrototypeEndpoint =
    //       "https://mobile.ucsd.edu/replatform/v1/qa/cards/prototypes/card-prototype--copy-me.json";
    //   String _response = await _networkHelper.fetchData(cardPrototypeEndpoint);
    //   _cardsModel = cardsModelFromJson(_response);
    //   _isLoading = false;
    //   return true;
    // } catch (e) {
    //   print(e);
    //   _error = e.toString();
    //   _isLoading = false;
{'fraction_non_alphanumeric': 0.1209700427960057, 'fraction_numerical': 0.006562054208273894, 'mean_word_length': 2.79027027027027, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6787419', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1064, 'n_words': 203}