def save(self):
     entity_id = self.pop('id', None)
     if not entity_id:
         raise ValueError("Can't update {} without id. "
                          "Create or retrieve it first".format(self.__class__.__name__))
     response = self._api_client.put(self.RESOURCE_PATH, entity_id, data=self.serialize())
     data = util.convert_to_api_object(response, self._api_client, self.__class__)
     self.refresh_from(**data)
     return self
 def refresh_from(self, **kwargs):
     # update fields with new data if any
     removed = set(self.keys()) - set(kwargs)
     self._passing_values = self._passing_values | removed
     self._unsaved_values = set()
     self.clear()
     self._passing_values = self._passing_values - set(kwargs)
     # perform conversion for nested data
     for k, v in kwargs.items():
         converted_value = util.convert_to_api_object(
             v, api_client=self._api_client)
         super(APIObject, self).__setitem__(k, converted_value)
 def delete(self, **params):
     entity_id = self.get('id')
     if not entity_id:
         raise ValueError("Can't delete {} without id. "
                          "Create or retrieve it first".format(
                              self.__class__.__name__))
     response = self._api_client.delete(self.RESOURCE_PATH,
                                        entity_id,
                                        data=params)
     data = util.convert_to_api_object(response, self._api_client,
                                       self.__class__)
     self.refresh_from(**data)
     return self
 def resolve(cls, entity_id, **params):
     response = cls._api_client.post(
         cls.RESOURCE_PATH, entity_id, 'resolve',
         data=params
     )
     return util.convert_to_api_object(response, cls._api_client, cls)
 def create(cls, **params):
     response = cls._api_client.post(cls.RESOURCE_PATH, data=params)
     return util.convert_to_api_object(response, cls._api_client, cls)
 def modify(cls, entity_id, **params):
     response = cls._api_client.put(cls.RESOURCE_PATH, entity_id, data=params)
     return util.convert_to_api_object(response, cls._api_client, cls)
 def retrieve(cls, entity_id, **params):
     response = cls._api_client.get(cls.RESOURCE_PATH,
                                    entity_id,
                                    params=params)
     api_obj = util.convert_to_api_object(response, cls._api_client, cls)
     return api_obj
 def list(cls, **params):
     response = cls._api_client.get(cls.RESOURCE_PATH, params=params)
     return util.convert_to_api_object(response, api_client=cls._api_client, resource_class=cls)