Savon::Model Build Status

Model for SOAP service oriented applications.

Bugs | Docs

Installation

The gem is available through Rubygems and can be installed via:

$ gem install savon_model

Getting started

class User
  include Savon::Model

  client do                                               [1]
    http.headers["Pragma"] = "no-cache"
  end

  document "http://example.com/users?wsdl"                [2]

  endpoint "http://example.com/users"                     [3]
  namespace "http://v1.example.com/users"                 [4]

  basic_auth "login", "password"                          [5]

  actions :get_user, :get_all_users                       [6]

  def self.all
    get_all_users.to_array                                [7]
  end

  def self.find(id)
    get_user(:id => id).to_hash                           [8]
  end

  def self.delete(id)
    client.request(:delete_user) do                       [9]
      soap.body = { :id => 1 }
    end.to_hash
  end
end
  1. You can call the client method with a block of settings to be passed to Savon::Client.new. The client method memoizes a Savon::Client instance, so you need to call this method before it gets called by any other method.

  2. Sets the WSDL document.

  3. Sets the SOAP endpoint.

  4. Sets the target namespace.

  5. Sets basic auth credentials.

  6. Specifies the SOAP actions provided by the service. This method dynamically creates both class and instance methods named after the arguments. These methods accept an optional SOAP body Hash or XML String to be passed to the Savon::Client instance.

  7. User.all calls the get_all_users SOAP action and returns a Savon::Response.

  8. User.find calls the get_user SOAP action with a SOAP body Hash and returns a Savon::Response.

  9. This is an example of what happens "behind the scenes" on [6]. You can always use the client method to directly access and use the Savon::Client instance.