Skip to content
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Handle:
- get the status of an order (`/api/order/vX/:id/status`)
- get active orders (`/api/order/vX/active`)
- get inactive orders (`/api/order/vX/inactive`)
- get delivery items (`api/manufactureritem/v2`)

## Install

Expand Down
32 changes: 32 additions & 0 deletions tests/test_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
API_ITEM_ENDPOINT,
BASE_URL,
FAVORITE_ITEM_ENDPOINT,
MANUFACTURER_ITEM_ENDPOINT,
TgtgClient,
)
from tgtg.exceptions import TgtgAPIError
Expand Down Expand Up @@ -127,3 +128,34 @@ def test_set_favorite_fail(client):
)
with pytest.raises(TgtgAPIError):
client.set_favorite(1, True)


def test_get_manufacturing_items_fail(client):
responses.add(
responses.POST,
urljoin(BASE_URL, MANUFACTURER_ITEM_ENDPOINT),
json={},
status=400,
)
with pytest.raises(TgtgAPIError):
client.get_manufacturer_items()


def test_get_manufacturing_items_success(client):
responses.add(
responses.POST,
urljoin(BASE_URL, MANUFACTURER_ITEM_ENDPOINT),
json={},
status=200,
)
assert client.get_manufacturer_items() == {}
assert (
len(
[
call
for call in responses.calls
if MANUFACTURER_ITEM_ENDPOINT in call.request.url
]
)
== 1
)
28 changes: 28 additions & 0 deletions tgtg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
ABORT_ORDER_ENDPOINT = "order/v8/{}/abort"
ORDER_STATUS_ENDPOINT = "order/v8/{}/status"
API_BUCKET_ENDPOINT = "discover/v1/bucket"
MANUFACTURER_ITEM_ENDPOINT = "manufactureritem/v2"

DEFAULT_APK_VERSION = "24.11.0"
USER_AGENTS = [
"TGTG/{} Dalvik/2.1.0 (Linux; U; Android 9; Nexus 5 Build/M4B30Z)",
Expand Down Expand Up @@ -430,3 +432,29 @@ def get_inactive(self, page=0, page_size=20):
return response.json()
else:
raise TgtgAPIError(response.status_code, response.content)

def get_manufacturer_items(self):
self.login()

data = {
"display_types_accepted": ["LIST"],
"element_types_accepted": [
"ITEM",
"NPS",
"TEXT",
"DUO_ITEMS",
"MANUFACTURER_STORY_CARD",
],
"action_types_accepted": [],
}
response = self.session.post(
self._get_url(MANUFACTURER_ITEM_ENDPOINT),
headers=self._headers,
json=data,
proxies=self.proxies,
timeout=self.timeout,
)
if response.status_code == HTTPStatus.OK:
return response.json()
else:
raise TgtgAPIError(response.status_code, response.content)