From 01e8996572aecf072f7bf92fbe67e7bed7d413a5 Mon Sep 17 00:00:00 2001 From: Andrea Busi Date: Tue, 28 Mar 2023 16:46:26 +0200 Subject: [PATCH] refactor: Use new request parameters for network downloads endpoint --- Sources/Earthquake Network/Costanti.h | 2 +- .../Earthquake Network/Models/EQNManager.m | 31 +++++++------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/Sources/Earthquake Network/Costanti.h b/Sources/Earthquake Network/Costanti.h index 503c85c..a6bf2f4 100644 --- a/Sources/Earthquake Network/Costanti.h +++ b/Sources/Earthquake Network/Costanti.h @@ -33,7 +33,7 @@ static double const EQNMathKelvin = 273.15; #pragma mark - Server APIs /// Download reti sismiche -static NSString * const EQNServerUrlDownloadRetiSismiche = @"https://cache.earthquakenetwork.it/distquake_download_automatic21%@.php"; +static NSString * const EQNServerUrlDownloadRetiSismiche = @"https://cache.earthquakenetwork.it/distquake_download_automatic21.php%@"; /// Recupera il tempo ancora disponibile per la versione Pro scontata static NSString * const EQNServerUrlOfferTimeRemaining = @"https://srv.earthquakenetwork.it/distquake_download_offer_time_remaining.php"; /// Registra l'abbonamento acquistato dall'utente diff --git a/Sources/Earthquake Network/Models/EQNManager.m b/Sources/Earthquake Network/Models/EQNManager.m index 64176cf..a9cddc7 100644 --- a/Sources/Earthquake Network/Models/EQNManager.m +++ b/Sources/Earthquake Network/Models/EQNManager.m @@ -120,28 +120,21 @@ - (void)scaricaReteSismica { - // Per ridurre i dati trasferiti tra app e server, ci sono degli endpoint dedicati - // in base alla magnitudo impostata dall'utente (per valori inferiori a 2.0). - // Se l'opzione `Mostra sismi di qualsiasi magnitudo se a meno di 50km` è attiva, - // dobbiamo utilizzare l'endpoint `_M0_0` perchè dobbiamo scaricare tutti i dati - - NSString *queryString = @""; - double filterMagnitude = [[EQNSeismic shared].magnitudoMinima doubleValue]; - bool filterAnyNearEarthquake = [EQNSeismic shared].sismiQualsiasiAbilitati; - - if (filterMagnitude < 0.5 || filterAnyNearEarthquake) { - queryString = @"_M0_0"; - } else if (filterMagnitude < 1.0) { - queryString = @"_M0_5"; - } else if (filterMagnitude < 1.5) { - queryString = @"_M1_0"; - } else if (filterMagnitude < 2.0) { - queryString = @"_M1_5"; + // L'endpoint per lo scaricamento dei dati prende due parametri: pro per il provider selezionato, mag per la + // magnitudo minima. Se l'utente ha selezionato più di un provider, inviamo ALL. Mentre la magnitudo + // deve avere sempre una cifra decimale (es 2.0). + + NSString *filterProvider = @""; + NSArray *networks = [EQNUserData.sharedData seismicNetworksSelected]; + if (networks.count == 1) { + filterProvider = [networks firstObject]; } else { - // verrà usato l'url base - queryString = @""; + filterProvider = @"ALL"; } + NSString *filterMagnitude = [EQNSeismic shared].magnitudoMinima; + + NSString *queryString = [NSString stringWithFormat:@"?pro=%@&mag=%@", filterProvider, filterMagnitude]; NSString *urlString = [NSString stringWithFormat:EQNServerUrlDownloadRetiSismiche, queryString]; NSURL *url = [NSURL URLWithString:urlString]; NSLog(@"[EQNManager] Url utilizzato per download reti sismiche: %@", url.absoluteURL);