--- /dev/null
+class Friend():
+
+ def __init__(self, name, source=None):
+ """ source is source service, such as LinkedIn """
+ self._attributes = { "fn": name }
+ self._multi_attributes = {}
+ self._source = source
+
+ def __unicode__(self):
+ return self.__repr__()
+
+ def __repr__(self):
+ return "Friend %s" % self._attributes['fn']
+
+ # public accessors -----------------
+
+ def get_name(self):
+ return self._attributes['fn']
+
+ def add_url(self, url):
+ self._add('url', url)
+
+ def is_empty(self):
+ for a in self._attributes:
+ return False
+ for a in self._multi_attributes:
+ return False
+ return True
+
+ def has_birthday_date(self):
+ return self._has('bday')
+
+ def set_name(self, name):
+ self._set('fn', name)
+
+ def set_nickname(self, nickname):
+ self._set('nickname', nickname)
+
+ def set_birthday_date(self, date):
+ self._set('bday', date)
+
+ def set_photo_url(self, url):
+ self._set('photo-url', url)
+
+ def update(self, other_friend):
+ """
+ Overwrites any attributes in this friend, with attributes from other_friend
+ """
+
+ self._attributes.update(other_friend._attributes)
+
+ for key in other_friend._multi_attributes.keys():
+ for value in other_friend._multi_attributes[key]:
+ self._add(key, value)
+
+ def update_contact(self, contact, overwrite=False):
+ """
+ Updates the contact with information from this object,
+ without overwriting unless overwrite is set to True.
+ """
+
+ # FIXME: currently we overwrite everything
+ self._if_defined('photo-url', contact.set_photo)
+ self._if_defined('nickname', contact.set_nickname)
+ if self._multi_attributes.has_key('url'):
+ for url in self._multi_attributes['url']:
+ contact.add_url(url)
+
+ def fixme(arg):
+ pass
+ #print "FIXME - birthday date needs to be parsed/fixed %s before calling contact.set_birthday" % arg
+ self._if_defined('bday', fixme)
+
+ # private helpers -----------------------
+ #
+ def _if_defined(self, key, callback):
+ if self._attributes.has_key(key):
+ callback(self._attributes[key])
+
+ def _set(self, key, value):
+ if value is not None:
+# print "%s SET %s to %s" % (self, key, value)
+ self._attributes[key] = value
+
+ def _add(self, key, value):
+ if value is not None:
+ if not self._multi_attributes.has_key(key):
+ self._multi_attributes[key] = []
+# print "%s ADD %s to %s" % (self, key, value)
+ self._multi_attributes[key].append(value)
+
+ def _has(self, key):
+ return self._attributes.has_key(key) or self._multi_attributes.has_key(key)
+
+ def _contains(self, key, value):
+ if self._attributes.has_key(key):
+ return value == self._attributes[key]
+ if self._multi_attributes.has_key(key):
+ return value in self._multi_attributes[key]
+ return False