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: 2 additions & 1 deletion README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -470,7 +470,7 @@ res = client.ActionOptCodesManager.update(

```python
res = client.LostOrders.get()
res = client.LostOrders.get(limit=20, offset=0)
res = client.LostOrders.get(limit=20, offset=0, appeal_status='processing')
res = client.LostOrders.getOne(76)
```

Expand All@@ -483,6 +483,7 @@ res = client.LostOrdersManager.create(
order_id='039NRUHFJEW', order_date='12.08.2016', order_price=345.77,
comment='some comment'
)
res = client.LostOrdersManager.update(77, appeal_status='resolved')
res = client.LostOrdersManager.delete(77)
```

Expand Down
46 changes: 45 additions & 1 deletion admitad/items/lost_orders.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,11 +20,34 @@ class LostOrders(Item):
def get(self, **kwargs):
"""
Args:
campaign (id)
website (id)
status (string)
start_date (date)
end_date (date)
appeal_id (string)
appeal_status (string)
limit (int)
offset (int)

"""
return self.transport.get().set_pagination(**kwargs).request(url=self.URL)
filtering = {
'filter_by': kwargs,
'available': {
'campaign': lambda x: Item.sanitize_integer_value(x, 'campaign', blank=True),
'website': lambda x: Item.sanitize_integer_value(x, 'website', blank=True),
'status': lambda x: Item.sanitize_string_value(x, 'status', blank=True),
'start_date': lambda x: Item.sanitize_string_value(x, 'start_date', blank=True),
'end_date': lambda x: Item.sanitize_string_value(x, 'end_date', blank=True),
'appeal_id': lambda x: Item.sanitize_string_value(x, 'appeal_id', blank=True),
'appeal_status': lambda x: Item.sanitize_string_value(x, 'appeal_status', blank=True),
}
}

return self.transport.get() \
.set_filtering(filtering) \
.set_pagination(**kwargs) \
.request(url=self.URL)

def getOne(self, lost_order_id):
"""
Expand All@@ -46,6 +69,7 @@ class LostOrdersManager(Item):

DELETE_URL = Item.prepare_url('lost_orders/%(lost_order_id)s/decline')
CREATE_URL = Item.prepare_url('lost_orders/create')
UPDATE_URL = Item.prepare_url('lost_orders/%(lost_order_id)s/update')

CREATE_FIELDS = {
'campaign': lambda x: Item.sanitize_integer_value(x, 'campaign'),
Expand All@@ -54,6 +78,7 @@ class LostOrdersManager(Item):
'order_date': lambda x: Item.sanitize_date(x, 'order_date'),
'order_price': lambda x: Item.sanitize_float_value(x, 'order_price'),
'comment': lambda x: Item.sanitize_string_value(x, 'comment'),
'appeal_id': lambda x: Item.sanitize_string_value(x, 'appeal_id'),
}

def delete(self, lost_order_id):
Expand All@@ -78,10 +103,29 @@ def create(self, attachments, **kwargs):
order_id (str)
order_date (date)
order_price (float)
appeal_id (str)
comment (str)

"""
data = Item.sanitize_fields(self.CREATE_FIELDS, **kwargs)
files = [('attachment', open(item, 'rb')) for item in Item.sanitize_string_array(attachments, 'attachments')]

return self.transport.post().set_data(data).set_files(files).request(url=self.CREATE_URL)

def update(self, lost_order_id, appeal_status):
"""
Args:
lost_order_id (int)
appeal_status (str)

"""
request_data = {
'url': self.UPDATE_URL,
'lost_order_id': Item.sanitize_id(lost_order_id),
}

data = {
'appeal_status': self.sanitize_string_value(appeal_status, 'appeal_status'),
}

return self.transport.put().set_data(data).request(**request_data)
25 changes: 22 additions & 3 deletions admitad/tests/test_lost_orders.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,15 +16,17 @@ def test_get_lost_orders_request(self):
resp.GET,
self.prepare_url(LostOrders.URL, params={
'limit': 20,
'offset': 1
'offset': 1,
'appeal_status': 'resolved',
}),
match_querystring=True,
json={'status': 'ok'},
status=200,
)
result = self.client.LostOrders.get(
limit=20,
offset=1
offset=1,
appeal_status='resolved'
)

self.assertIn('status', result)
Expand DownExpand Up@@ -61,7 +63,24 @@ def test_create_lost_order(self):
order_id='asd3f3',
order_date='01.01.2010',
order_price=1200,
comment='foo bar baz'
comment='foo bar baz',
appeal_id='foo'
)

self.assertIn('status', result)

def test_update_lost_order(self):
with responses.RequestsMock() as resp:
resp.add(
resp.PUT,
self.prepare_url(LostOrdersManager.UPDATE_URL, lost_order_id=10),
match_querystring=True,
json={'status': 'ok'},
status=200,
)
result = self.client.LostOrdersManager.update(
lost_order_id=10,
appeal_status='resolved'
)

self.assertIn('status', result)
Expand Down
4 changes: 2 additions & 2 deletions admitad/transport.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,9 +70,9 @@ def prepare_request_data(data=None, headers=None, method='GET',

prepared_data = prepare_data(data)

if method == 'POST':
if method in ['POST', 'PUT']:
kwargs['data'] = prepared_data
if method == 'GET':
if method in ['GET', 'DELETE']:
kwargs['params'] = prepared_data

return kwargs
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,13 +3,13 @@
setup(
name="admitad",
packages=['admitad', 'admitad.items'],
version='1.1.1',
version='1.2.0',
author='Admitad Dev Bot',
author_email='dev@admitad.com',
description='A Python wrapper around the Admitad API',
license='MIT',
url='https://github.com/admitad/admitad-python-api',
download_url='https://github.com/admitad/admitad-python-api/tarball/1.1.1',
download_url='https://github.com/admitad/admitad-python-api/tarball/1.2.0',
keywords=['admitad'],
install_requires=['requests>=2.0', 'future'],
tests_require=['nose2', 'responses'],
Expand Down