1# coding=utf-8 2r""" 3This code was generated by 4\ / _ _ _| _ _ 5 | (_)\/(_)(_|\/| |(/_ v1.0.0 6 / / 7""" 8 9from twilio.base import values 10from twilio.base.instance_context import InstanceContext 11from twilio.base.instance_resource import InstanceResource 12from twilio.base.list_resource import ListResource 13from twilio.base.page import Page 14 15 16class UserList(ListResource): 17 """ PLEASE NOTE that this class contains beta products that are subject to 18 change. Use them with caution. """ 19 20 def __init__(self, version): 21 """ 22 Initialize the UserList 23 24 :param Version version: Version that contains the resource 25 26 :returns: twilio.rest.frontline_api.v1.user.UserList 27 :rtype: twilio.rest.frontline_api.v1.user.UserList 28 """ 29 super(UserList, self).__init__(version) 30 31 # Path Solution 32 self._solution = {} 33 34 def get(self, sid): 35 """ 36 Constructs a UserContext 37 38 :param sid: The SID of the User resource to fetch 39 40 :returns: twilio.rest.frontline_api.v1.user.UserContext 41 :rtype: twilio.rest.frontline_api.v1.user.UserContext 42 """ 43 return UserContext(self._version, sid=sid, ) 44 45 def __call__(self, sid): 46 """ 47 Constructs a UserContext 48 49 :param sid: The SID of the User resource to fetch 50 51 :returns: twilio.rest.frontline_api.v1.user.UserContext 52 :rtype: twilio.rest.frontline_api.v1.user.UserContext 53 """ 54 return UserContext(self._version, sid=sid, ) 55 56 def __repr__(self): 57 """ 58 Provide a friendly representation 59 60 :returns: Machine friendly representation 61 :rtype: str 62 """ 63 return '<Twilio.FrontlineApi.V1.UserList>' 64 65 66class UserPage(Page): 67 """ PLEASE NOTE that this class contains beta products that are subject to 68 change. Use them with caution. """ 69 70 def __init__(self, version, response, solution): 71 """ 72 Initialize the UserPage 73 74 :param Version version: Version that contains the resource 75 :param Response response: Response from the API 76 77 :returns: twilio.rest.frontline_api.v1.user.UserPage 78 :rtype: twilio.rest.frontline_api.v1.user.UserPage 79 """ 80 super(UserPage, self).__init__(version, response) 81 82 # Path Solution 83 self._solution = solution 84 85 def get_instance(self, payload): 86 """ 87 Build an instance of UserInstance 88 89 :param dict payload: Payload response from the API 90 91 :returns: twilio.rest.frontline_api.v1.user.UserInstance 92 :rtype: twilio.rest.frontline_api.v1.user.UserInstance 93 """ 94 return UserInstance(self._version, payload, ) 95 96 def __repr__(self): 97 """ 98 Provide a friendly representation 99 100 :returns: Machine friendly representation 101 :rtype: str 102 """ 103 return '<Twilio.FrontlineApi.V1.UserPage>' 104 105 106class UserContext(InstanceContext): 107 """ PLEASE NOTE that this class contains beta products that are subject to 108 change. Use them with caution. """ 109 110 def __init__(self, version, sid): 111 """ 112 Initialize the UserContext 113 114 :param Version version: Version that contains the resource 115 :param sid: The SID of the User resource to fetch 116 117 :returns: twilio.rest.frontline_api.v1.user.UserContext 118 :rtype: twilio.rest.frontline_api.v1.user.UserContext 119 """ 120 super(UserContext, self).__init__(version) 121 122 # Path Solution 123 self._solution = {'sid': sid, } 124 self._uri = '/Users/{sid}'.format(**self._solution) 125 126 def fetch(self): 127 """ 128 Fetch the UserInstance 129 130 :returns: The fetched UserInstance 131 :rtype: twilio.rest.frontline_api.v1.user.UserInstance 132 """ 133 payload = self._version.fetch(method='GET', uri=self._uri, ) 134 135 return UserInstance(self._version, payload, sid=self._solution['sid'], ) 136 137 def update(self, friendly_name=values.unset, avatar=values.unset, 138 state=values.unset, is_available=values.unset): 139 """ 140 Update the UserInstance 141 142 :param unicode friendly_name: The string that you assigned to describe the User 143 :param unicode avatar: The avatar URL which will be shown in Frontline application 144 :param UserInstance.StateType state: Current state of this user 145 :param bool is_available: Whether the User is available for new conversations 146 147 :returns: The updated UserInstance 148 :rtype: twilio.rest.frontline_api.v1.user.UserInstance 149 """ 150 data = values.of({ 151 'FriendlyName': friendly_name, 152 'Avatar': avatar, 153 'State': state, 154 'IsAvailable': is_available, 155 }) 156 157 payload = self._version.update(method='POST', uri=self._uri, data=data, ) 158 159 return UserInstance(self._version, payload, sid=self._solution['sid'], ) 160 161 def __repr__(self): 162 """ 163 Provide a friendly representation 164 165 :returns: Machine friendly representation 166 :rtype: str 167 """ 168 context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) 169 return '<Twilio.FrontlineApi.V1.UserContext {}>'.format(context) 170 171 172class UserInstance(InstanceResource): 173 """ PLEASE NOTE that this class contains beta products that are subject to 174 change. Use them with caution. """ 175 176 class StateType(object): 177 ACTIVE = "active" 178 DEACTIVATED = "deactivated" 179 180 def __init__(self, version, payload, sid=None): 181 """ 182 Initialize the UserInstance 183 184 :returns: twilio.rest.frontline_api.v1.user.UserInstance 185 :rtype: twilio.rest.frontline_api.v1.user.UserInstance 186 """ 187 super(UserInstance, self).__init__(version) 188 189 # Marshaled Properties 190 self._properties = { 191 'sid': payload.get('sid'), 192 'identity': payload.get('identity'), 193 'friendly_name': payload.get('friendly_name'), 194 'avatar': payload.get('avatar'), 195 'state': payload.get('state'), 196 'is_available': payload.get('is_available'), 197 'url': payload.get('url'), 198 } 199 200 # Context 201 self._context = None 202 self._solution = {'sid': sid or self._properties['sid'], } 203 204 @property 205 def _proxy(self): 206 """ 207 Generate an instance context for the instance, the context is capable of 208 performing various actions. All instance actions are proxied to the context 209 210 :returns: UserContext for this UserInstance 211 :rtype: twilio.rest.frontline_api.v1.user.UserContext 212 """ 213 if self._context is None: 214 self._context = UserContext(self._version, sid=self._solution['sid'], ) 215 return self._context 216 217 @property 218 def sid(self): 219 """ 220 :returns: The unique string that identifies the resource 221 :rtype: unicode 222 """ 223 return self._properties['sid'] 224 225 @property 226 def identity(self): 227 """ 228 :returns: The string that identifies the resource's User 229 :rtype: unicode 230 """ 231 return self._properties['identity'] 232 233 @property 234 def friendly_name(self): 235 """ 236 :returns: The string that you assigned to describe the User 237 :rtype: unicode 238 """ 239 return self._properties['friendly_name'] 240 241 @property 242 def avatar(self): 243 """ 244 :returns: The avatar URL which will be shown in Frontline application 245 :rtype: unicode 246 """ 247 return self._properties['avatar'] 248 249 @property 250 def state(self): 251 """ 252 :returns: Current state of this user 253 :rtype: UserInstance.StateType 254 """ 255 return self._properties['state'] 256 257 @property 258 def is_available(self): 259 """ 260 :returns: Whether the User is available for new conversations 261 :rtype: bool 262 """ 263 return self._properties['is_available'] 264 265 @property 266 def url(self): 267 """ 268 :returns: An absolute URL for this user. 269 :rtype: unicode 270 """ 271 return self._properties['url'] 272 273 def fetch(self): 274 """ 275 Fetch the UserInstance 276 277 :returns: The fetched UserInstance 278 :rtype: twilio.rest.frontline_api.v1.user.UserInstance 279 """ 280 return self._proxy.fetch() 281 282 def update(self, friendly_name=values.unset, avatar=values.unset, 283 state=values.unset, is_available=values.unset): 284 """ 285 Update the UserInstance 286 287 :param unicode friendly_name: The string that you assigned to describe the User 288 :param unicode avatar: The avatar URL which will be shown in Frontline application 289 :param UserInstance.StateType state: Current state of this user 290 :param bool is_available: Whether the User is available for new conversations 291 292 :returns: The updated UserInstance 293 :rtype: twilio.rest.frontline_api.v1.user.UserInstance 294 """ 295 return self._proxy.update( 296 friendly_name=friendly_name, 297 avatar=avatar, 298 state=state, 299 is_available=is_available, 300 ) 301 302 def __repr__(self): 303 """ 304 Provide a friendly representation 305 306 :returns: Machine friendly representation 307 :rtype: str 308 """ 309 context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) 310 return '<Twilio.FrontlineApi.V1.UserInstance {}>'.format(context) 311