Skip to content

Commit

Permalink
Merge branch 'pass-language-code-to-itunes-search'
Browse files Browse the repository at this point in the history
  • Loading branch information
Add00w committed Sep 3, 2024
2 parents fa02d08 + f81875d commit b09ba54
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
20 changes: 14 additions & 6 deletions lib/src/itunes_search_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ class ITunesSearchAPI {
/// ```lookupURLByBundleId('com.google.Maps');```
/// ```lookupURLByBundleId('com.google.Maps', country: 'FR');```
Future<Map?> lookupByBundleId(String bundleId,
{String? country = 'US', bool useCacheBuster = true}) async {
{String? country = 'US',
String? language = 'en',
bool useCacheBuster = true}) async {
assert(bundleId.isNotEmpty);
if (bundleId.isEmpty) {
return null;
}
final url = lookupURLByBundleId(bundleId,
country: country ?? '', useCacheBuster: useCacheBuster)!;
country: country ?? '',
language: language ?? '',
useCacheBuster: useCacheBuster)!;
if (debugLogging) {
print('upgrader: download: $url');
}
Expand Down Expand Up @@ -94,14 +98,18 @@ class ITunesSearchAPI {
/// ```lookupURLByBundleId('com.google.Maps');```
/// ```lookupURLByBundleId('com.google.Maps', country: 'FR');```
String? lookupURLByBundleId(String bundleId,
{String country = 'US', bool useCacheBuster = true}) {
{String country = 'US',
String language = 'en',
bool useCacheBuster = true}) {
if (bundleId.isEmpty) {
return null;
}
return lookupURLByQSP(
{'bundleId': bundleId, 'country': country.toUpperCase()},
useCacheBuster: useCacheBuster);
return lookupURLByQSP({
'bundleId': bundleId,
'country': country.toUpperCase(),
'lang': language
}, useCacheBuster: useCacheBuster);
}
/// Look up URL by id.
Expand Down
31 changes: 31 additions & 0 deletions lib/src/upgrader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,37 @@ class Upgrader with WidgetsBindingObserver {
state.countryCodeOverride ?? findCountryCode(locale: locale);
if (state.debugLogging) {
print('upgrader: countryCode: $country');
// The language code of the locale, defaulting to `en`.
final language = languageCode ?? findLanguageCode();
if (debugLogging) {
print('upgrader: languageCode: $language');
}

// Get Android version from Google Play Store, or
// get iOS version from iTunes Store.
if (upgraderOS.isAndroid) {
await _getAndroidStoreVersion(country: country, language: language);
} else if (upgraderOS.isIOS) {
final iTunes = ITunesSearchAPI();
iTunes.debugLogging = debugLogging;
iTunes.client = client;
final response = await (iTunes
.lookupByBundleId(_packageInfo!.packageName, language: language,
country:country));

if (response != null) {
_appStoreVersion = iTunes.version(response);
_appStoreListingURL = iTunes.trackViewUrl(response);
_releaseNotes ??= iTunes.releaseNotes(response);
final mav = iTunes.minAppVersion(response);
if (mav != null) {
minAppVersion = mav.toString();
if (debugLogging) {
print('upgrader: ITunesResults.minAppVersion: $minAppVersion');
}
}
}
}
}

// Determine the language code of the locale, defaulting to `en`.
Expand Down
9 changes: 7 additions & 2 deletions test/itunes_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ void main() {
expect(
iTunes.lookupURLByBundleId('com.google.Maps', useCacheBuster: false),
equals(
'https://itunes.apple.com/lookup?bundleId=com.google.Maps&country=US'));
'https://itunes.apple.com/lookup?bundleId=com.google.Maps&country=US&lang=en'));
expect(
iTunes.lookupURLByBundleId('com.google.Maps',
useCacheBuster: false, language: 'ar'),
equals(
'https://itunes.apple.com/lookup?bundleId=com.google.Maps&country=US&lang=ar'));
expect(iTunes.lookupURLById('585027354', useCacheBuster: false),
equals('https://itunes.apple.com/lookup?id=585027354&country=US'));
expect(
Expand All @@ -30,7 +35,7 @@ void main() {

// Test the URL using the cache buster and remove it from the URL
const testUrl =
'https://itunes.apple.com/lookup?bundleId=com.google.Maps&country=US&_cb=';
'https://itunes.apple.com/lookup?bundleId=com.google.Maps&country=US&lang=en&_cb=';
final url = iTunes
.lookupURLByBundleId('com.google.Maps', useCacheBuster: true)!
.substring(0, testUrl.length);
Expand Down

0 comments on commit b09ba54

Please sign in to comment.