fixed api methods since called methods won't return a result object anymore but throw an exception if something's going wrong
This commit is contained in:
parent
7721b7e5f5
commit
963ad02cdd
1 changed files with 24 additions and 19 deletions
|
@ -49,26 +49,27 @@ function getPost(appkey, postid, username, password) {
|
||||||
* @param publish int, 0=no, 1=yes
|
* @param publish int, 0=no, 1=yes
|
||||||
* @return String representing the ID of the new entry
|
* @return String representing the ID of the new entry
|
||||||
*/
|
*/
|
||||||
function newPost (appkey, blogid, username, password, content, publish) {
|
function newPost(appkey, blogid, username, password, content, publish) {
|
||||||
var usr = root.blogger.getUser(username, password);
|
var usr = root.blogger.getUser(username, password);
|
||||||
var blog = root.blogger.getBlog(blogid.toString());
|
var blog = root.blogger.getBlog(blogid.toString());
|
||||||
if (!blog)
|
if (!blog)
|
||||||
throw("Couldn't find the blog " + blogid);
|
throw("Couldn't find the blog " + blogid);
|
||||||
try {
|
try {
|
||||||
blog.stories.checkAdd(usr, blog.members.getMembershipLevel(usr));
|
blog.stories.checkAdd(usr, blog.members.getMembershipLevel(usr));
|
||||||
} catch (deny) {
|
|
||||||
throw ("You don't have permission to post to this site");
|
|
||||||
}
|
|
||||||
|
|
||||||
var param = new Object();
|
var param = new Object();
|
||||||
param.http_remotehost = "bloggerAPI";
|
param.http_remotehost = "bloggerAPI";
|
||||||
root.blogger.parseBloggerAPIPosting (param, content);
|
root.blogger.parseBloggerAPIPosting (param, content);
|
||||||
param.publish = publish;
|
param.publish = publish;
|
||||||
param.addToFront = true;
|
param.addToFront = true;
|
||||||
var result = blog.stories.evalNewStory(param, usr);
|
var result = blog.stories.evalNewStory(param, usr);
|
||||||
if (result.error)
|
|
||||||
throw(result.message);
|
|
||||||
return result.id;
|
return result.id;
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof DenyException)
|
||||||
|
throw ("You don't have permission to post to this site");
|
||||||
|
else
|
||||||
|
throw(e.toString());
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,7 +84,7 @@ function newPost (appkey, blogid, username, password, content, publish) {
|
||||||
* @param publish int, 0=no, 1=yes
|
* @param publish int, 0=no, 1=yes
|
||||||
* @return Boolean true if successful
|
* @return Boolean true if successful
|
||||||
*/
|
*/
|
||||||
function editPost (appkey, postid, username, password, content, publish) {
|
function editPost(appkey, postid, username, password, content, publish) {
|
||||||
var usr = root.blogger.getUser(username, password);
|
var usr = root.blogger.getUser(username, password);
|
||||||
var entry = root.storiesByID.get(postid.toString());
|
var entry = root.storiesByID.get(postid.toString());
|
||||||
if (!entry)
|
if (!entry)
|
||||||
|
@ -178,11 +179,15 @@ function deletePost(appkey, postid, username, password, publish) {
|
||||||
// check if user is allowed to delete the entry
|
// check if user is allowed to delete the entry
|
||||||
try {
|
try {
|
||||||
entry.checkDelete(usr, entry.site.members.getMembershipLevel(usr));
|
entry.checkDelete(usr, entry.site.members.getMembershipLevel(usr));
|
||||||
} catch (deny) {
|
entry._parent.deleteStory(entry);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof DenyException)
|
||||||
throw ("You're not allowed to delete the entry with id " + postid);
|
throw ("You're not allowed to delete the entry with id " + postid);
|
||||||
|
else
|
||||||
|
throw(e.toString());
|
||||||
}
|
}
|
||||||
var result = entry._parent.deleteStory(entry);
|
return;
|
||||||
return !result.error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -214,7 +219,7 @@ function getUsersBlogs(appkey, username, password) {
|
||||||
param.blogid = blog.alias;
|
param.blogid = blog.alias;
|
||||||
param.blogName = blog.title;
|
param.blogName = blog.title;
|
||||||
param.url = blog.href();
|
param.url = blog.href();
|
||||||
result[result.length] = param;
|
result.push(param);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue