herepy 3.6.3__tar.gz → 3.6.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. {herepy-3.6.3 → herepy-3.6.5}/PKG-INFO +1 -1
  2. {herepy-3.6.3 → herepy-3.6.5}/herepy/__init__.py +1 -1
  3. {herepy-3.6.3 → herepy-3.6.5}/herepy/geocoder_api.py +20 -10
  4. {herepy-3.6.3 → herepy-3.6.5}/herepy/routing_api.py +19 -17
  5. {herepy-3.6.3 → herepy-3.6.5}/herepy/utils.py +11 -4
  6. {herepy-3.6.3 → herepy-3.6.5}/herepy.egg-info/PKG-INFO +1 -1
  7. {herepy-3.6.3 → herepy-3.6.5}/tests/test_geocoder_api.py +50 -2
  8. {herepy-3.6.3 → herepy-3.6.5}/tests/test_routing_api.py +62 -3
  9. {herepy-3.6.3 → herepy-3.6.5}/tests/test_utils.py +8 -0
  10. {herepy-3.6.3 → herepy-3.6.5}/COPYING +0 -0
  11. {herepy-3.6.3 → herepy-3.6.5}/LICENSE +0 -0
  12. {herepy-3.6.3 → herepy-3.6.5}/MANIFEST.in +0 -0
  13. {herepy-3.6.3 → herepy-3.6.5}/NOTICE +0 -0
  14. {herepy-3.6.3 → herepy-3.6.5}/README.rst +0 -0
  15. {herepy-3.6.3 → herepy-3.6.5}/herepy/destination_weather_api.py +0 -0
  16. {herepy-3.6.3 → herepy-3.6.5}/herepy/error.py +0 -0
  17. {herepy-3.6.3 → herepy-3.6.5}/herepy/ev_charging_stations_api.py +0 -0
  18. {herepy-3.6.3 → herepy-3.6.5}/herepy/fleet_telematics_api.py +0 -0
  19. {herepy-3.6.3 → herepy-3.6.5}/herepy/geocoder_autocomplete_api.py +0 -0
  20. {herepy-3.6.3 → herepy-3.6.5}/herepy/geocoder_reverse_api.py +0 -0
  21. {herepy-3.6.3 → herepy-3.6.5}/herepy/here_api.py +0 -0
  22. {herepy-3.6.3 → herepy-3.6.5}/herepy/here_enum.py +0 -0
  23. {herepy-3.6.3 → herepy-3.6.5}/herepy/isoline_routing_api.py +0 -0
  24. {herepy-3.6.3 → herepy-3.6.5}/herepy/map_image_api.py +0 -0
  25. {herepy-3.6.3 → herepy-3.6.5}/herepy/map_tile_api.py +0 -0
  26. {herepy-3.6.3 → herepy-3.6.5}/herepy/mercator_projection.py +0 -0
  27. {herepy-3.6.3 → herepy-3.6.5}/herepy/models.py +0 -0
  28. {herepy-3.6.3 → herepy-3.6.5}/herepy/objects.py +0 -0
  29. {herepy-3.6.3 → herepy-3.6.5}/herepy/places_api.py +0 -0
  30. {herepy-3.6.3 → herepy-3.6.5}/herepy/platform/__init__.py +0 -0
  31. {herepy-3.6.3 → herepy-3.6.5}/herepy/platform/tour_planning_api.py +0 -0
  32. {herepy-3.6.3 → herepy-3.6.5}/herepy/polling.py +0 -0
  33. {herepy-3.6.3 → herepy-3.6.5}/herepy/public_transit_api.py +0 -0
  34. {herepy-3.6.3 → herepy-3.6.5}/herepy/py.typed +0 -0
  35. {herepy-3.6.3 → herepy-3.6.5}/herepy/rme_api.py +0 -0
  36. {herepy-3.6.3 → herepy-3.6.5}/herepy/traffic_api.py +0 -0
  37. {herepy-3.6.3 → herepy-3.6.5}/herepy/vector_tile_api.py +0 -0
  38. {herepy-3.6.3 → herepy-3.6.5}/herepy.egg-info/SOURCES.txt +0 -0
  39. {herepy-3.6.3 → herepy-3.6.5}/herepy.egg-info/dependency_links.txt +0 -0
  40. {herepy-3.6.3 → herepy-3.6.5}/herepy.egg-info/requires.txt +0 -0
  41. {herepy-3.6.3 → herepy-3.6.5}/herepy.egg-info/top_level.txt +0 -0
  42. {herepy-3.6.3 → herepy-3.6.5}/requirements.txt +0 -0
  43. {herepy-3.6.3 → herepy-3.6.5}/setup.cfg +0 -0
  44. {herepy-3.6.3 → herepy-3.6.5}/setup.py +0 -0
  45. {herepy-3.6.3 → herepy-3.6.5}/tests/test_destination_weather_api.py +0 -0
  46. {herepy-3.6.3 → herepy-3.6.5}/tests/test_enum.py +0 -0
  47. {herepy-3.6.3 → herepy-3.6.5}/tests/test_ev_charging_stations_api.py +0 -0
  48. {herepy-3.6.3 → herepy-3.6.5}/tests/test_fleet_telematics_api.py +0 -0
  49. {herepy-3.6.3 → herepy-3.6.5}/tests/test_geocoder_autocomplete_api.py +0 -0
  50. {herepy-3.6.3 → herepy-3.6.5}/tests/test_geocoder_reverse_api.py +0 -0
  51. {herepy-3.6.3 → herepy-3.6.5}/tests/test_isoline_routing_api.py +0 -0
  52. {herepy-3.6.3 → herepy-3.6.5}/tests/test_map_image_api.py +0 -0
  53. {herepy-3.6.3 → herepy-3.6.5}/tests/test_map_tile_api.py +0 -0
  54. {herepy-3.6.3 → herepy-3.6.5}/tests/test_mercator_projection.py +0 -0
  55. {herepy-3.6.3 → herepy-3.6.5}/tests/test_models.py +0 -0
  56. {herepy-3.6.3 → herepy-3.6.5}/tests/test_places_api.py +0 -0
  57. {herepy-3.6.3 → herepy-3.6.5}/tests/test_publictransit_api.py +0 -0
  58. {herepy-3.6.3 → herepy-3.6.5}/tests/test_rme_api.py +0 -0
  59. {herepy-3.6.3 → herepy-3.6.5}/tests/test_traffic_api.py +0 -0
  60. {herepy-3.6.3 → herepy-3.6.5}/tests/test_vector_tile_api.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: herepy
3
- Version: 3.6.3
3
+ Version: 3.6.5
4
4
  Summary: A library that provides a Python interface to the HERE APIs
5
5
  Home-page: https://github.com/abdullahselek/HerePy
6
6
  Download-URL: https://pypi.org/pypi/herepy
@@ -6,7 +6,7 @@ __author__ = "Abdullah Selek"
6
6
  __email__ = "abdullahselek.os@gmail.com"
7
7
  __copyright__ = "Copyright (c) 2017 Abdullah Selek"
8
8
  __license__ = "MIT License"
9
- __version__ = "3.6.3"
9
+ __version__ = "3.6.5"
10
10
  __url__ = "https://github.com/abdullahselek/HerePy"
11
11
  __download_url__ = "https://pypi.org/pypi/herepy"
12
12
  __description__ = "A library that provides a Python interface to the HERE APIs"
@@ -106,11 +106,12 @@ class GeocoderApi(HEREApi):
106
106
 
107
107
  def address_with_details(
108
108
  self,
109
- city: str,
110
- country: str,
111
- lang: str = "en-US",
112
109
  house_number: Optional[int] = None,
113
110
  street: Optional[str] = None,
111
+ city: Optional[str] = None,
112
+ postal_code: Optional[str] = None,
113
+ country: Optional[str] = None,
114
+ lang: str = "en-US",
114
115
  ) -> Optional[GeocoderResponse]:
115
116
  """Geocodes with given address details
116
117
  Args:
@@ -122,6 +123,8 @@ class GeocoderApi(HEREApi):
122
123
  city name.
123
124
  country (str):
124
125
  country name.
126
+ postal_code (str):
127
+ postal code.
125
128
  lang (str):
126
129
  BCP47 compliant Language Code.
127
130
  Returns:
@@ -129,16 +132,23 @@ class GeocoderApi(HEREApi):
129
132
  Raises:
130
133
  HEREError"""
131
134
 
132
- qq_query = ""
135
+ qq_params = []
133
136
  if house_number is not None:
134
- qq_query += f"houseNumber={house_number};"
135
- if street is not None:
136
- qq_query += f"street={street};"
137
- qq_query += f"city={city};"
138
- qq_query += f"country={country}"
137
+ qq_params.append(f"houseNumber={house_number}")
138
+ if street:
139
+ qq_params.append(f"street={street}")
140
+ if city:
141
+ qq_params.append(f"city={city}")
142
+ if postal_code:
143
+ qq_params.append(f"postalCode={postal_code}")
144
+ if country:
145
+ qq_params.append(f"country={country}")
146
+
147
+ if len(qq_params) == 0:
148
+ raise HEREError("At least one of the parameters should be provided")
139
149
 
140
150
  data = {
141
- "qq": qq_query,
151
+ "qq": ";".join(qq_params),
142
152
  "apiKey": self._api_key,
143
153
  "lang": lang,
144
154
  }
@@ -5,6 +5,7 @@ import json
5
5
  import os
6
6
  import sys
7
7
  from typing import Dict, List, Optional, Union
8
+ from warnings import warn
8
9
 
9
10
  import requests
10
11
 
@@ -49,12 +50,13 @@ class RoutingApi(HEREApi):
49
50
  response_cls,
50
51
  manipulation_key: str = None,
51
52
  keys_for_manipulation: List = None,
53
+ headers: Optional[Dict[str, str]] = None,
52
54
  ):
53
55
  url = Utils.build_url(base_url, extra_params=data)
54
56
  if manipulation_key and keys_for_manipulation:
55
57
  for k in keys_for_manipulation:
56
58
  url = url.replace(k, manipulation_key)
57
- response = requests.get(url, timeout=self._timeout)
59
+ response = requests.get(url, timeout=self._timeout, headers=headers)
58
60
  json_data = json.loads(response.content.decode("utf8"))
59
61
  if response.status_code == requests.codes.OK:
60
62
  return response_cls.new_from_jsondict(json_data)
@@ -370,6 +372,7 @@ class RoutingApi(HEREApi):
370
372
  return_fields: List[RoutingApiReturnField] = [RoutingApiReturnField.polyline],
371
373
  span_fields: Optional[List[RoutingApiSpanField]] = None,
372
374
  truck: Optional[Dict[str, List[str]]] = None,
375
+ vehicle: Optional[Dict[str, List[str]]] = None,
373
376
  scooter: Optional[Dict[str, str]] = None,
374
377
  headers: Optional[dict] = None,
375
378
  ) -> Optional[RoutingResponseV8]:
@@ -417,7 +420,9 @@ class RoutingApi(HEREApi):
417
420
  For example, attributes,length will enable the fields attributes and length in the route response.
418
421
  This parameter also requires that the polyline option is set within the return parameter.
419
422
  truck (Optional[Dict[str, List[str]]]):
420
- Comma-separated list of shipped hazardous goods in the vehicle.
423
+ Deprecated. Use `vehicle` parameter.
424
+ vehicle (Optional[Dict[str, List[str]]]):
425
+ Comma-separated list of vehicle-specific parameters.
421
426
  Sample use of parameter: `{"shippedHazardousGoods": [explosive, gas, flammable]}`
422
427
  scooter (Optional[Dict[str, str]]):
423
428
  Scooter specific parameters.
@@ -457,17 +462,9 @@ class RoutingApi(HEREApi):
457
462
  if alternatives:
458
463
  data["alternatives"] = alternatives
459
464
  if avoid:
460
- key = list(avoid.keys())[0]
461
- values = list(avoid.values())[0]
462
- data["avoid"] = {
463
- key: ",".join(values),
464
- }
465
+ data["avoid"] = {key: ",".join(vals) for key, vals in avoid.items()}
465
466
  if exclude:
466
- key = list(avoid.keys())[0]
467
- values = list(avoid.values())[0]
468
- data["exclude"] = {
469
- key: ",".join(values),
470
- }
467
+ data["exclude"] = {key: ",".join(vals) for key, vals in exclude.items()}
471
468
  if units:
472
469
  data["units"] = units.__str__()
473
470
  if lang:
@@ -477,11 +474,15 @@ class RoutingApi(HEREApi):
477
474
  if span_fields:
478
475
  data["spans"] = ",".join([field.__str__() for field in span_fields])
479
476
  if truck:
480
- key = list(avoid.keys())[0]
481
- values = list(avoid.values())[0]
482
- data["truck"] = {
483
- key: ",".join(values),
484
- }
477
+ warn(
478
+ "'truck' parameter is deprecated in Routing API. Use 'vehicle' parameter instead.",
479
+ DeprecationWarning,
480
+ stacklevel=2,
481
+ )
482
+ if vehicle is None:
483
+ vehicle = truck
484
+ if vehicle:
485
+ data["vehicle"] = {key: ",".join(vals) for key, vals in vehicle.items()}
485
486
  if scooter:
486
487
  data["scooter"] = scooter
487
488
 
@@ -492,6 +493,7 @@ class RoutingApi(HEREApi):
492
493
  RoutingResponseV8,
493
494
  manipulation_key="via",
494
495
  keys_for_manipulation=via_keys,
496
+ headers=headers
495
497
  )
496
498
  return response
497
499
 
@@ -18,16 +18,23 @@ class Utils(object):
18
18
  parameters (dict):
19
19
  dictionary of query parameters to be converted.
20
20
  Returns:
21
- A URL-encoded string in "key=value&key=value" form
21
+ A URL-encoded string in "key=value&key=value" form. If the parameter value is
22
+ a dict, the encoded string is converted to "main_key[sub_key]=sub_value".
22
23
  """
23
24
  if parameters is None:
24
25
  return None
25
26
  if not isinstance(parameters, dict):
26
27
  raise HEREError("`parameters` must be a dict.")
27
28
  else:
28
- return urlencode(
29
- dict((k, v) for k, v in parameters.items() if v is not None)
30
- )
29
+ parameters = dict((k, v) for k, v in parameters.items() if v is not None)
30
+ result = dict()
31
+ for key, value in parameters.items():
32
+ if isinstance(value, dict):
33
+ for sub_key, sub_value in value.items():
34
+ result[f"{key}[{sub_key}]"] = sub_value
35
+ else:
36
+ result[key] = value
37
+ return urlencode(result)
31
38
 
32
39
  @staticmethod
33
40
  def build_url(url, extra_params=None):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: herepy
3
- Version: 3.6.3
3
+ Version: 3.6.5
4
4
  Summary: A library that provides a Python interface to the HERE APIs
5
5
  Home-page: https://github.com/abdullahselek/HerePy
6
6
  Download-URL: https://pypi.org/pypi/herepy
@@ -94,7 +94,8 @@ class GeocoderApiTest(unittest.TestCase):
94
94
  street="Barbaros",
95
95
  city="Istanbul",
96
96
  country="Turkey",
97
- house_number=34
97
+ house_number=34,
98
+ postal_code="34353",
98
99
  )
99
100
  self.assertTrue(response)
100
101
  self.assertIsInstance(response, herepy.GeocoderResponse)
@@ -136,7 +137,54 @@ class GeocoderApiTest(unittest.TestCase):
136
137
  )
137
138
  self.assertTrue(response)
138
139
  self.assertIsInstance(response, herepy.GeocoderResponse)
139
-
140
+
141
+ @responses.activate
142
+ def test_address_with_detail_without_country(self):
143
+ with open("testdata/models/geocoder.json", "r") as f:
144
+ expected_response = f.read()
145
+ responses.add(
146
+ responses.GET,
147
+ "https://geocode.search.hereapi.com/v1/geocode",
148
+ expected_response,
149
+ status=200,
150
+ )
151
+ response = self._api.address_with_details(
152
+ street="Barbaros",
153
+ city="Istanbul",
154
+ country= None
155
+ )
156
+ self.assertTrue(response)
157
+ self.assertIsInstance(response, herepy.GeocoderResponse)
158
+
159
+ @responses.activate
160
+ def test_address_with_detail_with_only_country(self):
161
+ with open("testdata/models/geocoder.json") as f:
162
+ expected_response = f.read()
163
+ responses.add(
164
+ responses.GET,
165
+ "https://geocode.search.hereapi.com/v1/geocode",
166
+ expected_response,
167
+ status=200,
168
+ )
169
+ response = self._api.address_with_details(
170
+ country="FR",
171
+ )
172
+ self.assertTrue(response)
173
+ self.assertIsInstance(response, herepy.GeocoderResponse)
174
+
175
+ @responses.activate
176
+ def test_address_with_detail_without_any_detail_raise(self):
177
+ with open("testdata/models/geocoder.json") as f:
178
+ expected_response = f.read()
179
+ responses.add(
180
+ responses.GET,
181
+ "https://geocode.search.hereapi.com/v1/geocode",
182
+ expected_response,
183
+ status=200,
184
+ )
185
+ with self.assertRaises(herepy.HEREError):
186
+ self._api.address_with_details(country="")
187
+
140
188
  @responses.activate
141
189
  def test_addresswithdetails_whenerroroccurred(self):
142
190
  with open("testdata/models/geocoder_error.json", "r") as f:
@@ -3,6 +3,7 @@
3
3
  import codecs
4
4
  import datetime
5
5
  import unittest
6
+ import pytest
6
7
 
7
8
  import responses
8
9
 
@@ -1095,7 +1096,7 @@ class RoutingApiTest(unittest.TestCase):
1095
1096
  lang="tr-TR",
1096
1097
  return_fields=[herepy.RoutingApiReturnField.polyline],
1097
1098
  span_fields=[herepy.RoutingApiSpanField.walkAttributes],
1098
- truck={"shippedHazardousGoods": ["explosive", "gas"]},
1099
+ vehicle={"shippedHazardousGoods": ["explosive", "gas"]},
1099
1100
  scooter={"allowHighway": "true"},
1100
1101
  )
1101
1102
  self.assertTrue(response)
@@ -1129,7 +1130,7 @@ class RoutingApiTest(unittest.TestCase):
1129
1130
  lang="tr-TR",
1130
1131
  return_fields=[herepy.RoutingApiReturnField.polyline],
1131
1132
  span_fields=[herepy.RoutingApiSpanField.walkAttributes],
1132
- truck={"shippedHazardousGoods": ["explosive", "gas"]},
1133
+ vehicle={"shippedHazardousGoods": ["explosive", "gas"]},
1133
1134
  scooter={"allowHighway": "true"},
1134
1135
  )
1135
1136
 
@@ -1190,7 +1191,7 @@ class RoutingApiTest(unittest.TestCase):
1190
1191
  lang="tr-TR",
1191
1192
  return_fields=[herepy.RoutingApiReturnField.polyline],
1192
1193
  span_fields=[herepy.RoutingApiSpanField.walkAttributes],
1193
- truck={"shippedHazardousGoods": ["explosive", "gas"]},
1194
+ vehicle={"shippedHazardousGoods": ["explosive", "gas"]},
1194
1195
  scooter={"allowHighway": "true"},
1195
1196
  )
1196
1197
 
@@ -1215,3 +1216,61 @@ class RoutingApiTest(unittest.TestCase):
1215
1216
  )
1216
1217
  self.assertTrue(response)
1217
1218
  self.assertIsInstance(response, herepy.RoutingResponseV8)
1219
+
1220
+ @responses.activate
1221
+ def test_route_v8_url_parameters_multiple(self):
1222
+ responses.add(
1223
+ responses.GET,
1224
+ "https://router.hereapi.com/v8/routes",
1225
+ "{}",
1226
+ status=200,
1227
+ match=[
1228
+ responses.matchers.query_param_matcher(
1229
+ {"vehicle[height]": "15000", "vehicle[width]": "3000"}, strict_match=False
1230
+ )
1231
+ ],
1232
+ )
1233
+ self._api.route_v8(transport_mode=herepy.RoutingTransportMode.truck,
1234
+ origin=[41.9798, -87.8801],
1235
+ destination=[41.9043, -87.9216],
1236
+ vehicle={"height": ["15000"], "width": ["3000"]}
1237
+ )
1238
+
1239
+ @responses.activate
1240
+ @pytest.mark.filterwarnings("ignore:'truck' parameter is deprecated")
1241
+ def test_route_v8_truck_parameter_deprecated(self):
1242
+ responses.add(
1243
+ responses.GET,
1244
+ "https://router.hereapi.com/v8/routes",
1245
+ "{}",
1246
+ status=200,
1247
+ match=[
1248
+ responses.matchers.query_param_matcher(
1249
+ {"vehicle[height]": "15000", "vehicle[width]": "3000"},
1250
+ strict_match=False,
1251
+ )
1252
+ ],
1253
+ )
1254
+ self._api.route_v8(
1255
+ transport_mode=herepy.RoutingTransportMode.truck,
1256
+ origin=[41.9798, -87.8801],
1257
+ destination=[41.9043, -87.9216],
1258
+ truck={"height": ["15000"], "width": ["3000"]},
1259
+ )
1260
+
1261
+ @responses.activate
1262
+ def test_route_v8_headers_in_request(self):
1263
+ resp = responses.add(
1264
+ responses.GET,
1265
+ "https://router.hereapi.com/v8/routes",
1266
+ "{}",
1267
+ status=200,
1268
+ )
1269
+ self._api.route_v8(
1270
+ transport_mode=herepy.RoutingTransportMode.truck,
1271
+ origin=[41.9798, -87.8801],
1272
+ destination=[41.9043, -87.9216],
1273
+ headers={"X-BIP": "BOP"},
1274
+ )
1275
+ original_request = resp.calls[0].request
1276
+ self.assertEqual(original_request.headers.get("X-BIP"), "BOP")
@@ -29,3 +29,11 @@ class UtilsTest(unittest.TestCase):
29
29
  "https://geocoder.cit.api.here.com/6.2/geocode.json", data
30
30
  )
31
31
  self.assertTrue(url)
32
+
33
+ def test_build_url_sub_data(self):
34
+ data = {
35
+ "key1": "val",
36
+ "key2": {"sub_key": "sub_val", "sub_key2": "sub_val2"},
37
+ }
38
+ url = Utils.build_url("https://router.hereapi.com/v8/routes", data)
39
+ self.assertEqual(url, "https://router.hereapi.com/v8/routes?key1=val&key2%5Bsub_key%5D=sub_val&key2%5Bsub_key2%5D=sub_val2")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes