getStreetsByName method

Future<BuiltList<StreetsBcnStreetApiModel>> getStreetsByName(
  1. String name, {
  2. LanguageCode languageCode = LanguageCode.es,
})

Implementation

Future<BuiltList<StreetsBcnStreetApiModel>> getStreetsByName(String name,
    {LanguageCode languageCode: LanguageCode.es}) async {
  var response = await UserAgentClient(http.Client()).get(Uri.https(
      'w33.bcn.cat',
      'geoBCN/serveis/territori/vies',
      {'nom': name, 'lang': languageCode.name.toUpperCase()}));
  if (response.statusCode == 200) {
    logger.d("Response: ${response.body}");
    final StreetsBcnResponseApiModel streets =
        standardSerializers.deserialize(jsonDecode(response.body),
                specifiedType: FullType((StreetsBcnResponseApiModel)))
            as StreetsBcnResponseApiModel;
    return streets.results;
  } else {
    logger.e("Error ${response.reasonPhrase} ${response.statusCode}");
    return Future.error(response);
  }
}