4. Protocol clients
4.1 Overview
Action Web Service includes some client classes for accessing remote web services.
These classes understand Action Web Service API definitions, so if you have the API definition of a remote service, you can access it with type conversion to and from the correct types occuring automatically for you.
However, these are not general purpose clients. If your client application is not tightly coupled to the server, it may make more sense to use Ruby’s native SOAP and XML-RPC clients.
See SOAP::WSDLDriverFactory or XMLRPC::Client for details on the Ruby native clients.
4.2 Using the clients
Using from inside a controller
If you want to access the remote web service API from inside a controller, a helper function named #web_client_api can be used.
Example
class MyController < ApplicationController
web_client_api :blogger, :xmlrpc, "http://blogger.com/me/api/RPC2", :handler_name => "blogger"
def list
blogger.getRecentPosts.each do
end
end
end
The result of calling #web_client_api is that a protected method named #blogger will now exist in the controller, using a BloggerAPI defined in app/apis/blogger_api.rb, and calling it will return a client object with all the methods of BloggerAPI available for execution.
Using directly
Create an instance of the client for the relevant protocol, either ActionWebService::Client::Soap or ActionWebService::Client::XmlRpc, and start invoking the API methods on it.
Example
blog = ActionWebService::Client::Soap.new(BloggerAPI, "http://blogger.com/me/api/RPC2", :handler_name => "blogger")
posts = blog.getRecentPosts