Skip to content

Commit

Permalink
All print statements for errors and exceptions have been placed behin…
Browse files Browse the repository at this point in the history
…d a debug flag.
  • Loading branch information
larryaasen committed Jul 31, 2023
1 parent 1c981d8 commit 18ba1ca
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 113 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Next

- All print statements for errors and exceptions have been placed behind a debug flag.

## 8.1.0-alpha.2

- Fixed an issue related to the stream updates from the previous release of 8.1.0-alpha.1.
Expand Down
14 changes: 7 additions & 7 deletions bin/itunes_lookup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void main(List<String> arguments) async {
}

final iTunes = ITunesSearchAPI();
iTunes.debugEnabled = true;
iTunes.debugLogging = true;
const countryCode = 'US';

Map? results;
Expand All @@ -52,12 +52,12 @@ void main(List<String> arguments) async {
return;
}

final bundleId = ITunesResults.bundleId(results);
final description = ITunesResults.description(results);
final minAppVersion = ITunesResults.minAppVersion(results);
final releaseNotes = ITunesResults.releaseNotes(results);
final trackViewUrl = ITunesResults.trackViewUrl(results);
final version = ITunesResults.version(results);
final bundleId = iTunes.bundleId(results);
final description = iTunes.description(results);
final minAppVersion = iTunes.minAppVersion(results);
final releaseNotes = iTunes.releaseNotes(results);
final trackViewUrl = iTunes.trackViewUrl(results);
final version = iTunes.version(results);

print('itunes_lookup bundleId: $bundleId');
print('itunes_lookup description: $description');
Expand Down
10 changes: 5 additions & 5 deletions bin/playstore_lookup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void main(List<String> arguments) async {
}

final playStore = PlayStoreSearchAPI();
playStore.debugEnabled = true;
playStore.debugLogging = true;

final results = await playStore.lookupById(lookupId, country: lookupCountry);

Expand All @@ -45,10 +45,10 @@ void main(List<String> arguments) async {
return;
}

final description = PlayStoreResults.description(results);
final minAppVersion = PlayStoreResults.minAppVersion(results);
final releaseNotes = PlayStoreResults.releaseNotes(results);
final version = PlayStoreResults.version(results);
final description = playStore.description(results);
final minAppVersion = playStore.minAppVersion(results);
final releaseNotes = playStore.releaseNotes(results);
final version = playStore.version(results);

print('playstore_lookup description: $description');
print('playstore_lookup minAppVersion: $minAppVersion');
Expand Down
74 changes: 48 additions & 26 deletions lib/src/itunes_search_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class ITunesSearchAPI {
/// Provide an HTTP Client that can be replaced for mock testing.
http.Client? client = http.Client();

bool debugEnabled = false;
/// Enable print statements for debugging.
bool debugLogging = false;

/// Look up by bundle id.
/// Example: look up Google Maps iOS App:
Expand All @@ -36,20 +37,22 @@ class ITunesSearchAPI {
final url = lookupURLByBundleId(bundleId,
country: country ??= '', useCacheBuster: useCacheBuster)!;
if (debugEnabled) {
if (debugLogging) {
print('upgrader: download: $url');
}
try {
final response = await client!.get(Uri.parse(url));
if (debugEnabled) {
if (debugLogging) {
print('upgrader: response statusCode: ${response.statusCode}');
}
final decodedResults = _decodeResults(response.body);
return decodedResults;
} catch (e) {
print('upgrader: lookupByBundleId exception: $e');
if (debugLogging) {
print('upgrader: lookupByBundleId exception: $e');

Check warning on line 54 in lib/src/itunes_search_api.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/itunes_search_api.dart#L53-L54

Added lines #L53 - L54 were not covered by tests
}
return null;
}
}
Expand All @@ -66,15 +69,17 @@ class ITunesSearchAPI {
final url =
lookupURLById(id, country: country, useCacheBuster: useCacheBuster)!;
if (debugEnabled) {
if (debugLogging) {
print('upgrader: download: $url');
}
try {
final response = await client!.get(Uri.parse(url));
final decodedResults = _decodeResults(response.body);
return decodedResults;
} catch (e) {
print('upgrader: lookupById exception: $e');
if (debugLogging) {
print('upgrader: lookupById exception: $e');

Check warning on line 81 in lib/src/itunes_search_api.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/itunes_search_api.dart#L80-L81

Added lines #L80 - L81 were not covered by tests
}
return null;
}
}
Expand Down Expand Up @@ -131,7 +136,7 @@ class ITunesSearchAPI {
if (decodedResults is Map) {
final resultCount = decodedResults['resultCount'];
if (resultCount == 0) {
if (debugEnabled) {
if (debugLogging) {
print(
'upgrader.ITunesSearchAPI: results are empty: $decodedResults');
}
Expand All @@ -143,98 +148,115 @@ class ITunesSearchAPI {
}
}
class ITunesResults {
extension ITunesResults on ITunesSearchAPI {
/// Return field bundleId from iTunes results.
static String? bundleId(Map response) {
String? bundleId(Map response) {
String? value;
try {
value = response['results'][0]['bundleId'];
} catch (e) {
print('upgrader.ITunesResults.bundleId: $e');
if (debugLogging) {
print('upgrader.ITunesResults.bundleId: $e');

Check warning on line 159 in lib/src/itunes_search_api.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/itunes_search_api.dart#L158-L159

Added lines #L158 - L159 were not covered by tests
}
}
return value;
}
/// Return field currency from iTunes results.
static String? currency(Map response) {
String? currency(Map response) {
String? value;
try {
value = response['results'][0]['currency'];
} catch (e) {
print('upgrader.ITunesResults.currency: $e');
if (debugLogging) {
print('upgrader.ITunesResults.currency: $e');

Check warning on line 172 in lib/src/itunes_search_api.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/itunes_search_api.dart#L171-L172

Added lines #L171 - L172 were not covered by tests
}
}
return value;
}
/// Return field description from iTunes results.
static String? description(Map response) {
String? description(Map response) {
String? value;
try {
value = response['results'][0]['description'];
} catch (e) {
print('upgrader.ITunesResults.description: $e');
if (debugLogging) {
print('upgrader.ITunesResults.description: $e');

Check warning on line 185 in lib/src/itunes_search_api.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/itunes_search_api.dart#L185

Added line #L185 was not covered by tests
}
}
return value;
}
/// Return the minimum app version taken from the tag in the description field
/// from the store response. The format is: [:mav: 1.2.3].
/// Returns version, such as 1.2.3, or null.
static Version? minAppVersion(Map response, {String tagName = 'mav'}) {
Version? minAppVersion(Map response, {String tagName = 'mav'}) {
Version? version;
try {
final description = ITunesResults.description(response);
if (description != null) {
final desc = description(response);
if (desc != null) {
String regExpSource = r"\[\:tagName\:[\s]*(?<version>[^\s]+)[\s]*\]";
regExpSource = regExpSource.replaceAll(RegExp('tagName'), tagName);
final regExp = RegExp(regExpSource, caseSensitive: false);
final match = regExp.firstMatch(description);
final match = regExp.firstMatch(desc);
final mav = match?.namedGroup('version');
if (mav != null) {
try {
// Verify version string using class Version
version = Version.parse(mav);
} on Exception catch (e) {
print('upgrader: ITunesResults.minAppVersion: $tagName error: $e');
if (debugLogging) {
print(
'upgrader: ITunesResults.minAppVersion: $tagName error: $e');

Check warning on line 212 in lib/src/itunes_search_api.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/itunes_search_api.dart#L210-L212

Added lines #L210 - L212 were not covered by tests
}
}
}
}
} on Exception catch (e) {
print('upgrader.ITunesResults.minAppVersion : $e');
if (debugLogging) {
print('upgrader.ITunesResults.minAppVersion : $e');

Check warning on line 219 in lib/src/itunes_search_api.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/itunes_search_api.dart#L218-L219

Added lines #L218 - L219 were not covered by tests
}
}
return version;
}
/// Return field releaseNotes from iTunes results.
static String? releaseNotes(Map response) {
String? releaseNotes(Map response) {
String? value;
try {
value = response['results'][0]['releaseNotes'];
} catch (e) {
print('upgrader.ITunesResults.releaseNotes: $e');
if (debugLogging) {
print('upgrader.ITunesResults.releaseNotes: $e');

Check warning on line 232 in lib/src/itunes_search_api.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/itunes_search_api.dart#L231-L232

Added lines #L231 - L232 were not covered by tests
}
}
return value;
}
/// Return field trackViewUrl from iTunes results.
static String? trackViewUrl(Map response) {
String? trackViewUrl(Map response) {
String? value;
try {
value = response['results'][0]['trackViewUrl'];
} catch (e) {
print('upgrader.ITunesResults.trackViewUrl: $e');
if (debugLogging) {
print('upgrader.ITunesResults.trackViewUrl: $e');

Check warning on line 245 in lib/src/itunes_search_api.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/itunes_search_api.dart#L244-L245

Added lines #L244 - L245 were not covered by tests
}
}
return value;
}
/// Return field version from iTunes results.
static String? version(Map response) {
String? version(Map response) {
String? value;
try {
value = response['results'][0]['version'];
} catch (e) {
print('upgrader.ITunesResults.version: $e');
if (debugLogging) {
print('upgrader.ITunesResults.version: $e');

Check warning on line 258 in lib/src/itunes_search_api.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/itunes_search_api.dart#L257-L258

Added lines #L257 - L258 were not covered by tests
}
}
return value;
}
Expand Down
Loading

0 comments on commit 18ba1ca

Please sign in to comment.