Dependency inject service ID, so that it can be stamped on friends and
[hermes] / package / src / org / maemo / hermes / engine / service.py
1 from friend import Friend
2
3 class Service:
4     """The notional `Service' for a provider. This is responsible for communicating
5        with the backend service and enhancing contacts.
6        
7        Copyright (c) Andrew Flegg <andrew@bleb.org> 2010.
8        Released under the Artistic Licence."""
9        
10     def __init__(self, service_id):
11         """Should make initial calls to the service and retrieve a list of friends."""
12         
13         self._service_id = service_id
14
15
16     # -----------------------------------------------------------------------
17     def get_id(self):
18         """Return the service ID, as given to the service at creation."""
19         
20         return self._service_id
21
22     
23     # -----------------------------------------------------------------------
24     def pre_process_contact(self, contact):
25         """If the contact have an URL (or similar) that proves an existing matching
26            to a friend on this service, then this should be remembered to avoid
27            name collision/mapping the same friend to other contacts with the same 
28            name."""
29          
30         return None
31
32     
33     def process_friends(self):
34         """Called once to signal that it's time to get all friends' data."""
35         
36         pass
37     
38     
39     # -----------------------------------------------------------------------
40     def process_contact(self, contact):
41         """Called for each contact in the address book. If the contact can be 
42            matched to a Friend, than return the Friend object or None."""
43            
44         pass
45     
46     
47     # -----------------------------------------------------------------------
48     def get_unmatched_friends(self):
49         """Return a list of friends not matched to a contact, or 'None' if manual mapping
50            is not supported."""
51          
52         return None
53
54
55     # -----------------------------------------------------------------------
56     def create_contacts(self):
57         """Return a list of friends which should have contacts created. This
58            should expected by the user, and optional."""
59            
60         return []
61
62
63     # -----------------------------------------------------------------------
64     def finalise(self, updated, overwrite = False):
65         """Once all contacts have been processed, allows for any tidy-up/additional
66            enrichment. If any contacts are updated at this stage, 'updated' should
67            be added to."""
68            
69         pass
70
71
72     # -----------------------------------------------------------------------
73     ###DEPRECATED
74     def _create_friend(self, name):
75         """Used to create a Friend object for a contact"""
76         
77         return Friend(name, self._service_id)