fetchAdsByQuadKey method

Future<AdFeatureCollection?> fetchAdsByQuadKey(
  1. String key,
  2. int scale, {
  3. dynamic completion(
    1. AdFeatureCollection?
    )?,
})

Implementation

Future<AdFeatureCollection?> fetchAdsByQuadKey(String key, int scale,
    {Function(AdFeatureCollection?)? completion}) async {
  try {
    final source = _source.fetchAdsByQuadKey(key, scale);
    final result = await _api.getRequest(source: source);
    if (result is Error) {
      throw Exception("Ad API failed: $source");
    }
    PMLogger.d("mbox: start fetchAdsFromQuadKey: $key");
    final http.Response response = (result as Success).value;
    final json = utf8.decode(response.bodyBytes);
    PMLogger.d("mbox: AdS server Response: $json");
    final collection = AdFeatureCollection.fromJson(jsonDecode(json));
    PMLogger.d(collection);
    if (completion != null) completion(collection);
    return collection;
  } on Exception catch (e) {
    PMLogger.e(e);
  }
  return null;
}