From 4f2f408ba1a7dd976a1ec5061d05ef0439e5f942 Mon Sep 17 00:00:00 2001 From: Leon Breedt Date: Thu, 10 Mar 2005 11:53:29 +0000 Subject: allow 0, 1, '0' or '1' to be cast to the appropriate values for boolean values. update XML-RPC example to work in :layered mode. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@883 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionwebservice/CHANGELOG | 8 ++ actionwebservice/TODO | 5 +- actionwebservice/examples/metaWeblog/README | 11 +- .../examples/metaWeblog/apis/blogger_api.rb | 60 ++++++++++ .../examples/metaWeblog/apis/blogger_service.rb | 34 ++++++ .../examples/metaWeblog/apis/meta_weblog_api.rb | 67 +++++++++++ .../metaWeblog/apis/meta_weblog_service.rb | 48 ++++++++ .../examples/metaWeblog/blog_controller.rb | 127 --------------------- .../metaWeblog/controllers/xmlrpc_controller.rb | 16 +++ .../lib/action_web_service/vendor/ws/types.rb | 3 + actionwebservice/test/ws/types_test.rb | 2 + 11 files changed, 246 insertions(+), 135 deletions(-) create mode 100644 actionwebservice/examples/metaWeblog/apis/blogger_api.rb create mode 100644 actionwebservice/examples/metaWeblog/apis/blogger_service.rb create mode 100644 actionwebservice/examples/metaWeblog/apis/meta_weblog_api.rb create mode 100644 actionwebservice/examples/metaWeblog/apis/meta_weblog_service.rb delete mode 100644 actionwebservice/examples/metaWeblog/blog_controller.rb create mode 100644 actionwebservice/examples/metaWeblog/controllers/xmlrpc_controller.rb (limited to 'actionwebservice') diff --git a/actionwebservice/CHANGELOG b/actionwebservice/CHANGELOG index 0e038b622c..d75d400b91 100644 --- a/actionwebservice/CHANGELOG +++ b/actionwebservice/CHANGELOG @@ -1,3 +1,11 @@ +*0.7.0* (Unreleased) + +* Fix XML-RPC example to use :layered mode, so it works again + +* Support casting '0' or 0 into false, and '1' or 1 into true, when expecting a boolean value + +* Fix that SOAP fault response fault code values were not QName's #804 + *0.6.0* (7th March, 2005) * Add action_controller/test_invoke, used for integrating AWS with the Rails testing infrastructure diff --git a/actionwebservice/TODO b/actionwebservice/TODO index 87d2a62c08..af1d6ff5fc 100644 --- a/actionwebservice/TODO +++ b/actionwebservice/TODO @@ -1,7 +1,6 @@ = 0.7.0 - - WS Test Integration - - WS Scaffolding - - WS Generators + - WS Dynamic Scaffolding + - WS Scaffolding Generators = 0.8.0 - Consumption of WSDL services diff --git a/actionwebservice/examples/metaWeblog/README b/actionwebservice/examples/metaWeblog/README index 0550b06623..f66f56770b 100644 --- a/actionwebservice/examples/metaWeblog/README +++ b/actionwebservice/examples/metaWeblog/README @@ -1,16 +1,17 @@ = 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. +The example APIs are more verbose than you may want to make them, for documentation +reasons. = Running - 1. Copy blog_controller.rb to "app/controllers" in a Rails project. + 1. Copy the "apis" directory and its files into "app" in a Rails project. + 2. Copy the "controllers" directory and its files into "app" in a Rails project - 2. 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. + 3. Fire up a desktop blogging application (such as w.bloggar, MarsEdit, or BloGTK), + point it at http://localhost:3000/xmlrpc/api, and try creating or editing blog posts. diff --git a/actionwebservice/examples/metaWeblog/apis/blogger_api.rb b/actionwebservice/examples/metaWeblog/apis/blogger_api.rb new file mode 100644 index 0000000000..9f85a2391e --- /dev/null +++ b/actionwebservice/examples/metaWeblog/apis/blogger_api.rb @@ -0,0 +1,60 @@ +# +# see the blogger API spec at http://www.blogger.com/developers/api/1_docs/ +# note that the method signatures are subtly different to metaWeblog, they +# are not identical. take care to ensure you handle the different semantics +# properly if you want to support blogger API too, to get maximum compatibility. +# + +module Blog + class Blog < ActionWebService::Struct + member :url, :string + member :blogid, :string + member :blogName, :string + end + + class User < ActionWebService::Struct + member :nickname, :string + member :userid, :string + member :url, :string + member :email, :string + member :lastname, :string + member :firstname, :string + end +end + +# +# blogger +# +class BloggerAPI < ActionWebService::API::Base + inflect_names false + + api_method :newPost, :returns => [:string], :expects => [ + {:appkey=>:string}, + {:blogid=>:string}, + {:username=>:string}, + {:password=>:string}, + {:content=>:string}, + {:publish=>:bool} + ] + + api_method :editPost, :returns => [:bool], :expects => [ + {:appkey=>:string}, + {:postid=>:string}, + {:username=>:string}, + {:password=>:string}, + {:content=>:string}, + {:publish=>:bool} + ] + + api_method :getUsersBlogs, :returns => [[Blog::Blog]], :expects => [ + {:appkey=>:string}, + {:username=>:string}, + {:password=>:string} + ] + + api_method :getUserInfo, :returns => [Blog::User], :expects => [ + {:appkey=>:string}, + {:username=>:string}, + {:password=>:string} + ] +end diff --git a/actionwebservice/examples/metaWeblog/apis/blogger_service.rb b/actionwebservice/examples/metaWeblog/apis/blogger_service.rb new file mode 100644 index 0000000000..b79b53e6f7 --- /dev/null +++ b/actionwebservice/examples/metaWeblog/apis/blogger_service.rb @@ -0,0 +1,34 @@ +require 'blogger_api' + +class BloggerService < ActionWebService::Base + web_service_api BloggerAPI + + def initialize + @postid = 0 + end + + def newPost(key, id, user, pw, content, publish) + $stderr.puts "id=#{id} user=#{user} pw=#{pw}, content=#{content.inspect} [#{publish}]" + (@postid += 1).to_s + end + + def editPost(key, post_id, user, pw, content, publish) + $stderr.puts "id=#{post_id} user=#{user} pw=#{pw} content=#{content.inspect} [#{publish}]" + true + end + + def getUsersBlogs(key, user, pw) + $stderr.puts "getting blogs for #{user}" + blog = Blog::Blog.new( + :url =>'http://blog', + :blogid => 'myblog', + :blogName => 'My Blog' + ) + [blog] + end + + def getUserInfo(key, user, pw) + $stderr.puts "getting user info for #{user}" + Blog::User.new(:nickname => 'user', :email => 'user@test.com') + end +end diff --git a/actionwebservice/examples/metaWeblog/apis/meta_weblog_api.rb b/actionwebservice/examples/metaWeblog/apis/meta_weblog_api.rb new file mode 100644 index 0000000000..adef12a20f --- /dev/null +++ b/actionwebservice/examples/metaWeblog/apis/meta_weblog_api.rb @@ -0,0 +1,67 @@ +# +# here lie structures, cousins of those on http://www.xmlrpc.com/metaWeblog +# but they don't necessarily the real world reflect +# so if you do, find that your client complains: +# please tell, of problems you suffered through +# + +module Blog + class Post < ActionWebService::Struct + member :title, :string + member :link, :string + member :description, :string + member :author, :string + member :category, :string + member :comments, :string + member :guid, :string + member :pubDate, :string + end + + class Category < ActionWebService::Struct + member :description, :string + member :htmlUrl, :string + member :rssUrl, :string + end +end + +# +# metaWeblog +# +class MetaWeblogAPI < ActionWebService::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 :getCategories, :returns => [[Blog::Category]], :expects => [ + {:blogid=>:string}, + {:username=>:string}, + {:password=>:string}, + ] + + api_method :getRecentPosts, :returns => [[Blog::Post]], :expects => [ + {:blogid=>:string}, + {:username=>:string}, + {:password=>:string}, + {:numberOfPosts=>:int}, + ] +end diff --git a/actionwebservice/examples/metaWeblog/apis/meta_weblog_service.rb b/actionwebservice/examples/metaWeblog/apis/meta_weblog_service.rb new file mode 100644 index 0000000000..9c66558f1b --- /dev/null +++ b/actionwebservice/examples/metaWeblog/apis/meta_weblog_service.rb @@ -0,0 +1,48 @@ +require 'meta_weblog_api' + +class MetaWeblogService < ActionWebService::Base + web_service_api MetaWeblogAPI + + def initialize + @postid = 0 + end + + def newPost(id, user, pw, struct, publish) + $stderr.puts "id=#{id} user=#{user} pw=#{pw}, struct=#{struct.inspect} [#{publish}]" + (@postid += 1).to_s + end + + def editPost(post_id, user, pw, struct, publish) + $stderr.puts "id=#{post_id} user=#{user} pw=#{pw} struct=#{struct.inspect} [#{publish}]" + true + end + + def getPost(post_id, user, pw) + $stderr.puts "get post #{post_id}" + Blog::Post.new(:title => 'hello world', :description => 'first post!') + end + + def getCategories(id, user, pw) + $stderr.puts "categories for #{user}" + cat = Blog::Category.new( + :description => 'Tech', + :htmlUrl => 'http://blog/tech', + :rssUrl => 'http://blog/tech.rss') + [cat] + end + + def getRecentPosts(id, user, pw, num) + $stderr.puts "recent #{num} posts for #{user} on blog #{id}" + post1 = Blog::Post.new( + :title => 'first post!', + :link => 'http://blog.xeraph.org/testOne.html', + :description => 'this is the first post' + ) + post2 = Blog::Post.new( + :title => 'second post!', + :link => 'http://blog.xeraph.org/testTwo.html', + :description => 'this is the second post' + ) + [post1, post2] + end +end diff --git a/actionwebservice/examples/metaWeblog/blog_controller.rb b/actionwebservice/examples/metaWeblog/blog_controller.rb deleted file mode 100644 index e575203311..0000000000 --- a/actionwebservice/examples/metaWeblog/blog_controller.rb +++ /dev/null @@ -1,127 +0,0 @@ -# point your client at http://project_url/blog/api to test -# this - -# structures as defined by the metaWeblog/blogger -# specifications. -module Blog - class Enclosure < ActionWebService::Struct - member :url, :string - member :length, :int - member :type, :string - end - - class Source < ActionWebService::Struct - member :url, :string - member :name, :string - end - - class Post < ActionWebService::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 < ActionWebService::Struct - member :url, :string - member :blogid, :string - member :blogName, :string - end -end - -# skeleton metaWeblog API -class MetaWeblogAPI < ActionWebService::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 - web_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( - :url =>'http://blog.xeraph.org', - :blogid => 'sttm', - :blogName => 'slave to the machine' - ) - [blog] - end - - def getRecentPosts - $stderr.puts "Returning recent posts (%d requested)" % @params['numberOfPosts'] - post1 = Blog::Post.new( - :title => 'first post!', - :link => 'http://blog.xeraph.org/testOne.html', - :description => 'this is the first post' - ) - post2 = Blog::Post.new( - :title => 'second post!', - :link => 'http://blog.xeraph.org/testTwo.html', - :description => 'this is the second post' - ) - [post1, post2] - end -end diff --git a/actionwebservice/examples/metaWeblog/controllers/xmlrpc_controller.rb b/actionwebservice/examples/metaWeblog/controllers/xmlrpc_controller.rb new file mode 100644 index 0000000000..7486402d6c --- /dev/null +++ b/actionwebservice/examples/metaWeblog/controllers/xmlrpc_controller.rb @@ -0,0 +1,16 @@ +# +# example controller implementing both blogger and metaWeblog APIs +# in a way that should be compatible with clients supporting both/either. +# +# test by pointing your client at http://URL/xmlrpc/api +# + +require 'meta_weblog_service' +require 'blogger_service' + +class XmlrpcController < ApplicationController + web_service_dispatching_mode :layered + + web_service :metaWeblog, MetaWeblogService.new + web_service :blogger, BloggerService.new +end diff --git a/actionwebservice/lib/action_web_service/vendor/ws/types.rb b/actionwebservice/lib/action_web_service/vendor/ws/types.rb index 650cdb0848..88098b5bce 100644 --- a/actionwebservice/lib/action_web_service/vendor/ws/types.rb +++ b/actionwebservice/lib/action_web_service/vendor/ws/types.rb @@ -146,6 +146,9 @@ module WS value.to_s when :bool return false if value.nil? + int_value = Integer(value) rescue nil + return true if int_value == 1 + return false if int_value == 0 value = value.to_s return true if value == 'true' return false if value == 'false' diff --git a/actionwebservice/test/ws/types_test.rb b/actionwebservice/test/ws/types_test.rb index 649fdbad7c..e66ae65945 100644 --- a/actionwebservice/test/ws/types_test.rb +++ b/actionwebservice/test/ws/types_test.rb @@ -27,6 +27,8 @@ class TypesTest < Test::Unit::TestCase assert_equal('50.0', @caster.cast(50.0, String)) assert_equal(true, @caster.cast('true', FalseClass)) assert_equal(false, @caster.cast('false', TrueClass)) + assert_equal(true, @caster.cast(1, FalseClass)) + assert_equal(false, @caster.cast(0, TrueClass)) assert_raises(TypeError) do @caster.cast('yes', FalseClass) end -- cgit v1.2.3