-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathcustomer.py
145 lines (109 loc) · 3.54 KB
/
customer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# -*- coding: UTF-8 -*-
'''
magento.customer
Customer API for magento
:license: BSD, see LICENSE for more details
'''
from magento.api import API
class Customer(API):
"""
Customer API
Example usage::
from magento import Customer as CustomerAPI
with CustomerAPI(url, username, password) as customer_api:
return customer_api.list()
"""
__slots__ = ()
def list(self, filters=None):
"""
Retreive list of customers
:param filters: Dictionary of filters.
Format: `{<attribute>:{<operator>:<value>}}`
Example: `{'firstname':{'ilike':'sharoon'}}`
:return: List of dictionaries of matching records
"""
return self.call('customer.list', filters and [filters] or [{}])
def create(self, data):
"""
Create a customer using the given data
:param data: Dictionary of values
:return: Integer ID of new record
"""
return int(self.call('customer.create', [data]))
def info(self, id, attributes=None):
"""
Retrieve customer data
:param id: ID of customer
:param attributes: `List` of attributes needed
"""
if attributes:
return self.call('customer.info', [id, attributes])
else:
return self.call('customer.info', [id])
def update(self, id, data):
"""
Update a customer using the given data
:param id: ID of the customer record to modify
:param data: Dictionary of values
:return: Boolean
"""
return self.call('customer.update', [id, data])
def delete(self, id):
"""
Delete a customer
:param id: ID of customer to delete
:return: Boolean
"""
return self.call('customer.delete', [id])
class CustomerGroup(API):
"""
Customer Group API to connect to magento
"""
__slots__ = ()
def list(self):
"""
Retreive list of customers
:return: List of dictionaries of matching records
"""
return self.call('customer_group.list', [])
class CustomerAddress(API):
"""
Customer Address API
"""
__slots__ = ()
def list(self, customer_id):
"""
Retreive list of customer Addresses
:param customer_id: ID of customer whose address needs to be fetched
:return: List of dictionaries of matching records
"""
return self.call('customer_address.list', [customer_id])
def create(self, customer_id, data):
"""
Create a customer using the given data
:param customer_id: ID of customer, whose address is being added
:param data: Dictionary of values (country, zip, city, etc...)
:return: Integer ID of new record
"""
return int(self.call('customer_address.create', [customer_id, data]))
def info(self, id):
"""
Retrieve customer data
:param id: ID of customer
"""
return self.call('customer_address.info', [id])
def update(self, id, data):
"""
Update a customer address using the given data
:param id: ID of the customer address record to modify
:param data: Dictionary of values
:return: Boolean
"""
return self.call('customer_address.update', [id, data])
def delete(self, id):
"""
Delete a customer address
:param id: ID of address to delete
:return: Boolean
"""
return self.call('customer_address.delete', [id])