Skip to content

Commit

Permalink
Went through most of the doc strings, improved the quality where need…
Browse files Browse the repository at this point in the history
…ed, and made them more consistent across the entire library.
  • Loading branch information
thomasw committed Apr 30, 2010
1 parent c0a62f9 commit 3ce9569
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 63 deletions.
13 changes: 7 additions & 6 deletions pyposterous/cursor.py
Expand Up @@ -4,13 +4,14 @@ class Cursor(object):
"""Allows for iterating over multiple pages of Posterous results.
Keyword arguments:
method -- The method with paginated results
num_posts -- (Optional) The number of posts to request from posterous per page
start_page -- (Optional) The page to start on.
limit -- (Optional) Only return LIMIT results.
parameters -- (Optional) parameters you'd like to pass to the specified method
"""
* method -- The method with paginated results
* num_posts -- (Optional) The number of posts to request from posterous per page
* start_page -- (Optional) The page to start on.
* limit -- (Optional) Only return LIMIT results.
* parameters -- (Optional) parameters you'd like to pass to the specified method
"""
def __init__(self, method, num_posts=20, start_page=1, limit=0, parameters={}):
# pagination will be equal to true if this method supports it
if not getattr(method, 'pagination', False):
Expand Down
109 changes: 61 additions & 48 deletions pyposterous/idl.py
Expand Up @@ -11,8 +11,9 @@
'parameters':(),
'auth_required':True,
'returns': ['force_list',],
'__doc__':"""Returns a list of all sites owned and authored by
this user.
'__doc__':"""Returns a list of site objects representing the sites
owned and authored by this user.
"""
},
'read_posts': {
Expand All @@ -25,15 +26,16 @@
('tag', (basestring, Tag), ['optional'])],
'auth_required':False,
'returns': ['force_list',],
'__doc__':"""Returns a list of posts based on the specified
'__doc__':"""Returns a list of post objects based on the specified
parameters.
Keyword arguments:
site_id -- Optional. Id of the site to read from
hostname -- Optional. Subdomain of the site to read from
num_posts -- Optional. How many posts you want. Default is 10, max is 50
page -- Optional. What 'page' you want (based on num_posts). Default is 1
tag -- Optional
* site_id -- Optional. Id of the site to read from
* hostname -- Optional. Subdomain of the site to read from
* num_posts -- Optional. How many posts you want. Default is 10, max is 50
* page -- Optional. What 'page' you want (based on num_posts). Default is 1
* tag -- Optional
"""
},
Expand All @@ -44,12 +46,13 @@
('hostname', basestring, ['optional'])],
'auth_required':False,
'returns': ['force_list',],
'__doc__':"""Returns a list of tags based on the specified
'__doc__':"""Returns a list of tags objects on the specified
site.
Keyword arguments:
site_id -- Optional. Id of the site to read from
hostname -- Optional. Subdomain of the site to read from
* site_id -- Optional. Id of the site to read from
* hostname -- Optional. Subdomain of the site to read from
"""
},
Expand All @@ -68,19 +71,21 @@
('sourceLink', basestring, ['optional']),
],
'auth_required':True,
'__doc__':"""Creates a new post.
'__doc__':"""Creates a new post. Returns a post object representing
that post.
Keyword arguments:
site_id -- Optional. Id of the site to post to. If not supplied, posts to the user's default site
media -- Optional. File object for single file or a list of file objects.
title -- Optional. Title of post
body -- Optional. Body of post
autopost -- Optional. 0 or 1.
private -- Optional. 0 or 1.
date -- Optional. In GMT. Any parsable format. Cannot be in the future.
tags -- Optional. Comma separate tags
source -- Optional. The name of your application or website
sourceLink -- Optional. Link to your application or website
* site_id -- Optional. Id of the site to post to. If not supplied, posts to the user's default site
* media -- Optional. File object for single file or a list of file objects.
* title -- Optional. Title of post
* body -- Optional. Body of post
* autopost -- Optional. 0 or 1.
* private -- Optional. 0 or 1.
* date -- Optional. In GMT. Any parsable format. Cannot be in the future.
* tags -- Optional. Comma separate tags
* source -- Optional. The name of your application or website
* sourceLink -- Optional. Link to your application or website
"""
},
Expand All @@ -93,13 +98,15 @@
('body', basestring, ['optional']),
],
'auth_required':True,
'__doc__':"""Updates an existing post.
'__doc__':"""Updates an existing post. Returns a post object for
the updated post.
Keyword arguments:
post_id -- Id of the post to update.
media -- Optional. File object for single file or a list of file objects. Will append to post.
title -- Optional. Title of post. Will update post if present.
body -- Optional. Body of post. Will update post if present.
* post_id -- Id of the post to update.
* media -- Optional. File object for single file or a list of file objects. Will append to post.
* title -- Optional. Title of post. Will update post if present.
* body -- Optional. Body of post. Will update post if present.
"""
},
Expand All @@ -113,14 +120,16 @@
('date', datetime, ['optional']),
],
'auth_required':True,
'__doc__':"""Adds a comment to the specified post.
'__doc__':"""Adds a comment to the specified post. Returns a comment
object with the parent post as an attribute.
Keyword arguments:
post_id -- The post id to comment on
comment -- The comment body
name -- Optional. The name to use
email -- Optional. The email address to use
date -- Optional. In GMT. Any parsable format. Cannot be in the future.
* post_id -- The post id to comment on
* comment -- The comment body
* name -- Optional. The name to use
* email -- Optional. The email address to use
* date -- Optional. In GMT. Any parsable format. Cannot be in the future.
"""
},
Expand Down Expand Up @@ -157,15 +166,17 @@
'auth_required':False,
'returns':['force_primative',],
'__doc__':"""Post text and files on Posterous using Twitter credentials.
Returns a dictionary containing mediaid and mediaurl.
Keyword arguments:
username -- Twitter username
password -- Twitter password
media -- Optional. File object for single file or a list of file objects.
message -- Optional. Title of post
body -- Optional. Body of post
source -- Optional. The name of your application or website
sourceLink -- Optional. Link to your application or website
* username -- Twitter username
* password -- Twitter password
* media -- Optional. File object for single file or a list of file objects.
* message -- Optional. Title of post
* body -- Optional. Body of post
* source -- Optional. The name of your application or website
* sourceLink -- Optional. Link to your application or website
"""
},
Expand All @@ -183,16 +194,18 @@
'auth_required':False,
'returns':['force_primative',],
'__doc__':"""Post text and files on Posterous using Twitter
credentials and then tweet a message with a link to the post.
credentials and then tweet a message with a link to the post. Returns
a dictionary containing mediaid and mediaurl.
Keyword arguments:
username -- Twitter username
password -- Twitter password
media -- Optional. File object for single file or a list of file objects.
message -- Optional. Title of post
body -- Optional. Body of post
source -- Optional. The name of your application or website
sourceLink -- Optional. Link to your application or website
* username -- Twitter username
* password -- Twitter password
* media -- Optional. File object for single file or a list of file objects.
* message -- Optional. Title of post
* body -- Optional. Body of post
* source -- Optional. The name of your application or website
* sourceLink -- Optional. Link to your application or website
"""
},
Expand Down
2 changes: 1 addition & 1 deletion pyposterous/methods.py
@@ -1,4 +1,3 @@
import urllib2_file
import urllib2
from datetime import datetime

Expand Down Expand Up @@ -126,6 +125,7 @@ def __clean_and_set_value(self, name, value):
self.args.append((name, value,))

def execute(self):
import urllib2_file
# Anything with TEST in the URL is a test function, not a real API
# call
if 'TEST' in self.url:
Expand Down
44 changes: 36 additions & 8 deletions pyposterous/models.py
Expand Up @@ -11,32 +11,44 @@ def api(self):
class Site(PosterousData):
def get_tags(self):
"""Returns the tags for this site using self.id first and self.hostname
second. If neither is specified, a PosterousError is raised."""
second. If neither is specified, a PosterousError is raised.
"""
try:
return self.api().get_tags(site_id=self.id)
except AttributeError:
try:
return self.api().get_tags(hostname=self.hostname)
except AttributeError:
raise PyposterousError('No ID or hostname has been specified for this site object.')
raise PyposterousError('No ID or hostname attributes have been defined for this site instance.')

def read_posts(self, num_posts=None, page=None, tag=None):
"""Returns a list of posts for this site using self.id."""
"""Returns a list of posts for this site using self.id or self.hostname.
If niether is specified a PyposterousError is raised.
See pyposterous.API.read_posts for parameter documentation.
"""
try:
return self.api().read_posts(site_id=self.id, num_posts=num_posts, page=page, tag=tag)
except AttributeError:
try:
return self.api().read_posts(hostname=self.hostname, num_posts=num_posts, page=page, tag=tag)
except AttributeError:
raise PyposterousError('No ID or hostname has been specified for this site object.')
raise PyposterousError('No ID or hostname attributes have been defined for this site instance.')


def new_post(self, media=None, title=None, body=None, autopost=None, private=None, date=None, tags=None, source=None, sourceLink=None):
"""Posts a new blog post to this site using self.id"""
"""Posts a new blog post to this site using self.id. If self.id isn't
specified, a PyposterousError is raised.
See pyposterous.API.new_post for parameter documentation.
"""
try:
return self.api().new_post(self.id, media, title, body, autopost, private, date, tags, source, sourceLink)
except AttributeError:
raise PyposterousError('No ID has been specified for this site object.')
raise PyposterousError('No id attribute defined for this site instance.')

class Tag(PosterousData):
def __str__(self):
Expand All @@ -48,15 +60,17 @@ def __str__(self):
class Post(PosterousData):
def update_post(self, media=None):
"""Updates the post this object represents based on the values of
post_id, title, and body.
self.id, self.title, and self.body. If self.id isn't specified, a
PyposterousError is raised.
media -- a file or a list of files to APPEND to the existing post.
"""
kwargs = {}
try:
kwargs['post_id'] = self.id
except:
raise PyposterousError('No post_id specified for this Post object.')
raise PyposterousError('No id attribute defined for this post instance.')

try:
kwargs['title'] = self.title
Expand All @@ -73,7 +87,21 @@ def update_post(self, media=None):
return self.api().update_post(**kwargs)

def new_comment(self, body, name=None, email=None, date=None):
"""Posts a new comment to this post using the value of self.id. If self.id
isn't specified, a PyposterousError is raised.
This method is compatible with the Cursor class.
See pyposterous.API.new_comment for parameter documentation.
"""
try:
self.id
except AttributeError:
raise PyposterousError('No id attribute defined for this post instance.')

return self.api().new_comment(self.id, body, name, email, date)
new_comment.pagination=True

class Comment(PosterousData):
pass
Expand Down

0 comments on commit 3ce9569

Please sign in to comment.