Skip to content

Commit 5b9a61b

Browse files
authored
Coryp/ch1815/update geodesic and geocode ip response (#3)
* update geodesic response * update geocode/ip to return address * bump version * address name to addressLabel, placeLabel
1 parent 4dee0a4 commit 5b9a61b

5 files changed

Lines changed: 15 additions & 15 deletions

File tree

examples/geocode_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
"latitude": 40.704262,
3030
"longitude": -73.986675,
31-
"name": "20 Jay Street",
31+
"addressLabel": "20 Jay Street",
3232
"neighborhood": "DUMBO",
3333
"number": "20",
3434
"postalCode": "11201",
@@ -62,7 +62,7 @@
6262
},
6363
"latitude": 40.704053,
6464
"longitude": -73.986802,
65-
"name": "20 Jay St",
65+
"addressLabel": "20 Jay St",
6666
"neighborhood": "DUMBO",
6767
"number": "20",
6868
"state": "New York",

radar/endpoints.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,20 +453,20 @@ def reverse(self, coordinates):
453453
return [Address(self._radar, data) for data in raw_addresses]
454454

455455
def ip(self, ip):
456-
"""Geocodes an IP address, converting IP address to country.
456+
"""Geocodes an IP address, converting IP address to partial address.
457457
458458
https://radar.io/documentation/api#geocode-ip
459459
460460
Args:
461461
ip (str): The IP address to geocode.
462462
463463
Returns:
464-
`list` of :class:`~radar.models.address.Address`
464+
`:class:`~radar.models.address.Address`
465465
"""
466466
path = API_PATH["geocode_ip"]
467467
params = {"ip": ip}
468468

469-
raw_address = self._get(path, params=params)
469+
raw_address = self._get(path, params=params, json_key="address")
470470
return Address(self._radar, raw_address)
471471

472472

radar/models/address.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class Address(Model):
1414
distance (float)
1515
formattedAddress (str)
1616
geometry (GeoJSON.Point)
17-
name (str)
17+
addressLabel (str)
18+
placeLabel (str)
1819
number (str)
1920
latitude (float)
2021
longitude (float)
@@ -31,4 +32,5 @@ class Address(Model):
3132
"latitude",
3233
"longitude",
3334
"formattedAddress",
35+
"placeLabel",
3436
)

radar/models/route.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ def __init__(self, distance=None, duration=None, mode=None):
6666
self.duration = None
6767

6868
def __repr__(self):
69-
display_str = f"<distance={self.distance.text}"
69+
fields = []
70+
if self.distance:
71+
fields.append(f"distance={self.distance.text}")
7072
if self.duration:
71-
display_str += f" duration={self.duration.text}>"
72-
else:
73-
display_str += ">"
73+
fields.append(f"duration={self.duration.text}")
74+
display_str = f"<{' '.join(fields)}>"
7475
return display_str
7576

7677

@@ -96,15 +97,12 @@ def __init__(self, radar, data={}):
9697
self._radar = radar
9798
self.raw_json = data
9899
for attribute, value in data.items():
99-
if attribute in ["transit", "car", "bike", "foot"]:
100+
if attribute in ["geodesic", "transit", "car", "bike", "foot"]:
100101
route = Route(
101102
distance=value.get("distance"),
102103
duration=value.get("duration"),
103104
mode=attribute,
104105
)
105106
setattr(self, attribute, route)
106-
elif attribute in ["geodesic"]:
107-
route = Route(distance=value, mode=attribute)
108-
setattr(self, attribute, route)
109107
else:
110108
setattr(self, attribute, value)

radar/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "0.0.3"
1+
VERSION = "0.0.4"

0 commit comments

Comments
 (0)