3 def __init__(self, name, source=None):
4 """ source is source service, such as LinkedIn """
5 self._attributes = { "fn": name }
6 self._multi_attributes = {}
10 return self.__repr__()
13 return "Friend %s" % self._attributes['fn']
15 # public accessors -----------------
18 return self._attributes['fn']
20 def add_url(self, url):
24 for a in self._attributes:
26 for a in self._multi_attributes:
30 def has_birthday_date(self):
31 return self._has('bday')
33 def set_name(self, name):
36 def set_nickname(self, nickname):
37 self._set('nickname', nickname)
39 def set_birthday_date(self, date):
40 self._set('bday', date)
42 def set_photo_url(self, url):
43 self._set('photo-url', url)
45 def update(self, other_friend):
47 Overwrites any attributes in this friend, with attributes from other_friend
50 self._attributes.update(other_friend._attributes)
52 for key in other_friend._multi_attributes.keys():
53 for value in other_friend._multi_attributes[key]:
56 def update_contact(self, contact, overwrite=False):
58 Updates the contact with information from this object,
59 without overwriting unless overwrite is set to True.
62 # FIXME: currently we overwrite everything
63 self._if_defined('photo-url', contact.set_photo)
64 self._if_defined('nickname', contact.set_nickname)
65 if self._multi_attributes.has_key('url'):
66 for url in self._multi_attributes['url']:
71 #print "FIXME - birthday date needs to be parsed/fixed %s before calling contact.set_birthday" % arg
72 self._if_defined('bday', fixme)
74 # private helpers -----------------------
76 def _if_defined(self, key, callback):
77 if self._attributes.has_key(key):
78 callback(self._attributes[key])
80 def _set(self, key, value):
82 # print "%s SET %s to %s" % (self, key, value)
83 self._attributes[key] = value
85 def _add(self, key, value):
87 if not self._multi_attributes.has_key(key):
88 self._multi_attributes[key] = []
89 # print "%s ADD %s to %s" % (self, key, value)
90 self._multi_attributes[key].append(value)
93 return self._attributes.has_key(key) or self._multi_attributes.has_key(key)
95 def _contains(self, key, value):
96 if self._attributes.has_key(key):
97 return value == self._attributes[key]
98 if self._multi_attributes.has_key(key):
99 return value in self._multi_attributes[key]