Renaming managers to backend to conform with DialCentral
[doneit] / src / rtm_backend.py
index 5a3f346..4aab70e 100644 (file)
@@ -12,7 +12,7 @@ def fix_url(rturl):
        return "/".join(rturl.split(r"\/"))
 
 
-class RtMilkManager(object):
+class RtmBackend(object):
        """
        Interface with rememberthemilk.com
 
@@ -39,6 +39,38 @@ class RtMilkManager(object):
                self._timeline = resp.timeline
                self._lists = []
 
+       def save(self):
+               pass
+
+       def load(self):
+               pass
+
+       def add_project(self, name):
+               rsp = self._rtm.lists.add(
+                       timeline=self._timeline,
+                       name=name,
+               )
+               assert rsp.stat == "ok", "Bad response: %r" % (rsp, )
+               self._lists = []
+
+       def set_project_name(self, projId, name):
+               rsp = self._rtm.lists.setName(
+                       timeline=self._timeline,
+                       list_id=projId,
+                       name=name,
+               )
+               assert rsp.stat == "ok", "Bad response: %r" % (rsp, )
+               self._lists = []
+
+       def set_project_visibility(self, projId, visibility):
+               action = self._rtm.lists.unarchive if visibility else self._rtm.lists.archive
+               rsp = action(
+                       timeline=self._timeline,
+                       list_id=projId,
+               )
+               assert rsp.stat == "ok", "Bad response: %r" % (rsp, )
+               self._lists = []
+
        def get_projects(self):
                if len(self._lists) == 0:
                        self._populate_projects()
@@ -51,9 +83,6 @@ class RtMilkManager(object):
                assert len(projs) == 1, "%r: %r / %r" % (projId, projs, self._lists)
                return projs[0]
 
-       def get_project_names(self):
-               return (list["name"] for list in self.get_projects)
-
        def lookup_project(self, projName):
                """
                From a project's name, returns the project's details
@@ -92,7 +121,10 @@ class RtMilkManager(object):
                                        "completedDate": task.completed,
                                        "priority": task.priority,
                                        "estimate": task.estimate,
-                                       "notes": list(self._get_notes(taskId, taskSeries.notes)),
+                                       "notes": dict((
+                                               (note["id"], note)
+                                               for note in self._get_notes(taskId, taskSeries.notes)
+                                       )),
                                }
                                taskDetails = self._parse_task_details(rawTaskDetails)
                                yield taskDetails
@@ -218,7 +250,7 @@ class RtMilkManager(object):
        @staticmethod
        def _pack_ids(*ids):
                """
-               >>> RtMilkManager._pack_ids(123, 456)
+               >>> RtmBackend._pack_ids(123, 456)
                '123-456'
                """
                return "-".join((str(id) for id in ids))
@@ -226,7 +258,7 @@ class RtMilkManager(object):
        @staticmethod
        def _unpack_ids(ids):
                """
-               >>> RtMilkManager._unpack_ids("123-456")
+               >>> RtmBackend._unpack_ids("123-456")
                ['123', '456']
                """
                return ids.split("-")