Commits

makoto tsuyuki committed 869d4f3

update api doesn't work. discard update method.

  • Participants
  • Parent commits a045f84

Comments (0)

Files changed (2)

 
 import urllib
 import httplib
-import simplejson
+try :
+  import simplejson as json
+except ImportError:
+  import json
 from base64 import b64encode
 
-DEBUG = True
-
 def parametalize(params_candidate={}) :
   if params_candidate.has_key('self') :
     del params_candidate['self']
   """
   Requirements
   =======================
-  * `simplejson`_
+  * `simplejson`_ if your python < 2.5
   * `pit`_ **optional**. See diigotest.py. You might love it ;)
 
   .. _`simplejson`: http://pypi.python.org/pypi?:action=display&name=simplejson
   Notes
   =======================
   You might get 503 Error, because of Diigo's API limit.
+  
+  v.0.2
+  ^^^^^^^^^^^^^^^^^^
+  **Update Bookmark** is deprecated and raise DeprecationWarning.
 
   Usage
   =======================
 
     * url
 
-  Update Bookmark
-  --------------------
-  ::
-
-    >>> result = api.bookmark_update(title='', description='',url='', shared='yes', tags='')
-    >>> print result['message']
-    updated 1 bookmark
-
-  * required arguments
-
-    * url
-
   Delete Bookmark
   --------------------
   ::
     * url
 
   """
-  user = ''
-  password = ''
-  server = 'api2.diigo.com:80'
+  server = 'secure.diigo.com:443'
   
-  def __init__(self, user='', password='') :
+  def __init__(self, user='', password='', debug=False) :
     self.user = user
     self.password = password
+    self.debug = debug
     if not self.user:
       raise ValueError, 'You must pass your username and password.'
     self.headers = {"Content-type": "application/x-www-form-urlencoded",
 
   def bookmark_update(self, title='', description='',url='',
                          shared='yes', tags=''):
-    if url == None or len(url) == 0:
-      raise ValueError, 'url must specified'
-    return self._handle_bookmark(parametalize(locals()), 'PUT')
+    raise DeprecationWarning('''Doese this API work?''')
+    # if url == None or len(url) == 0:
+    #   raise ValueError, 'url must specified'
+    # return self._handle_bookmark(parametalize(locals()), 'POST')
 
   def bookmark_delete(self, url=''):
     if url == None or len(url) == 0:
     return self._handle_bookmark(parametalize(locals()), 'DELETE')
   
   def _handle_bookmark(self, param={}, method='GET') :
-    if DEBUG :
+    if self.debug :
       print 'DEBUG: %s._handle_bookmark->%s' % (self.__class__, method)
-      print '     :%s' % (param)
+      print ' ARGS:%s' % (param)
       print ''
     params = urllib.urlencode(param)
-    conn = httplib.HTTPConnection(self.server)
+    conn = httplib.HTTPSConnection(self.server)
     try:
       if method == 'GET':
-        conn.request(method, "/bookmarks?%s" % params, {}, self.headers)
+        conn.request(method, "/api/v2/bookmarks?%s" % params, "", self.headers)
         response = conn.getresponse()
-        bookmarks = [DiigoBookmark(d) for d in simplejson.load(response)]
+        bookmarks = [DiigoBookmark(d) for d in json.load(response)]
         return bookmarks
       else :
-        conn.request(method, "/bookmarks" , params, self.headers)
+        conn.request(method, "/api/v2/bookmarks" , params, self.headers)
         response = conn.getresponse()
         if response.status >= 400:
-          if DEBUG:
-            print response.read()
+          if self.debug:
+            print "ERROR: STATUS:%d\n       %s" % (response.status, response.read())
           raise PyDiigoError(response.status,
                             '',
                             method,
                             params)
-        result = simplejson.load(response)
-        if DEBUG:
+        result = json.load(response)
+        if self.debug:
             print result
         return result
     finally:
                                                   self.message, self.method, self.param)
 
 
-VERSION = '0.1'
+VERSION = '0.2'
 AUTHOR = 'makoto tsuyuki'
 AUTHOR_EMAIL = 'mtsuyuki_at_gmail_dot_com'
 PROJECT_URL = 'http://www.tsuyukimakoto.com/project/pydiigo/'

File pydiigotest.py

     diigo_password = None
     if not diigo_user:
       try :
-        # http://pypi.python.org/pypi/pit/0.2
+        # http://pypi.python.org/pypi/pit/0.3
         # http://www.youtube.com/watch?v=VeqYJXCm3Dw&eurl=http://d.hatena.ne.jp/a2c/20081016/1224097042&feature=player_embedded
         from pit import Pit
         diigo_config = Pit.get('diigo.com',{'require' : {'username':'Your diigo username','password':'Your diigo password'}})
         diigo_user, diigo_password = diigo_config['username'],diigo_config['password']
       except ImportError: pass
-    self.api = DiigoApi(diigo_user, diigo_password)
+    self.api = DiigoApi(diigo_user, diigo_password, debug=True)
     try:
       self.api.bookmark_delete(url='http://www.tsuyukimakoto.com/')
     except PyDiigoError:pass
 
   def test_crud(self):
-    time.sleep(60)
-    result = self.api.bookmark_add(title='tsuyukimakoto.com',url='http://www.tsuyukimakoto.com/', tags='pydiigotest')
-    self.assert_(result['message'] == 'added 1 bookmarks')
-    time.sleep(60)
+    result = self.api.bookmark_add(title='tsuyukimakoto',url='http://www.tsuyukimakoto.com/', tags='pydiigotest')
+    self.assert_(result['message'] == 'Saved 1 bookmark(s)')
     bookmark = self.api.bookmarks_find(url='http://www.tsuyukimakoto.com', users='tsuyukimakoto')[0]
-    self.assert_(bookmark.title == 'tsuyukimakoto.com')
+    self.assert_(bookmark.title == 'tsuyukimakoto')
     self.assert_(bookmark.url == 'http://www.tsuyukimakoto.com')
     self.assert_(bookmark.tags == 'pydiigotest')
-    time.sleep(60)
+    time.sleep(5)
     bookmark = self.api.bookmarks_find(tags='pydiigotest', users='tsuyukimakoto')[0]
     self.assert_(bookmark.tags == 'pydiigotest')
-    time.sleep(60)
-    result = self.api.bookmark_update(title='was spam-ish', url='http://www.tsuyukimakoto.com/', tags='test,django,python')
-    self.assert_(result['message'] == 'updated 1 bookmarks')
-    time.sleep(60)
-    bookmark = self.api.bookmarks_find(url='http://www.tsuyukimakoto.com/', users='tsuyukimakoto')[0]
-    self.assert_(bookmark.title == 'was spam-ish')
-    self.assert_(bookmark.url == 'http://www.tsuyukimakoto.com')
-    self.assert_(bookmark.tags == 'test,django,python')
-    time.sleep(60)
+    try:
+      result = self.api.bookmark_update(title='testtest', url='http://www.tsuyukimakoto.com/', tags='test,django,python')
+      fail()
+    except DeprecationWarning:
+      pass
     result = self.api.bookmark_delete(url='http://www.tsuyukimakoto.com/')
-    self.assert_(result['message'] == 'deleted 1 bookmarks')
-    time.sleep(60)
+    self.assert_(result['message'] == 'deleted 1 bookmark(s)')
     bookmarks = self.api.bookmarks_find(tags='pydiigotest', users='tsuyukimakoto')
-    print 'length:%s' % len(bookmarks)
-    for b in bookmarks:
-        print b
     self.assert_(len(bookmarks) == 0)
 
 if __name__ == '__main__':