|
6 | 6 |
|
7 | 7 | import requests |
8 | 8 |
|
9 | | -from pyzipcodeapi.dataclass import Distance, Error |
| 9 | +from pyzipcodeapi.dataclass import Distance, Error, MultiDistance |
10 | 10 | from pyzipcodeapi.enums import FormatEnum, UnitEnum, CountryEnum |
11 | 11 | from pyzipcodeapi.options import OPTIONS |
12 | 12 |
|
@@ -104,13 +104,13 @@ def __init__(self, api_key: str): |
104 | 104 | self.api_key = api_key |
105 | 105 | self.con = HTTPSConnection(host=self.host) |
106 | 106 |
|
107 | | - def _make_api_call( |
| 107 | + def _api_call( |
108 | 108 | self, |
109 | 109 | option: str, |
110 | 110 | f: FormatEnum, |
111 | 111 | path: str, |
112 | | - country: CountryEnum = CountryEnum.US, |
113 | 112 | data_class: type | None = None, |
| 113 | + country: CountryEnum = CountryEnum.US, |
114 | 114 | ) -> DictReader | bytes | type | Element | Error: |
115 | 115 | base_url = f"rest/v2/CA" if country == CountryEnum.CA else f"rest" |
116 | 116 | self.con.request( |
@@ -140,10 +140,19 @@ def distance( |
140 | 140 | country: CountryEnum = CountryEnum.US, |
141 | 141 | ) -> Distance | DictReader | Element: |
142 | 142 | """distance.<format>/<zip_code1>/<zip_code2>/<units>""" |
143 | | - return self._make_api_call( |
144 | | - "distance", |
145 | | - f, |
146 | | - path=f"{zip_code1}/{zip_code2}/{units}", |
147 | | - country=country, |
148 | | - data_class=Distance, |
149 | | - ) |
| 143 | + path = f"{zip_code1}/{zip_code2}/{units}" |
| 144 | + dc = Distance |
| 145 | + return self._api_call("distance", f, path, dc, country=country) |
| 146 | + |
| 147 | + def multi_distance( |
| 148 | + self, |
| 149 | + zip_code: str, |
| 150 | + zip_codes: list[str], |
| 151 | + units: UnitEnum = UnitEnum.KM, |
| 152 | + f: FormatEnum | None = FormatEnum.JSON, |
| 153 | + ) -> MultiDistance | DictReader | Element: |
| 154 | + """multi-distance.<format>/<zip_code>/<other_zip_codes>/<units>""" |
| 155 | + assert len(zip_codes) <= 100 |
| 156 | + path = f"{zip_code}/{','.join(zip_codes)}/{units}" |
| 157 | + dc = MultiDistance |
| 158 | + return self._api_call("multi-distance", f, path, dc) |
0 commit comments