lookupById method

Future<Document?> lookupById(
  1. String id, {
  2. String? country = 'US',
  3. String? language = 'en',
  4. bool useCacheBuster = true,
})

Look up by id.

Implementation

Future<Document?> lookupById(String id,
    {String? country = 'US',
    String? language = 'en',
    bool useCacheBuster = true}) async {
  assert(id.isNotEmpty);
  if (id.isEmpty) return null;

  final url = lookupURLById(id,
      country: country, language: language, useCacheBuster: useCacheBuster)!;
  if (debugLogging) {
    print('upgrader: lookupById url: $url');
  }

  try {
    final response =
        await client!.get(Uri.parse(url), headers: clientHeaders);
    if (response.statusCode < 200 || response.statusCode >= 300) {
      if (debugLogging) {
        print(
            'upgrader: Can\'t find an app in the Play Store with the id: $id');
      }
      return null;
    }

    // Uncomment for creating unit test input files.
    // final file = io.File('file.txt');
    // await file.writeAsBytes(response.bodyBytes);

    final decodedResults = _decodeResults(response.body);

    return decodedResults;
  } on Exception catch (e) {
    if (debugLogging) {
      print('upgrader: lookupById exception: $e');
    }
    return null;
  }
}