Skip to content

Commit 0676dfd

Browse files
committed
feat: add org id
This makes it possible to filter for a specific org id (a store). The id can be found in the address bar when browsing for example https://www.blocket.se/mobility/search/mc?orgId=XXXXXXX. Closes #48
1 parent f0d2f23 commit 0676dfd

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

blocket_api/blocket.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def search_car(
8888
milage_to: int | None = None,
8989
colors: list[CarColor] = [],
9090
transmissions: list[CarTransmission] = [],
91+
org_id: int | None = None,
9192
) -> dict[str, Any]:
9293
url = f"{SITE_URL}/mobility/search/api/search/SEARCH_ID_CAR_USED"
9394

@@ -101,6 +102,7 @@ def search_car(
101102
"year_to": year_to,
102103
"milage_from": milage_from,
103104
"milage_to": milage_to,
105+
"org_id": org_id,
104106
}
105107

106108
params = [QueryParam(k, v) for k, v in param_dict.items() if v is not None]
@@ -125,6 +127,7 @@ def search_boat(
125127
price_to: int | None = None,
126128
length_from: int | None = None,
127129
length_to: int | None = None,
130+
org_id: int | None = None,
128131
) -> Any:
129132
url = f"{SITE_URL}/mobility/search/api/search/SEARCH_ID_BOAT_USED"
130133

@@ -136,6 +139,7 @@ def search_boat(
136139
"price_to": price_to,
137140
"length_feet_from": length_from,
138141
"length_feet_to": length_to,
142+
"org_id": org_id,
139143
}
140144

141145
params = [QueryParam(k, v) for k, v in param_dict.items() if v is not None]
@@ -158,6 +162,7 @@ def search_mc(
158162
price_to: int | None = None,
159163
engine_volume_from: int | None = None,
160164
engine_volume_to: int | None = None,
165+
org_id: int | None = None,
161166
) -> dict[str, Any]:
162167
url = f"{SITE_URL}/mobility/search/api/search/SEARCH_ID_MC_USED"
163168

@@ -169,6 +174,7 @@ def search_mc(
169174
"price_to": price_to,
170175
"engine_volume_from": engine_volume_from,
171176
"engine_volume_to": engine_volume_to,
177+
"org_id": org_id,
172178
}
173179

174180
params = [QueryParam(k, v) for k, v in param_dict.items() if v is not None]

tests/requests.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def test_search_car(self) -> None:
123123
"&price_from=1000"
124124
"&price_to=50000"
125125
"&transmission=2"
126+
"&org_id=1337"
126127
)
127128
respx.get(expected_url).mock(
128129
return_value=httpx.Response(200, json={"status": "ok"})
@@ -133,6 +134,7 @@ def test_search_car(self) -> None:
133134
price_from=1000,
134135
price_to=50000,
135136
transmissions=[CarTransmission.AUTOMATIC],
137+
org_id=1337,
136138
)
137139
assert result == {"status": "ok"}
138140

@@ -151,6 +153,7 @@ def test_search_boat(self) -> None:
151153
"&price_to=90000"
152154
"&length_feet_from=10"
153155
"&length_feet_to=15"
156+
"&org_id=1337"
154157
)
155158
respx.get(expected_url).mock(
156159
return_value=httpx.Response(200, json={"status": "ok"})
@@ -163,13 +166,14 @@ def test_search_boat(self) -> None:
163166
length_to=15,
164167
price_from=20000,
165168
price_to=90000,
169+
org_id=1337,
166170
)
167171
assert result == {"status": "ok"}
168172

169173

170174
class Test_McSearch:
171175
@respx.mock
172-
def test_search_boat(self) -> None:
176+
def test_search_mc(self) -> None:
173177
expected_url = (
174178
f"{SITE_URL}/mobility/search/api/search/SEARCH_ID_MC_USED"
175179
"?q=snabb"
@@ -182,6 +186,7 @@ def test_search_boat(self) -> None:
182186
"&make=1484"
183187
"&location=0.300001"
184188
"&type=11"
189+
"&org_id=1337"
185190
)
186191
respx.get(expected_url).mock(
187192
return_value=httpx.Response(200, json={"status": "ok"})
@@ -195,6 +200,7 @@ def test_search_boat(self) -> None:
195200
price_to=90000,
196201
engine_volume_from=10,
197202
engine_volume_to=15,
203+
org_id=1337,
198204
)
199205
assert result == {"status": "ok"}
200206

0 commit comments

Comments
 (0)