99from identify .util .exceptions import InsufficientConfigArgumentsException
1010
1111
12- class SyncIdentifyClient ( BaseIdentifyClient ) :
12+ class TrafficTypeMicroClient :
1313 '''
14- Synchronous Identify API client
1514 '''
1615
17- def __init__ (self , config ):
16+ def __init__ (self , http_client ):
1817 '''
19- Class constructor.
18+ '''
19+ self ._http_client = http_client
2020
21- :param config: Dictionary containing optiones required to instantiate
22- the API client. Shoud have AT LEAST the following keys:
23- - 'base_url': Base url where the API is hosted
24- - 'apikey': APIKey used to authenticate the user.
21+ def get_all (self ):
2522 '''
26- if 'base_url' in config and 'apikey' in config :
27- self ._base_url = config ['base_url' ]
28- self ._apikey = config ['apikey' ]
29- else :
30- missing = [i not in config for i in ['base_url' , 'apikey' ]]
31- raise InsufficientConfigArgumentsException (
32- 'The following keys must be present in the config dict: %s'
33- % ',' .join (missing )
34- )
23+ Returns a list of TrafficType objects.
24+ '''
25+ return TrafficType .retrieve_all (self ._http_client )
26+
3527
36- self ._client = SyncHttpClient (self ._base_url , self ._apikey )
28+ class EnvironmentMicroClient :
29+ '''
30+ '''
3731
38- def get_traffic_types (self ):
32+ def __init__ (self , http_client ):
3933 '''
40- Returns a list of TrafficType objects.
4134 '''
42- return TrafficType . retrieve_all ( self ._client )
35+ self ._http_client = http_client
4336
44- def get_environments (self ):
37+ def get_all (self ):
4538 '''
4639 Returns a list of environments.
4740 '''
48- return Environment .retrieve_all (self ._client )
41+ return Environment .retrieve_all (self ._http_client )
42+
4943
50- def get_attributes_for_traffic_type (self , traffic_type_id ):
44+ class AttributeMicroClient :
45+ '''
46+ '''
47+
48+ def __init__ (self , http_client ):
49+ '''
50+ '''
51+ self ._http_client = http_client
52+
53+ def get_all (self , traffic_type_id ):
5154 '''
5255 Returns a list of attributes for a particular traffic type.
5356
5457 :param traffic_type_id: Id of the traffic type whose attributes are to
5558 be retrieved.
5659 '''
5760 return Attribute .retrieve_all (
58- self ._client ,
61+ self ._http_client ,
5962 trafficTypeId = traffic_type_id
6063 )
6164
62- def create_attribute_for_traffic_type (self , traffic_type_id , attr_data ):
65+ def create (self , traffic_type_id , attr_data ):
6366 '''
6467 Creates an attribute for a specific traffic type.
6568
@@ -73,7 +76,7 @@ def create_attribute_for_traffic_type(self, traffic_type_id, attr_data):
7376 - 'dataType': Data type of the new attribute
7477 '''
7578 return Attribute .create (
76- self ._client ,
79+ self ._http_client ,
7780 attr_data .get ('id' ),
7881 traffic_type_id ,
7982 attr_data .get ('displayName' ),
@@ -82,18 +85,28 @@ def create_attribute_for_traffic_type(self, traffic_type_id, attr_data):
8285 attr_data .get ('isSearchable' )
8386 )
8487
85- def delete_attribute_from_schema (self , traffic_type_id , attribute_id ):
88+ def delete (self , traffic_type_id , attribute_id ):
8689 '''
8790 Delete an attribute from a particular traffic type.
8891
8992 :param traffic_type_id: Trafic id of the schema whose attribute
9093 will be removed.
9194 :param attribute_id: Id of the attribute to be removed.
9295 '''
93- return Attribute .delete (self ._client , attribute_id , traffic_type_id )
96+ return Attribute .delete (self ._http_client , attribute_id , traffic_type_id )
97+
98+
99+ class IdentityMicroClient :
100+ '''
101+ '''
94102
95- def add_identities (self , traffic_type_id , environment_id , identities ,
96- organization_id = None ):
103+ def __init__ (self , http_client ):
104+ '''
105+ '''
106+ self ._http_client = http_client
107+
108+ def add_many (self , traffic_type_id , environment_id , identities ,
109+ organization_id = None ):
97110 '''
98111 Create Identities for a specific traffic type and environment.
99112
@@ -113,15 +126,15 @@ def add_identities(self, traffic_type_id, environment_id, identities,
113126 }
114127 '''
115128 return Identity .create_many (
116- self ._client ,
129+ self ._http_client ,
117130 traffic_type_id ,
118131 environment_id ,
119132 identities ,
120133 organization_id
121134 )
122135
123- def add_identity (self , traffic_type_id , environment_id , key , values ,
124- organization_id = None ):
136+ def add (self , traffic_type_id , environment_id , key , values ,
137+ organization_id = None ):
125138 '''
126139 Create a new Identity.
127140
@@ -136,16 +149,16 @@ def add_identity(self, traffic_type_id, environment_id, key, values,
136149 }
137150 '''
138151 return Identity .create (
139- self ._client ,
152+ self ._http_client ,
140153 key ,
141154 traffic_type_id ,
142155 environment_id ,
143156 values ,
144157 organization_id
145158 )
146159
147- def update_identity (self , traffic_type_id , environment_id , key , values ,
148- organization_id = None ):
160+ def update (self , traffic_type_id , environment_id , key , values ,
161+ organization_id = None ):
149162 '''
150163 Update an Identity.
151164
@@ -160,16 +173,16 @@ def update_identity(self, traffic_type_id, environment_id, key, values,
160173 }
161174 '''
162175 return Identity .update (
163- self ._client ,
176+ self ._http_client ,
164177 key ,
165178 traffic_type_id ,
166179 environment_id ,
167180 values ,
168181 organization_id
169182 )
170183
171- def patch_identity (self , traffic_type_id , environment_id , key , values ,
172- organization_id = None ):
184+ def patch (self , traffic_type_id , environment_id , key , values ,
185+ organization_id = None ):
173186 '''
174187 Patch an Identity.
175188
@@ -184,15 +197,15 @@ def patch_identity(self, traffic_type_id, environment_id, key, values,
184197 }
185198 '''
186199 return Identity .patch (
187- self ._client ,
200+ self ._http_client ,
188201 key ,
189202 traffic_type_id ,
190203 environment_id ,
191204 values ,
192205 organization_id
193206 )
194207
195- def delete_attributes_from_key (self , traffic_type_id , environment_id , key ):
208+ def delete_attributes (self , traffic_type_id , environment_id , key ):
196209 '''
197210 Delete all attributes for a specific key.
198211
@@ -201,8 +214,56 @@ def delete_attributes_from_key(self, traffic_type_id, environment_id, key):
201214 :key: Key whose attributes will be deleted.
202215 '''
203216 return Identity .delete_all_attributes (
204- self ._client ,
217+ self ._http_client ,
205218 traffic_type_id ,
206219 environment_id ,
207220 key
208221 )
222+
223+
224+ class SyncIdentifyClient (BaseIdentifyClient ):
225+ '''
226+ Synchronous Identify API client
227+ '''
228+
229+ def __init__ (self , config ):
230+ '''
231+ Class constructor.
232+
233+ :param config: Dictionary containing optiones required to instantiate
234+ the API client. Shoud have AT LEAST the following keys:
235+ - 'base_url': Base url where the API is hosted
236+ - 'apikey': APIKey used to authenticate the user.
237+ '''
238+ if 'base_url' in config and 'apikey' in config :
239+ self ._base_url = config ['base_url' ]
240+ self ._apikey = config ['apikey' ]
241+ else :
242+ missing = [i not in config for i in ['base_url' , 'apikey' ]]
243+ raise InsufficientConfigArgumentsException (
244+ 'The following keys must be present in the config dict: %s'
245+ % ',' .join (missing )
246+ )
247+
248+ http_client = SyncHttpClient (self ._base_url , self ._apikey )
249+
250+ self ._traffic_type_client = TrafficTypeMicroClient (http_client )
251+ self ._environment_client = EnvironmentMicroClient (http_client )
252+ self ._attribute_client = AttributeMicroClient (http_client )
253+ self ._identity_client = IdentityMicroClient (http_client )
254+
255+ @property
256+ def traffic_type (self ):
257+ return self ._traffic_type_client
258+
259+ @property
260+ def environment (self ):
261+ return self ._environment_client
262+
263+ @property
264+ def attribute (self ):
265+ return self ._attribute_client
266+
267+ @property
268+ def identity (self ):
269+ return self ._identity_client
0 commit comments