-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsplit.py
More file actions
106 lines (91 loc) · 3.8 KB
/
split.py
File metadata and controls
106 lines (91 loc) · 3.8 KB
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
from __future__ import absolute_import, division, print_function, \
unicode_literals
from splitapiclient.resources.base_resource import BaseResource
from splitapiclient.util.helpers import require_client, as_dict
from splitapiclient.resources import TrafficType
class Split(BaseResource):
'''
'''
_schema = {
'name': 'string',
'description': 'string',
'trafficType' : {
'id': 'string',
'namr': 'string'
},
'creationTime' : 'number',
'id': 'string',
'rolloutStatus': {
'id': 'string',
'name': 'string'
},
'rolloutStatusTimestamp': 'number',
'tags': [{'name': 'string'}],
'owners': [{'id':'string','type':'string'}]
}
def __init__(self, data=None, workspace_id=None, client=None):
'''
'''
if not data:
data = {}
BaseResource.__init__(self, data.get('name'), client)
self._name = data.get('name')
self._description = data.get('description')
self._trafficType = TrafficType(data.get('trafficType')) if 'trafficType' in data else {}
self._workspace_id = workspace_id
self._creationTime = data.get('creationTime') if 'creationTime' in data else 0
self._tags = data.get('tags') if 'tags' in data else []
self._id = data.get('id') if 'id' in data else None
self._rolloutStatus = data.get('rolloutStatus') if 'rolloutStatus' in data else {}
self._rolloutStatusTimestamp = data.get('rolloutStatusTimestamp') if 'rolloutStatusTimestamp' in data else 0
self._owners = data.get('owners') if 'owners' in data else []
@property
def name(self):
return self._name
@property
def description(self):
return self._description
def update_description(self, new_description, apiclient=None):
'''
Update split description
'''
imc = require_client('Split', self._client, apiclient)
return imc.update_description(self._name, new_description, self._workspace_id)
def add_to_environment(self, environment_id, data, apiclient=None):
'''
Add split to environment
:param data: environment id
:param apiclient: If this instance wasn't returned by the client,
the IdentifyClient instance should be passed in order to perform the
http call
:returns: SplitDefinition instance
:rtype: SplitDefinition
'''
imc = require_client('Split', self._client, apiclient)
return imc.add_to_environment(self._name, environment_id, self._workspace_id, data)
def remove_from_environment(self, environment_id, comment="", title="", apiclient=None):
'''
Remove split from environment
:param data: environment id
:param data: title
:param data: comment
:param apiclient: If this instance wasn't returned by the client,
the IdentifyClient instance should be passed in order to perform the
http call
:returns: SplitDefinition instance
:rtype: SplitDefinition
'''
imc = require_client('Split', self._client, apiclient)
return imc.remove_from_environment(self._name, environment_id, comment, title, self._workspace_id)
def associate_tags(self, tags, apiclient=None):
'''
Add tags to split
:param data: array of tags (strings)
:param apiclient: If this instance wasn't returned by the client,
the IdentifyClient instance should be passed in order to perform the
http call
:returns: True if successful
:rtype: boolean
'''
imc = require_client('Split', self._client, apiclient)
return imc.associate_tags(self._name, tags, self._workspace_id)