Module api :: Class Api
[hide private]
[frames] | no frames]

Class Api
source code

object --+
         |
        Api

The base class providing access to the web api functionality via method calls.

usage:
>>> import api as connotea
>>> api = connotea.Api('user', 'password')
>>> bookmarks = api.query('bookmarks', user='user')
>>> posts = api.query(uri='http://www.dlib.org/dlib/may06/apps/05apps.html')
>>> posts[0].bookmark.citation.authors
[u'Ann Apps', u'Ross MacIntyre']

>>> newPost = api.add('http://www.zim.mpg.de/',('zim','heinz nixdorf'))
>>> newPost.description
>>> newPost.description = 'new description'
>>> newPost = api.edit(newPost, comment='new comment')
>>> newPost.description
u'new description'

>>> newPost.comments.pop().entry
u'new comment'

>>> api.remove(newPost)


Instance Methods [hide private]
  __init__(self, user, password, authenticate=False, debug=False)
  _request(self, url, data=None, errorHandler=None)
generic connotea WebAPI request
  add(self, uri, tags, title=None, description=None, mywork=False, private=False, comment=None)
Quote from the web api specification:
  edit(self, post, comment=None)
Updates a Post.
  getBookmark(self, post)
get a complete Bookmark object associated with a Post instance.
  getTags(self, object)
return a list of Tag instances for object's list of tag names
  query(self, what='posts', user=None, tag=None, date=None, uri=None, uriMd5=None, num=None, start=None, q=None)
query URLs are constructed as follows.
  remove(self, what)
Removes a post specified as Post instance or uri.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__


Class Variables [hide private]
AUTH_HOST  
AUTH_REALM  
BASE_URL  

Inherited from object: __class__


Method Details [hide private]

__init__(self, user, password, authenticate=False, debug=False)
(Constructor)

source code 
Parameters:
  • user - username for a connotea account
  • password - password for the connotea user
  • authenticate - flag signalling whether to try authentication on init
  • debug - flag signalling debug mode
Overrides: object.__init__

_request(self, url, data=None, errorHandler=None)

source code 
generic connotea WebAPI request
Parameters:
  • url - the path component of the request url to be attached to self.BASE_URL
  • data - a dictionary or sequence of pairs to create the body of the request. If this parameter is not None, the request will be using the HTTP POST method.
  • errorHandler - a urllib2.HTTPDefaultErrorHandler subclass

add(self, uri, tags, title=None, description=None, mywork=False, private=False, comment=None)

source code 
Quote from the web api specification:
 New posts can be created by submitting an HTTP POST request to
 
 http://www.connotea.org/data/add

 The body of the POST should be simply an HTML form-style set of key=value URL-escaped pairs.

 The fields available are listed below. The uri and tags fields are required, alll other fields are optional.

  - uri => the URL for the bookmark you're creating
  - tags => a string representing the tags. Individual tags should be comma- or space-separated, and multi-word tags must be enclosed in quotes ("")
  - usertitle => the title to use for the post
  - description => description of the bookmark
  - mywork => 0 or 1. If 1, it means you are claiming authorship (or co-authorship) of the work being bookmarked
  - private => 0 or 1. 0 means the post is shared with all, 1 means it is kept private to the user.
  - comment => HTML for a comment. Note that newlines will be automatically converted to <br/>.
Parameters:
  • uri - see above
  • tags - either a correctly formatted string as described above or a list or tuple of arbitrary strings, specifying the single tags. note that double quotes will be stripped from these strings.

edit(self, post, comment=None)

source code 
Updates a Post.
Parameters:
  • post - a Post instance
  • comment - a string
Returns:
a Post instance representing the updated post, i.e. post will not be updated in place!

getBookmark(self, post)

source code 
get a complete Bookmark object associated with a Post instance.

getTags(self, object)

source code 
return a list of Tag instances for object's list of tag names

query(self, what='posts', user=None, tag=None, date=None, uri=None, uriMd5=None, num=None, start=None, q=None)

source code 

query URLs are constructed as follows.

URL path compoents:
  • /bookmarks or /tags or '' (empty string, which means 'posts')
  • /user/ [username] (optional)
  • /tag/ [tagname] (optional)
  • /date/ [date of form YYYY-MM-DD ] (optional)
  • /uri/ [uri or hash] (optional)
URL query parameters:
  • q= [free text search string]
  • num= [number of results per]
  • start= [result number to start at]

remove(self, what)

source code 
Removes a post specified as Post instance or uri.
Parameters:
  • what - te specification of the post ro remove
Returns:
None on success

Class Variable Details [hide private]

AUTH_HOST

Value:
'http://www.connotea.org'                                              
      

AUTH_REALM

Value:
'Connotea'                                                             
      

BASE_URL

Value:
'http://www.connotea.org/data'