Dependency inject service ID, so that it can be stamped on friends and
[hermes] / package / src / org / maemo / hermes / engine / friend.py
index 0264aaa..32ee3c2 100644 (file)
@@ -1,8 +1,16 @@
 class Friend():
+    """Encapsulate the data from a remote service.
     
-    def __init__(self, name):
-        self._attributes = { "fn": name }
+       Copyright (c) Fredrik Wendt <fredrik@wendt.se> 2010.
+       Released under the Artistic Licence."""
+
+    
+    def __init__(self, name=None, source=None):
+        """ source is source service, such as LinkedIn """
+        self._attributes = {};
+        if name: self._set('fn', name)
         self._multi_attributes = {}
+        self._source = source 
         
     def __unicode__(self):
         return self.__repr__()
@@ -12,6 +20,26 @@ class Friend():
     
     # public accessors -----------------
     
+    def get_contact(self):
+        return self._attributes['contact']
+    
+    def get_name(self):
+        return self._attributes['fn']
+    
+    def get_source(self):
+        return self._source
+    
+    def get_nickname(self):
+        return self._attributes["nickname"]
+    
+    def get_urls(self):
+        try: return self._multi_attributes['url'] 
+        except: return []
+        
+    def get_photo_url(self):
+        try: return self._attributes['photo-url']
+        except: return None
+    
     def add_url(self, url):
         self._add('url', url)
         
@@ -34,6 +62,9 @@ class Friend():
     def set_birthday_date(self, date):
         self._set('bday', date)
         
+    def set_contact(self, contact):
+        self._set('contact', contact)
+        
     def set_photo_url(self, url):
         self._set('photo-url', url)
     
@@ -86,4 +117,13 @@ class Friend():
     
     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
+    
+    def __getitem__(self, key):
+        return self._attributes[key]