Commits

Anonymous committed c61b225

Add send API and its tests

Comments (0)

Files changed (2)

readitlater/api.py

 import logging
 import urllib
 import urllib2
+import json
 
 API_ENDPOINT = 'https://readitlaterlist.com/v2/'
 
                 url=url, title=title)
         return True
 
+    def send(self, username, password, **params):
+        """
+        Send changes using the `send` method
+
+        See more about this API here:
+        http://readitlaterlist.com/api/docs/#send
+
+        Examples
+        --------
+
+        >>> new = [
+        ...     {"url":"http://google.com",
+        ...      "title":"Google"
+        ...      "ref_id":"123456709"
+        ...      },
+        ...      {"url":"http://ideashower.com"
+        ...       "title":"The Idea Shower"
+        ...      },
+        ... ]
+        >>> api.send(username, password, new=new)
+
+        """
+        jsonparams = dict(
+            (key, json.dumps(
+                dict((str(i), val) for (i, val) in enumerate(vallist))))
+            for (key, vallist) in params.iteritems())
+        self.__call('send', username=username, password=password, **jsonparams)
+        return True
+
     def status(self):
         if not self.__status:
             self.__call('api')

test_readitlater.py

         self.assertTrue(self.api.add(configs.RIL_USERNAME, configs.RIL_PASSWORD, 
             'http://google.com/', 'Google'))
 
+    def test_send_new(self):
+        data = [{"url": "http://google.com",
+                 "title": "Google",
+                 "ref_id": "123456709"},
+                {"url": "http://ideashower.com",
+                 "title": "The Idea Shower"}]
+        self.assertTrue(self.api.send(
+            configs.RIL_USERNAME, configs.RIL_PASSWORD, new=data))
+
+    def test_send_read(self):
+        data = [{"url": "http://google.com"},
+                {"url": "http://ideashower.com"}]
+        self.assertTrue(self.api.send(
+            configs.RIL_USERNAME, configs.RIL_PASSWORD, read=data))
+
+    def test_send_update_title(self):
+        data = [{"url": "http://google.com",
+                 "title": "Google"},
+                {"url": "http://ideashower.com",
+                 "title": "The Idea Shower"}]
+        self.assertTrue(self.api.send(
+            configs.RIL_USERNAME, configs.RIL_PASSWORD, update_title=data))
+
+    def test_send_update_tags(self):
+        data = [{"url": "http://google.com",
+                 "tags": "comma,seperated,list"},
+                {"url": "http://ideashower.com",
+                 "tags": "ideas,developer,nate weiner"}]
+        self.assertTrue(self.api.send(
+            configs.RIL_USERNAME, configs.RIL_PASSWORD, update_tags=data))
+
+
 if __name__ == '__main__':
     logging.basicConfig(level=logging.DEBUG, filename='test.log')