Skip to content

Commit f496fef

Browse files
authored
Merge pull request #8 from kleinjoshuaa/import_attributes_from_json
added the ability to import bulk attributes via JSON
2 parents 44d1879 + db3ee7a commit f496fef

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

splitapiclient/microclients/attribute_microclient.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
from splitapiclient.resources import Attribute
23
from splitapiclient.util.exceptions import HTTPResponseError, \
34
UnknownApiClientError
@@ -30,6 +31,17 @@ class AttributeMicroClient:
3031
'query_string': [],
3132
'response': True,
3233
},
34+
'import_from_json': {
35+
'method': 'POST',
36+
'url_template': 'schema/ws/{workspaceId}/trafficTypes/{trafficTypeId}/attribute:bulk',
37+
'headers': [{
38+
'name': 'Authorization',
39+
'template': 'Bearer {value}',
40+
'required': True,
41+
}],
42+
'query_string': [],
43+
'response': True,
44+
},
3345
'delete': {
3446
'method': 'DELETE',
3547
'url_template': 'schema/ws/{workspaceId}/trafficTypes/{trafficTypeId}/{attributeId}',
@@ -134,3 +146,20 @@ def delete_by_instance(self, attribute):
134146
attribute._workspace_id,
135147
data.get('trafficTypeId')
136148
)
149+
def import_attributes_from_json(self, workspaceId, trafficTypeId, data):
150+
'''
151+
import attributes from JSON file into Split
152+
153+
:param segment: workspace id, traffic type id, json data
154+
155+
:returns: bool
156+
'''
157+
res = self._http_client.make_request(
158+
self._endpoint['import_from_json'],
159+
body=data,
160+
workspaceId = workspaceId,
161+
trafficTypeId = trafficTypeId,
162+
)
163+
164+
165+
return True

splitapiclient/resources/traffic_type.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,26 @@ def add_identity(self, data, apiclient=None):
8989
identity['trafficTypeId'] = self.id
9090
return imc.save(identity)
9191

92+
def import_attributes_from_json(self, json_data, apiclient=None):
93+
'''
94+
95+
import attributes from JSON file into Split
96+
97+
:param tt: workspace id, json data, apiclient
98+
99+
:returns: attribute
100+
101+
:param apiclient: If this instance wasn't returned by the client,
102+
the IdentifyClient instance should be passed in order to perform the
103+
http call
104+
105+
:returns: True if successful
106+
:rtype: boolean
107+
'''
108+
amc = require_client('Attribute', self._client, apiclient)
109+
return amc.import_attributes_from_json(self._workspace_id, self.id, data=json_data)
110+
111+
92112
def add_identities(self, data, apiclient=None):
93113
'''
94114
Add multiple new identities associated with this traffic type.

0 commit comments

Comments
 (0)