mirror of
https://github.com/hmalik144/easy_cc_flutter.git
synced 2026-03-18 15:45:56 +00:00
Removal of api key
Network calls, integration of retrofit api added backup api
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import '../model/Currency.dart';
|
||||
import '../prefs/CurrencyPair.dart';
|
||||
|
||||
abstract class Repository {
|
||||
CurrencyPair getConversionPair();
|
||||
Future<void> setConversionPair(String fromCurrency, String toCurrency);
|
||||
Future<Currency> getConversationRateFromApi(String fromCurrency, String toCurrency);
|
||||
}
|
||||
@@ -1,11 +1,22 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:easy_cc_flutter/Utils/currencyUtils.dart';
|
||||
import 'package:easy_cc_flutter/data/model/Currency.dart';
|
||||
import 'package:easy_cc_flutter/data/prefs/CurrencyPair.dart';
|
||||
import 'package:easy_cc_flutter/data/prefs/PreferenceProvider.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
|
||||
import '../../locator.dart';
|
||||
import '../../main.dart';
|
||||
import '../network/backupCurrencyApi.dart';
|
||||
import '../network/currencyApi.dart';
|
||||
import '../network/safeApiCall.dart';
|
||||
import 'Repository.dart';
|
||||
|
||||
class RepositoryImpl extends Repository {
|
||||
class RepositoryImpl extends Repository with SafeApiCall {
|
||||
final PreferenceProvider _prefs = locator<PreferenceProvider>();
|
||||
final CurrencyApi _api = locator<CurrencyApi>();
|
||||
final BackupCurrencyApi _backupApi = locator<BackupCurrencyApi>();
|
||||
|
||||
@override
|
||||
CurrencyPair getConversionPair() {
|
||||
@@ -17,4 +28,20 @@ class RepositoryImpl extends Repository {
|
||||
return _prefs.saveConversionPair(fromCurrency, toCurrency);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Currency> getConversationRateFromApi(String fromCurrency, String toCurrency) async {
|
||||
String from = fromCurrency.getCurrencyCode();
|
||||
String to = toCurrency.getCurrencyCode();
|
||||
|
||||
String currency = "${from}_$to";
|
||||
|
||||
try {
|
||||
ResponseObject responseObject = await getDataFromApiCall(_api.getConversion(dotenv.env['apiKey']!, currency));
|
||||
return responseObject.convert();
|
||||
} on HttpException catch(error) {
|
||||
logger.e(error);
|
||||
CurrencyResponse responseObject = await getDataFromApiCall(_backupApi.getCurrencyRate(from, to));
|
||||
return responseObject.convert();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user