diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-18 10:35:25 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-18 10:35:25 +0000 |
commit | e7a29380292902eae4799b2658507b3cfffb9cec (patch) | |
tree | 99a7cd3c7d720ef73f998c2756be1fef77ff0ee1 /actionservice/examples/metaWeblog | |
parent | e39bf105941133d3d6699c52c18dbd3b9aa0bf5c (diff) | |
download | rails-e7a29380292902eae4799b2658507b3cfffb9cec.tar.gz rails-e7a29380292902eae4799b2658507b3cfffb9cec.tar.bz2 rails-e7a29380292902eae4799b2658507b3cfffb9cec.zip |
Added Action Service to the repository
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@658 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionservice/examples/metaWeblog')
-rw-r--r-- | actionservice/examples/metaWeblog/README | 28 | ||||
-rw-r--r-- | actionservice/examples/metaWeblog/blog_controller.rb | 121 |
2 files changed, 149 insertions, 0 deletions
diff --git a/actionservice/examples/metaWeblog/README b/actionservice/examples/metaWeblog/README new file mode 100644 index 0000000000..f8a56d7018 --- /dev/null +++ b/actionservice/examples/metaWeblog/README @@ -0,0 +1,28 @@ += metaWeblog example + + +This example shows how one might begin to go about adding metaWeblog +(http://www.xmlrpc.com/metaWeblogApi) API support to a Rails-based +blogging application. + + += Running + + 1. Ensure you have the 'actionservice' Gem installed. You can generate it using + this command: + + $ rake package + + + 2. Edit config/environment.rb, and add the following line after the rest of the + require_gem statements: + + require_gem 'actionservice' + + + 3. Copy blog_controller.rb to "app/controllers" in a Rails project. + + + 4. Fire up a desktop blogging application (such as BloGTK on Linux), + point it at http://localhost:3000/blog/api, and try creating or + editing blog posts. diff --git a/actionservice/examples/metaWeblog/blog_controller.rb b/actionservice/examples/metaWeblog/blog_controller.rb new file mode 100644 index 0000000000..b23ccb04c6 --- /dev/null +++ b/actionservice/examples/metaWeblog/blog_controller.rb @@ -0,0 +1,121 @@ +# structures as defined by the metaWeblog/blogger +# specifications. +module Blog + class Enclosure < ActionService::Struct + member :url, :string + member :length, :int + member :type, :string + end + + class Source < ActionService::Struct + member :url, :string + member :name, :string + end + + class Post < ActionService::Struct + member :title, :string + member :link, :string + member :description, :string + member :author, :string + member :category, :string + member :comments, :string + member :enclosure, Enclosure + member :guid, :string + member :pubDate, :string + member :source, Source + end + + class Blog < ActionService::Struct + member :url, :string + member :blogid, :string + member :blogName, :string + end +end + +# skeleton metaWeblog API +class MetaWeblogAPI < ActionService::API::Base + inflect_names false + + api_method :newPost, :returns => [:string], :expects => [ + {:blogid=>:string}, + {:username=>:string}, + {:password=>:string}, + {:struct=>Blog::Post}, + {:publish=>:bool}, + ] + + api_method :editPost, :returns => [:bool], :expects => [ + {:postid=>:string}, + {:username=>:string}, + {:password=>:string}, + {:struct=>Blog::Post}, + {:publish=>:bool}, + ] + + api_method :getPost, :returns => [Blog::Post], :expects => [ + {:postid=>:string}, + {:username=>:string}, + {:password=>:string}, + ] + + api_method :getUsersBlogs, :returns => [[Blog::Blog]], :expects => [ + {:appkey=>:string}, + {:username=>:string}, + {:password=>:string}, + ] + + api_method :getRecentPosts, :returns => [[Blog::Post]], :expects => [ + {:blogid=>:string}, + {:username=>:string}, + {:password=>:string}, + {:numberOfPosts=>:int}, + ] +end + +class BlogController < ApplicationController + service_api MetaWeblogAPI + + def initialize + @postid = 0 + end + + def newPost + $stderr.puts 'Creating post: username=%s password=%s struct=%s' % [ + @params['username'], + @params['password'], + @params['struct'].inspect + ] + (@postid += 1).to_s + end + + def editPost + $stderr.puts 'Editing post: username=%s password=%s struct=%s' % [ + @params['username'], + @params['password'], + @params['struct'].inspect + ] + true + end + + def getUsersBlogs + $stderr.puts "Returning user %s's blogs" % @params['username'] + blog = Blog::Blog.new + blog.url = 'http://blog.xeraph.org' + blog.blogid = 'sttm' + blog.blogName = 'slave to the machine' + [blog] + end + + def getRecentPosts + $stderr.puts "Returning recent posts (%d requested)" % @params['numberOfPosts'] + post1 = Blog::Post.new + post1.title = 'first post!' + post1.link = 'http://blog.xeraph.org/testOne.html' + post1.description = 'this is the first post' + post2 = Blog::Post.new + post2.title = 'second post!' + post2.link = 'http://blog.xeraph.org/testTwo.html' + post2.description = 'this is the second post' + [post1, post2] + end +end |