Skip to content

Commit 4f6a334

Browse files
committed
docs
1 parent 0320b0d commit 4f6a334

10 files changed

Lines changed: 158 additions & 10 deletions

File tree

identify/http_clients/sync_client.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ def setup_method(self, method, body=None):
3838

3939
def _handle_invalid_response(self, response):
4040
'''
41-
TODO
41+
Handle responses that are not okay and throw an appropriate exception.
42+
If the code doesn't match the known ones, a generic HTTPResponseError
43+
is thrown
44+
45+
:param response: requests' module response object
4246
'''
4347
status_codes_exceptions = {
4448
404: HTTPNotFoundError,
@@ -54,6 +58,10 @@ def _handle_invalid_response(self, response):
5458

5559
def _handle_connection_error(self, e):
5660
'''
61+
Handle error when attempting to connect to identify backend.
62+
Logs exception thrown by requests module, and raises an
63+
IdentifyBackendUnreachableError error, so that it can be caught
64+
by using the top level IdentifyException
5765
'''
5866
LOGGER.debug(e)
5967
raise IdentifyBackendUnreachableError(

identify/microclients/attribute_microclient.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def __init__(self, http_client):
5151
def list(self, traffic_type_id):
5252
'''
5353
Returns a list of TrafficType objects.
54+
55+
:param traffic_type_id: Id of the TrafficType whose attributes will be
56+
returned
57+
:rtype: list(TrafficType)
5458
'''
5559
try:
5660
response = self._http_client.make_request(
@@ -67,6 +71,13 @@ def list(self, traffic_type_id):
6771

6872
def create(self, attribute):
6973
'''
74+
Create a new attribute.
75+
76+
:param attribute: Attribute instance or dict with camelcase keys
77+
containing Attribute properties
78+
79+
:returns: newly created attribute
80+
:rtype: Attribute
7081
'''
7182
# TODO: Validate!
7283
try:
@@ -88,11 +99,18 @@ def create(self, attribute):
8899

89100
def delete(self, attribute):
90101
'''
102+
Delete an attribute
103+
104+
:param attribute: Attribute instance
91105
'''
92106
return self.delete_by_id(attribute.id, attribute.traffic_type_id)
93107

94108
def delete_by_id(self, attribute_id, traffic_type_id):
95109
'''
110+
Delete an attribute by specifying its id and it's traffic type id.
111+
112+
:param attribute_id: attribute's id
113+
:param traffic_type_id: atribute's traffic type id
96114
'''
97115
try:
98116
return self._http_client.make_request(

identify/microclients/environment_microclient.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ class EnvironmentMicroClient:
2323

2424
def __init__(self, http_client):
2525
'''
26+
Constructor
2627
'''
2728
self._http_client = http_client
2829

2930
def list(self):
3031
'''
3132
Returns a list of Environment objects.
33+
34+
:returns: list of Environment objects
35+
:rtype: list(Environment)
3236
'''
3337
try:
3438
response = self._http_client.make_request(

identify/microclients/identity_microclient.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,19 @@ class IdentityMicroClient:
7272

7373
def __init__(self, http_client):
7474
'''
75+
Constructor
7576
'''
7677
self._http_client = http_client
7778

7879
def save(self, identity):
7980
'''
81+
Save an identity
82+
83+
:param identity: Identity instance or dict containing keys with identity
84+
properties
85+
86+
:returns: newly created Identity
87+
:rtype: Identity
8088
'''
8189
try:
8290
data = identity.to_dict() if isinstance(identity, Identity) else identity
@@ -98,7 +106,15 @@ def save(self, identity):
98106

99107
def save_all(self, identities):
100108
'''
101-
entities: { key: { attr_id: value, ...} }
109+
Save multiple identities at once
110+
111+
:param identities: array of Identity instances or dicts containing keys
112+
with identity's properties
113+
114+
:returns: tuple with successful and failed items. Succesful items
115+
are Identity objects. Failed ones will contain the Identity object
116+
for the failed item togegther with a status code and a message
117+
:rtype: tuple
102118
'''
103119
# TODO: Validate!
104120
try:
@@ -139,6 +155,13 @@ def save_all(self, identities):
139155

140156
def update(self, identity):
141157
'''
158+
Update an existing identity
159+
160+
:param identity: Identity instance or dict containing keys with identity
161+
properties
162+
163+
:returns: updated Identity
164+
:rtype: Identity
142165
'''
143166
try:
144167
data = identity.to_dict() if isinstance(identity, Identity) else identity
@@ -160,6 +183,13 @@ def update(self, identity):
160183

161184
def patch(self, identity):
162185
'''
186+
Patch an existing identity
187+
188+
:param identity: Identity instance or dict containing keys with identity
189+
properties
190+
191+
:returns: patched Identity
192+
:rtype: Identity
163193
'''
164194
try:
165195
data = identity.to_dict() if isinstance(identity, Identity) else identity
@@ -181,6 +211,9 @@ def patch(self, identity):
181211

182212
def delete_all_attributes(self, identity):
183213
'''
214+
Delete all attributes from the current identity
215+
216+
:param identity: Identity instance
184217
'''
185218
return self.delete_all_attributes_by_id(
186219
identity.traffic_type_id,
@@ -190,6 +223,12 @@ def delete_all_attributes(self, identity):
190223

191224
def delete_all_attributes_by_id(self, traffic_type_id, environment_id, key):
192225
'''
226+
Delete all attributes by specifying the traffic type id, the environment
227+
id and the identity's key instead of passing an Identify object.
228+
229+
:param traffic_type_id: Identity's traffic type id
230+
:param environment_id: Identity's environment id
231+
:param key: Identity's key
193232
'''
194233
try:
195234
self._http_client.make_request(

identify/microclients/traffic_type_microclient.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ class TrafficTypeMicroClient:
2323

2424
def __init__(self, http_client):
2525
'''
26+
Constructor
2627
'''
2728
self._http_client = http_client
2829

2930
def list(self):
3031
'''
3132
Returns a list of TrafficType objects.
33+
34+
:returns: List of TrafficType objects
35+
:rtype: list(TrafficType)
3236
'''
3337
try:
3438
response = self._http_client.make_request(

identify/resources/attribute.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ def is_searchable(self, new):
6767

6868
def delete(self, identify_client=None):
6969
'''
70+
Delete this attribute
71+
72+
:param identify_client: If this instance wasn't returned by the client,
73+
the IdentifyClient instance should be passed in order to perform the
74+
http call
7075
'''
7176
if identify_client is not None:
7277
amc = identify_client.attribute

identify/resources/environment.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ def name(self, new):
2828

2929
def add_identity(self, data, identify_client=None):
3030
'''
31+
Add a new identity associated with this environment.
32+
33+
:param data: Identity object or dict containing identity properties
34+
:param identify_client: If this instance wasn't returned by the client,
35+
the IdentifyClient instance should be passed in order to perform the
36+
http call
3137
'''
3238
if identify_client is not None:
3339
imc = identify_client.identity
@@ -44,6 +50,18 @@ def add_identity(self, data, identify_client=None):
4450

4551
def add_identities(self, data, identify_client=None):
4652
'''
53+
Add multiple new identities associated with this environment.
54+
55+
:param data: list ofIdentity objects or dicts containing identity
56+
properties
57+
:param identify_client: If this instance wasn't returned by the client,
58+
the IdentifyClient instance should be passed in order to perform the
59+
http call
60+
61+
:returns: tuple with successful and failed items. Succesful items
62+
are Identity objects. Failed ones will contain the Identity object
63+
for the failed item togegther with a status code and a message
64+
:rtype: tuple
4765
'''
4866
if identify_client is not None:
4967
imc = identify_client.identity

identify/resources/identity.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ def organization_id(self, new):
6666

6767
def save(self, identify_client=None):
6868
'''
69+
Save this Identity
70+
71+
:param identify_client: If this instance wasn't returned by the client,
72+
the IdentifyClient instance should be passed in order to perform the
73+
http call
74+
75+
:returns: newly saved Identity object
76+
:rtype: Identity
6977
'''
7078
if identify_client is not None:
7179
imc = identify_client.identity
@@ -79,6 +87,14 @@ def save(self, identify_client=None):
7987

8088
def update(self, identify_client=None):
8189
'''
90+
Update this Identity
91+
92+
:param identify_client: If this instance wasn't returned by the client,
93+
the IdentifyClient instance should be passed in order to perform the
94+
http call
95+
96+
:returns: newly saved Identity object
97+
:rtype: Identity
8298
'''
8399
if identify_client is not None:
84100
imc = identify_client.identity
@@ -92,6 +108,11 @@ def update(self, identify_client=None):
92108

93109
def delete_attributes(self, identify_client=None):
94110
'''
111+
Delete all attributes from this Identity
112+
113+
:param identify_client: If this instance wasn't returned by the client,
114+
the IdentifyClient instance should be passed in order to perform the
115+
http call
95116
'''
96117
if identify_client is not None:
97118
imc = identify_client.identity

identify/resources/traffic_type.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class TrafficType(BaseResource):
1717

1818
def __init__(self, data, client=None):
1919
'''
20+
Constructor
2021
'''
2122
BaseResource.__init__(self, data.get('id'), client)
2223
self._name = data.get('name')
@@ -40,6 +41,14 @@ def display_attribute_id(self, new):
4041

4142
def fetch_attributes(self, identify_client=None):
4243
'''
44+
Fetch all attributes for this traffic type
45+
46+
:param identify_client: If this instance wasn't returned by the client,
47+
the IdentifyClient instance should be passed in order to perform the
48+
http call
49+
50+
:returns: List of attributes associated with this traffic type
51+
:rtype: list(Attribute)
4352
'''
4453
if identify_client is not None:
4554
amc = identify_client.attribute
@@ -52,6 +61,15 @@ def fetch_attributes(self, identify_client=None):
5261

5362
def add_attribute(self, data, identify_client=None):
5463
'''
64+
Add a new attribute associated with this traffic type
65+
66+
:param data: Attribute instance or dict containing Attribute properties
67+
:param identify_client: If this instance wasn't returned by the client,
68+
the IdentifyClient instance should be passed in order to perform the
69+
http call
70+
71+
:returns: Newly created attribute
72+
:rtype: Attribute
5573
'''
5674
if identify_client is not None:
5775
amc = identify_client.attribute
@@ -68,6 +86,15 @@ def add_attribute(self, data, identify_client=None):
6886

6987
def add_identity(self, data, identify_client=None):
7088
'''
89+
Add a new identity associated with this traffic type.
90+
91+
:param data: Identity object or dict containing identity properties
92+
:param identify_client: If this instance wasn't returned by the client,
93+
the IdentifyClient instance should be passed in order to perform the
94+
http call
95+
96+
:returns: newly created Identity
97+
:rtype: Identity
7198
'''
7299
if identify_client is not None:
73100
imc = identify_client.identity
@@ -84,6 +111,18 @@ def add_identity(self, data, identify_client=None):
84111

85112
def add_identities(self, data, identify_client=None):
86113
'''
114+
Add multiple new identities associated with this traffic type.
115+
116+
:param data: list ofIdentity objects or dicts containing identity
117+
properties
118+
:param identify_client: If this instance wasn't returned by the client,
119+
the IdentifyClient instance should be passed in order to perform the
120+
http call
121+
122+
:returns: tuple with successful and failed items. Succesful items
123+
are Identity objects. Failed ones will contain the Identity object
124+
for the failed item togegther with a status code and a message
125+
:rtype: tuple
87126
'''
88127
if identify_client is not None:
89128
imc = identify_client.identity

identify/tests/resources/test_base_resource.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,3 @@ def from_dict(self, c, r): pass
2626

2727
b = SampleResource2('', '')
2828
assert isinstance(b, BaseResource)
29-
30-
def test_validate(self):
31-
# TODO!
32-
pass
33-
34-
def test_to_dict(self):
35-
# TODO!
36-
pass

0 commit comments

Comments
 (0)