11# -*- coding: utf-8 -*-
2+ """Operation to create or save an instance of a particular resource."""
23
34from intercom import utils
45
56
67class Save (object ):
8+ """A mixin that provides `create` and `save` functionality."""
79
810 def create (self , ** params ):
11+ """Create an instance of the resource from the supplied parameters."""
912 collection = utils .resource_class_to_collection_name (
1013 self .collection_class )
1114 response = self .client .post ("/%s/" % (collection ), params )
1215 if response : # may be empty if we received a 202
1316 return self .collection_class (** response )
1417
15- # def from_dict(self, pdict):
16- # for key, value in list(pdict.items()):
17- # setattr(self, key, value)
18-
19- # @property
20- # def to_dict(self):
21- # a_dict = {}
22- # for name in list(self.__dict__.keys()):
23- # if name == "changed_attributes":
24- # continue
25- # a_dict[name] = self.__dict__[name] # direct access
26- # return a_dict
27-
28- # @classmethod
29- # def from_api(cls, response):
30- # obj = cls()
31- # obj.from_response(response)
32- # return obj
33-
34- # def from_response(self, response):
35- # self.from_dict(response)
36- # return self
37-
3818 def save (self , obj ):
19+ """Save the instance of the resource."""
3920 collection = utils .resource_class_to_collection_name (
4021 obj .__class__ )
4122 params = obj .attributes
@@ -50,12 +31,15 @@ def save(self, obj):
5031 return obj .from_response (response )
5132
5233 def id_present (self , obj ):
34+ """Return whether the obj has an `id` attribute with a value."""
5335 return getattr (obj , 'id' , None ) and obj .id != ""
5436
5537 def posted_updates (self , obj ):
38+ """Return whether the updates to this object have been posted to Intercom."""
5639 return getattr (obj , 'update_verb' , None ) == 'post'
5740
5841 def identity_hash (self , obj ):
42+ """Return the identity_hash for this object."""
5943 identity_vars = getattr (obj , 'identity_vars' , [])
6044 parts = {}
6145 for var in identity_vars :
0 commit comments