Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ api.search_car(
price_to=50000,
transmissions=[CarTransmission.MANUAL],
locations=[Location.STOCKHOLM],
org_id=1337, # dealer or store id
)

# search for boats
Expand All @@ -66,6 +67,7 @@ api.search_boat(
length_to=15,
price_from=20000,
price_to=90000,
org_id=1337, # dealer or store id
)

# search for motorcycles
Expand All @@ -80,6 +82,7 @@ api.search_mc(
price_to=90000,
engine_volume_from=100,
engine_volume_to=200,
org_id=1337, # dealer or store id
)


Expand Down
6 changes: 6 additions & 0 deletions blocket_api/blocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def search_car(
milage_to: int | None = None,
colors: list[CarColor] = [],
transmissions: list[CarTransmission] = [],
org_id: int | None = None,
) -> dict[str, Any]:
url = f"{SITE_URL}/mobility/search/api/search/SEARCH_ID_CAR_USED"

Expand All @@ -101,6 +102,7 @@ def search_car(
"year_to": year_to,
"milage_from": milage_from,
"milage_to": milage_to,
"org_id": org_id,
}

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

Expand All @@ -136,6 +139,7 @@ def search_boat(
"price_to": price_to,
"length_feet_from": length_from,
"length_feet_to": length_to,
"org_id": org_id,
}

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

Expand All @@ -169,6 +174,7 @@ def search_mc(
"price_to": price_to,
"engine_volume_from": engine_volume_from,
"engine_volume_to": engine_volume_to,
"org_id": org_id,
}

params = [QueryParam(k, v) for k, v in param_dict.items() if v is not None]
Expand Down
8 changes: 7 additions & 1 deletion tests/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def test_search_car(self) -> None:
"&price_from=1000"
"&price_to=50000"
"&transmission=2"
"&org_id=1337"
)
respx.get(expected_url).mock(
return_value=httpx.Response(200, json={"status": "ok"})
Expand All @@ -133,6 +134,7 @@ def test_search_car(self) -> None:
price_from=1000,
price_to=50000,
transmissions=[CarTransmission.AUTOMATIC],
org_id=1337,
)
assert result == {"status": "ok"}

Expand All @@ -151,6 +153,7 @@ def test_search_boat(self) -> None:
"&price_to=90000"
"&length_feet_from=10"
"&length_feet_to=15"
"&org_id=1337"
)
respx.get(expected_url).mock(
return_value=httpx.Response(200, json={"status": "ok"})
Expand All @@ -163,13 +166,14 @@ def test_search_boat(self) -> None:
length_to=15,
price_from=20000,
price_to=90000,
org_id=1337,
)
assert result == {"status": "ok"}


class Test_McSearch:
@respx.mock
def test_search_boat(self) -> None:
def test_search_mc(self) -> None:
expected_url = (
f"{SITE_URL}/mobility/search/api/search/SEARCH_ID_MC_USED"
"?q=snabb"
Expand All @@ -182,6 +186,7 @@ def test_search_boat(self) -> None:
"&make=1484"
"&location=0.300001"
"&type=11"
"&org_id=1337"
)
respx.get(expected_url).mock(
return_value=httpx.Response(200, json={"status": "ok"})
Expand All @@ -195,6 +200,7 @@ def test_search_boat(self) -> None:
price_to=90000,
engine_volume_from=10,
engine_volume_to=15,
org_id=1337,
)
assert result == {"status": "ok"}

Expand Down