As I’ve written about previously, I’m working on a Radiant site with my buddy KB. We want to leverage a newsletter building application and an email sending service that we’ve developed for our other projects in this site. To do so, we needed to consume some web services that are part of another Rails application to do the subscribing and unsubscribing from a mailing list. There doesn’t seem to be much information about consuming web services from a Radiant application, so I thought I’d share what I found here. My discovery was based on a suggestion by Sean Cribbs to look at the Radiant LDAP extension.
So basically I found that you need to create a global tags module. In it you define your ActionWebService API and the tags you’ll use. Here’s a sample:
require 'action_web_service'
module MyTest
include Radiant::Taggable
class MyTestApi < ActionWebSerivce::API::Base
api_method :some_method, :expects => [{:foo => :string}]
end
tag 'mytest:action' do |tag|
if request.post?
# some code to get posted values
myval = request.paremters['mytestvalue']
if myval.empty?
raise "No value."
end
mytest = ActionWebService::Client::Soap.new(MyTestApi, "http://someapiurl/", :handler_name => "some_handler"
mytest.some_method(myval)
end
end
end
So that’s it in a nutshell. Wrap your tags and an Api class in the same module. You can call your Api methods from your tag definitions to execute the services you need.