Skip to content

Commit

Permalink
Remove ikea_api.get_items() (closes #199), iows items endpoint (closes
Browse files Browse the repository at this point in the history
 #202), `ikea_api.utils.unshorten_urls_from_ingka_pagelinks()` (#203)

`ikea_api.get_items()` is practically useless now that iows items endpoint is unavailable. `ikea_api.utils.unshorten_urls_from_ingka_pagelinks()` is likely to be confusing and unpopular, so removing it too.
  • Loading branch information
vrslev committed Nov 4, 2023
1 parent 7a7baa1 commit 8376508
Show file tree
Hide file tree
Showing 19 changed files with 8 additions and 4,763 deletions.
13 changes: 2 additions & 11 deletions README.md
Expand Up @@ -10,7 +10,7 @@ With this library you can access following IKEA's APIs:

- Cart,
- Home Delivery and Collect Services (actually, Order Capture),
- Items info (3 different services),
- Items info (2 services),
- 3D models,
- Purchases (history and order info),
- Search,
Expand Down Expand Up @@ -254,25 +254,16 @@ purchases.order_info(
### 🪑 Item info

Get item specification by item code (product number or whatever). There are 3 endpoints to do this because you can't get all the data about all the items using only one endpoint.
Get item specification by item code (product number or whatever). There are 2 endpoints to do this because you can't get all the data about all the items using only one endpoint.

```python
iows_items = ikea_api.IowsItems(constants)
iows_items.get_items(["30457903"])

ingka_items = ikea_api.IngkaItems(constants)
ingka_items.get_items(["30457903"])

pip_item = ikea_api.PipItem(constants)
pip_item.get_item("30457903")
```

> 💡 You probably won't want to use raw APIs when there's convenient "smart" wrapper that combines them all and parses basic info:
>
> ```python
> await ikea_api.get_items(["30457903"])
> ```
### 📦 Item 3D models

Get 3D models by item code.
Expand Down
2 changes: 0 additions & 2 deletions src/ikea_api/__init__.py
Expand Up @@ -2,7 +2,6 @@
from ikea_api.endpoints.auth import Auth as Auth
from ikea_api.endpoints.cart import Cart as Cart
from ikea_api.endpoints.ingka_items import IngkaItems as IngkaItems
from ikea_api.endpoints.iows_items import IowsItems as IowsItems
from ikea_api.endpoints.order_capture import OrderCapture as OrderCapture
from ikea_api.endpoints.order_capture import (
convert_cart_to_checkout_items as convert_cart_to_checkout_items,
Expand Down Expand Up @@ -35,6 +34,5 @@
from ikea_api.wrappers.wrappers import (
get_delivery_services as get_delivery_services,
)
from ikea_api.wrappers.wrappers import get_items as get_items
from ikea_api.wrappers.wrappers import get_purchase_history as get_purchase_history
from ikea_api.wrappers.wrappers import get_purchase_info as get_purchase_info
87 changes: 0 additions & 87 deletions src/ikea_api/endpoints/iows_items.py

This file was deleted.

32 changes: 1 addition & 31 deletions src/ikea_api/utils.py
@@ -1,14 +1,10 @@
from __future__ import annotations

import asyncio
import re
from typing import TYPE_CHECKING, Any, Iterable, Optional, cast
from typing import Any

from ikea_api.constants import Constants

if TYPE_CHECKING:
import httpx


def parse_item_codes(item_codes: list[str] | str) -> list[str]:
raw_res: list[str] = re.findall(
Expand All @@ -19,32 +15,6 @@ def parse_item_codes(item_codes: list[str] | str) -> list[str]:
return list(dict.fromkeys(regex.sub("", i) for i in raw_res))


def _parse_ingka_pagelink_urls(message: str) -> Iterable[str]:
base_url = "https://ingka.page.link/"
postfixes = re.findall("ingka.page.link/([0-9A-z]+)", message)
for postfix in postfixes:
yield base_url + postfix


def _get_location_headers(responses: Iterable[httpx.Response]) -> list[str]:
res: list[str] = []
for response in responses:
location = cast(Optional[str], response.headers.get("Location")) # type: ignore
if location is not None:
res.append(location)
return res


async def unshorten_urls_from_ingka_pagelinks(message: str) -> list[str]:
import httpx

client = httpx.AsyncClient()
urls = _parse_ingka_pagelink_urls(message)
coros = (client.get(url, follow_redirects=False) for url in urls) # type: ignore
responses = await asyncio.gather(*coros)
return _get_location_headers(responses)


def format_item_code(item_code: str) -> str | None:
matches = parse_item_codes(item_code)
if not matches:
Expand Down

0 comments on commit 8376508

Please sign in to comment.