Skip to content

Commit 9b0439e

Browse files
committed
Add "lose" API
1 parent ce21aa4 commit 9b0439e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pytarallo/Tarallo.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,28 @@ def move(self, code: str, location: str):
231231
else:
232232
raise RuntimeError(f"Move failed with {move_status}")
233233

234+
def lose(self, code: str):
235+
"""
236+
Move an item to another location
237+
"""
238+
lose_status = self.delete(f'v2/items/{self.urlencode(code)}/parent').status_code
239+
if lose_status == 204:
240+
return True
241+
elif lose_status == 400:
242+
response_json = json.loads(self.response.content)
243+
if "message" in response_json:
244+
raise ValidationError(f"Cannot lose {code}: {response_json['message']}")
245+
else:
246+
raise ValidationError(f"Cannot lose {code}")
247+
elif lose_status == 404:
248+
response_json = json.loads(self.response.content)
249+
if 'item' in response_json:
250+
raise ItemNotFoundError(f"Item {response_json['item']} doesn't exist")
251+
else:
252+
raise ServerError("Server didn't find an item, but isn't telling us which one")
253+
else:
254+
raise RuntimeError(f"Move failed with {lose_status}")
255+
234256
def delete_product(self, brand: str, model: str, variant: str):
235257
"""
236258
send a DELETE request to the server to remove a product

0 commit comments

Comments
 (0)