Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
/ savon_model Public archive

DEPRECATED: Model for SOAP service oriented applications

License

Notifications You must be signed in to change notification settings

savonrb/savon_model

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Savon::Model Build Status

Model for SOAP service oriented applications.

DEPRECATED

As of v0.9.8, Savon ships with a refactored version of Savon::Model.
Please upgrade and use the latest version of Savon instead!

Installation

Savon::Model is available through Rubygems and can be installed via:

$ gem install savon_model

Include

Savon::Model comes with quite a few handy class and instance methods for using Savon inside your SOAP model classes.
Simply include the module in any of your classes to get started.

require "savon_model"

class User
  include Savon::Model
end

Service

You can configure Savon to work with or without a WSDL document with the .document, .endpoint and .namespace class methods.
Point Savon to the WSDL of your service:

class User
  include Savon::Model

  document "http://service.example.com?wsdl"
end

or set the SOAP endpoint and target namespace to bypass the WSDL:

class User
  include Savon::Model

  endpoint "http://service.example.com"
  namespace "http://v1.service.example.com"
end

Authentication

Set your HTTP basic authentication username and password via the .basic_auth method:

class User
  include Savon::Model

  basic_auth "login", "password"
end

or use the .wsse_auth method to set your WSSE username, password and (optional) whether or not to use digest authentication.

class User
  include Savon::Model

  wsse_auth "login", "password", :digest
end

Actions

Define the service methods you're working with via the .actions class method. Savon::Model creates both class and instance
methods for every action. These methods accept a SOAP body Hash and return a Savon::SOAP::Response for you to use.
You can wrap those methods in other methods:

class User
  include Savon::Model

  actions :get_user, :get_all_users

  def self.all
    get_all_users.to_array
  end

end

or extend them by delegating to super:

class User
  include Savon::Model

  actions :get_user, :get_all_users

  def get_user(id)
    super(:user_id => id).to_hash[:get_user_response][:return]
  end

end

Else

The Savon::Client instance used in your model lives at .client inside your class. It gets initialized lazily whenever you call
any other class or instance method that tries to access the client. In case you need to control how the client gets initialized,
you can pass a block to .client before it's memoized:

class User
  include Savon::Model

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

end

You can also bypass Savon::Model and directly use the client:

class User
  include Savon::Model

  document "http://service.example.com?wsdl"

  def find_by_id(id)
    response = client.request(:find_user) do
      soap.body = { :id => id }
    end

    response.body[:find_user_response][:return]
  end

end

About

DEPRECATED: Model for SOAP service oriented applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages