1515# limitations under the License.
1616
1717
18- """Contains a client to communicate with the Blogger servers."""
18+ """Contains a client to communicate with the Blogger servers.
19+
20+ For documentation on the Blogger API, see:
21+ http://code.google.com/apis/blogger/
22+ """
1923
2024
2125__author__ = 'j.s@google.com (Jeff Scudder)'
2226
2327
2428import gdata .client
25- import gdata .data .blogger
29+ import gdata .blogger .data
30+ import atom .data
2631
2732
2833# List user's blogs, takes a user ID, or 'default'.
3641# Takes a blog ID.
3742BLOG_ARCHIVE_URL = 'http://www.blogger.com/feeds/%s/archive/full'
3843
44+
3945class BloggerClient (gdata .client .GDClient ):
4046 api_version = '2'
4147 auth_serice = 'blogger'
@@ -46,3 +52,86 @@ def get_blogs(self, user_id='default', auth_token=None,
4652 return self .get_feed (BLOGS_URL % user_id , auth_token = auth_token ,
4753 desired_class = desired_class , ** kwargs )
4854
55+ GetBlogs = get_blogs
56+
57+ def get_posts (self , blog_id , auth_token = None ,
58+ desired_class = gdata .blogger .data .BlogPostFeed , query = None ,
59+ ** kwargs ):
60+ return self .get_feed (BLOG_POST_URL % blog_id , auth_token = auth_token ,
61+ desired_class = desired_class , query = query , ** kwargs )
62+
63+ GetPosts = get_posts
64+
65+ def get_post_comments (self , blog_id , post_id , auth_token = None ,
66+ desired_class = gdata .blogger .data .CommentFeed ,
67+ query = None , ** kwargs ):
68+ return self .get_feed (BLOG_POST_COMMENTS_URL % (blog_id , post_id ),
69+ auth_token = auth_token , desired_class = desired_class ,
70+ query = query , ** kwargs )
71+
72+ GetPostComments = get_post_comments
73+
74+ def get_blog_comments (self , blog_id , auth_token = None ,
75+ desired_class = gdata .blogger .data .CommentFeed ,
76+ query = None , ** kwargs ):
77+ return self .get_feed (BLOG_COMMENTS_URL % blog_id , auth_token = auth_token ,
78+ desired_class = desired_class , query = query , ** kwargs )
79+
80+ GetBlogComments = get_blog_comments
81+
82+ def get_blog_archive (self , blog_id , auth_token = None , ** kwargs ):
83+ return self .get_feed (BLOG_ARCHIVE_URL % blog_id , auth_token = auth_token ,
84+ ** kwargs )
85+
86+ GetBlogArchive = get_blog_archive
87+
88+ def add_post (self , blog_id , title , body , labels = None , draft = False ,
89+ auth_token = None , title_type = 'text' , body_type = 'html' , ** kwargs ):
90+ # Construct an atom Entry for the blog post to be sent to the server.
91+ new_entry = gdata .blogger .data .BlogPost (
92+ title = atom .data .Title (text = title , type = title_type ),
93+ content = atom .data .Content (text = body , type = body_type ))
94+ if labels :
95+ for label in labels :
96+ new_entry .add_label (label )
97+ if draft :
98+ new_entry .control = atom .data .Control (draft = atom .data .Draft (text = 'yes' ))
99+ print 'here is your new post:'
100+ print str (new_entry )
101+ return self .post (new_entry , BLOG_POST_URL % blog_id , auth_token = auth_token , ** kwargs )
102+
103+ AddPost = add_post
104+
105+ def add_comment (self , blog_id , post_id , title , body , auth_token = None ,
106+ title_type = 'text' , body_type = 'html' , ** kwargs ):
107+ new_entry = gdata .blogger .data .Comment (
108+ title = atom .data .Title (text = title , type = title_type ),
109+ content = atom .data .Content (text = body , type = body_type ))
110+ return self .post (new_entry , BLOG_POST_COMMENTS_URL % (blog_id , post_id ),
111+ auth_token = auth_token , ** kwargs )
112+
113+ AddComment = add_comment
114+
115+ def update (self , entry , auth_token = None , ** kwargs ):
116+ # The Blogger API does not currently support ETags, so for now remove
117+ # the ETag before performing an update.
118+ old_etag = entry .etag
119+ entry .etag = None
120+ response = gdata .client .GDClient .update (self , entry ,
121+ auth_token = auth_token , ** kwargs )
122+ entry .etag = old_etag
123+ return response
124+
125+ Update = update
126+
127+ def delete (self , entry , auth_token = None , ** kwargs ):
128+ # The Blogger API does not currently support ETags, so for now remove
129+ # the ETag before performing a delete.
130+ old_etag = entry .etag
131+ entry .etag = None
132+ response = gdata .client .GDClient .delete (self , entry ,
133+ auth_token = auth_token , ** kwargs )
134+ entry .etag = old_etag
135+ return response
136+
137+ Delete = delete
0 commit comments