getGeoInfo static method

Future<Result> getGeoInfo(
  1. String pincode
)

Implementation

static Future<Result<dynamic>> getGeoInfo(String pincode) async {
  await checkKwikpassHealth();

  try {
    final gokwik = DioClient().getClient();

    final results = await Future.wait([
      cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.gkAccessTokenKey)!),
      cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.gkMerchantIdKey)!),
      cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.gkRequestIdKey)!),
      cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.integrationType)!),
    ]);

    final accessToken = results[0];
    final mid = results[1];
    final requestId = results[2];
    final integrationType = results[3];

    final headers = <String, String>{
      'accept': 'application/json',
      cdnConfigInstance.getHeader(APIHeaderKeys.gkMerchantId)!: mid ?? '',
      cdnConfigInstance.getHeader(APIHeaderKeys.kpIntegrationType)!:
          integrationType ?? 'PLUGIN',
    };

    if (accessToken != null && accessToken.isNotEmpty) {
      headers[cdnConfigInstance.getHeader(APIHeaderKeys.gkAccessToken)!] = accessToken;
    }

    if (requestId != null && requestId.isNotEmpty) {
      headers[cdnConfigInstance.getHeader(APIHeaderKeys.gkRequestId)!] = requestId;
    }

    final response = await gokwik.get(
      cdnConfigInstance.getEndpoint(APIEndpointKeys.getGeoInfo)!,
      queryParameters: {'pincode': pincode},
      options: Options(headers: headers),
    );

    return Success(response.data);
  } catch (err) {
    throw handleApiError(err);
  }
}