forked from technoweenie/mephisto
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement movable type xml-rpc API [Moritz Angermann]
git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2402 567b1171-46fb-0310-a4c9-b4bef9110e78
- Loading branch information
technoweenie
committed
Oct 27, 2006
1 parent
2163e57
commit a18ee2e
Showing
9 changed files
with
282 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,88 @@ | ||
class MovableTypeApi < ActionWebService::API::Base | ||
inflect_names false | ||
|
||
# Movable Type Programatic interface | ||
# see: <http://www.movabletype.org/mt-static/docs/mtmanual_programmatic.html> | ||
# supportedTextFilters has already been there! | ||
# - Moritz Angermann | ||
# | ||
# mt.getRecentPostTitles | ||
# Description: Returns a bandwidth-friendly list of the most recent posts in the system. | ||
# Parameters: String blogid, String username, String password, int numberOfPosts | ||
# Return value: on success, array of structs containing ISO.8601 dateCreated, String userid, String postid, String title; on failure, fault | ||
# Notes: dateCreated is in the timezone of the weblog blogid | ||
# Reference: <http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtgetrecentposttitles.html> | ||
|
||
#api_method :getRecentPostTitles, | ||
# :expects => [ {:blogid => :string}, {:username => :string}, {:password => :string}, {:numberOfPosts => :int} ], | ||
# :returns => [[MovableTypeStructs::Post]] | ||
|
||
# mt.getCategoryList | ||
# Description: Returns a list of all categories defined in the weblog. | ||
# Parameters: String blogid, String username, String password | ||
# Return value: on success, an array of structs containing String categoryId and String categoryName; on failure, fault. | ||
# Reference: <http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtgetcategorylist.html> | ||
api_method :getCategoryList, | ||
:expects => [ {:blogid => :string}, {:username => :string}, {:password => :string} ], | ||
:returns => [[MovableTypeStructs::Category]] | ||
|
||
# mt.getPostCategories | ||
# Description: Returns a list of all categories to which the post is assigned. | ||
# Parameters: String postid, String username, String password | ||
# Return value: on success, an array of structs containing String categoryName, String categoryId, and boolean isPrimary; on failure, fault. | ||
# Notes: isPrimary denotes whether a category is the post's primary category. | ||
# Reference: <http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtgetpostcategories.html> | ||
api_method :getPostCategories, | ||
:expects => [ {:postid => :string}, {:username => :string}, {:password => :string} ], | ||
:returns => [[MovableTypeStructs::Category]] | ||
|
||
# mt.setPostCategories | ||
# Description: Sets the categories for a post. | ||
# Parameters: String postid, String username, String password, array categories | ||
# Return value: on success, boolean true value; on failure, fault | ||
# Notes: the array categories is an array of structs containing String categoryId and boolean isPrimary. Using isPrimary to set the primary category is optional--in the absence of this flag, the first struct in the array will be assigned the primary category for the post. | ||
# Reference: <http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtsetpostcategories.html> | ||
api_method :setPostCategories, | ||
:expects => [ {:postid => :string}, {:username => :string}, {:password => :string}, {:categories => [MovableTypeStructs::PostCategory]} ], | ||
:returns => [:bool] | ||
|
||
# mt.supportedMethods | ||
# Description: Retrieve information about the XML-RPC methods supported by the server. | ||
# Parameters: none | ||
# Return value: an array of method names supported by the server. | ||
# Reference: <http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtsupportedMethods.html> | ||
|
||
api_method :supportedMethods, | ||
:expects => [], | ||
:returns => [[:string]] | ||
|
||
# mt.supportedTextFilters | ||
# Description: Retrieve information about the text formatting plugins supported by the server. | ||
# Parameters: none | ||
# Return value: an array of structs containing String key and String label. key is the unique string identifying a text formatting plugin, and label is the readable description to be displayed to a user. key is the value that should be passed in the mt_convert_breaks parameter to newPost and editPost. | ||
# Reference: <http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtsupportedtextfilters.html> | ||
|
||
api_method :supportedTextFilters, | ||
:expects => [], | ||
:returns => [[MovableTypeStructs::TextFilter]] | ||
end | ||
|
||
# mt.getTrackbackPings | ||
# Description: Retrieve the list of TrackBack pings posted to a particular entry. This could be used to programmatically retrieve the list of pings for a particular entry, then iterate through each of those pings doing the same, until one has built up a graph of the web of entries referencing one another on a particular topic. | ||
# Parameters: String postid | ||
# Return value: an array of structs containing String pingTitle (the title of the entry sent in the ping), String pingURL (the URL of the entry), and String pingIP (the IP address of the host that sent the ping). | ||
# Reference: <http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtgettrackbackpings.html> | ||
|
||
# api_method :getTrackbackPings, | ||
# :expects => [ {:postid => :string} ], | ||
# :returns => [[MovableTypeStructs::Trackback]] | ||
|
||
# mt.publishPost | ||
# Description: Publish (rebuild) all of the static files related to an entry from your weblog. Equivalent to saving an entry in the system (but without the ping). | ||
# Parameters: String postid, String username, String password | ||
# Returns value: on success, boolean true value; on failure, fault | ||
# Reference: <http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtpublishpost.html> | ||
|
||
#api_method :publishPost, | ||
# :expects => [ {:postid => :string}, {:username => :string}, {:password => :string} ], | ||
# :returns => [:bool] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,44 @@ | ||
class MovableTypeService < XmlRpcService | ||
web_service_api MovableTypeApi | ||
before_invocation :authenticate, :except => [:supportedMethods, :supportedTextFilters] | ||
|
||
#def getRecentPostTitles(blogid, username, password, numberOfPosts) | ||
# # FIXME not implemented | ||
#end | ||
|
||
def getCategoryList(blogid, username, password) | ||
site.sections.find(:all, :order => 'id ASC').collect { |c| MovableTypeStructs::Category.new(:categoryId => c.id, :categoryName => c.name) } | ||
end | ||
|
||
def getPostCategories(postid, username, password) | ||
article = @user.articles.find(postid) | ||
article.sections.collect { |c| MovableTypeStructs::Category.new(:categoryId => c.id, :categoryName => c.name) } | ||
end | ||
|
||
def setPostCategories(postid, username, password, categories) | ||
article = @user.articles.find(postid) | ||
article.section_ids= categories.collect { |c| c.categoryId } | ||
article.save! | ||
true | ||
end | ||
|
||
def supportedMethods | ||
MetaWeblogService.public_instance_methods(false).collect { |m| "metaWeblog.{#m}" } \ | ||
+ MovableTypeService.public_instance_methods(false).collect { |m| "mt.{#m}" } | ||
end | ||
|
||
def supportedTextFilters | ||
FilteredColumn.filters.collect { |(key, filter)| MovableTypeStructs::TextFilter.new(:key => key, :label => filter.filter_name) } | ||
end | ||
end | ||
|
||
# def getTrackbackPings, | ||
# ... | ||
# end | ||
|
||
#def publishPost(postid, username, password) | ||
# article = @user.articles.find(postid) | ||
# #article. hmmm now what? | ||
# true | ||
#end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module MovableTypeStructs | ||
class Category < ActionWebService::Struct | ||
member :categoryId, :string | ||
member :categoryName, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module MovableTypeStructs | ||
class Post < ActionWebService::Struct | ||
member :dateCreated, :time #ISO.8601 | ||
member :userid, :string | ||
member :postid, :string | ||
member :title, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module MovableTypeStructs | ||
class PostCategory < ActionWebService::Struct | ||
member :categoryId, :string | ||
member :categoryName, :string | ||
member :isPrimary, :bool | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module MovableTypeStructs | ||
class Trackback < ActionWebService::Struct | ||
member :pingTitle, :string | ||
member :pingURL, :string | ||
member :pingIP, :string | ||
end | ||
end |
Oops, something went wrong.