Sha256: d64665d879c77e01638139538421b5eadb95779b3044bfcea5645c96bf513143

Contents?: true

Size: 1.8 KB

Versions: 1

Compression:

Stored size: 1.8 KB

Contents

= Apricot eats Gorilla

Apricot eats Gorilla converts SOAP response messages to Ruby hashes.
It's based on CobraVsMongoose but uses Hpricot instead of REXML and it
also doesn't follow the BadgerFish convention.

== Install

  $ sudo gem sources -a http://gems.github.com
  $ sudo gem install smacks-apricoteatsgorilla
  $ sudo gem install hpricot

== Dependencies

  Hpricot 0.6.164 (also available for JRuby)

== An example

Let's assume you receive the following SOAP response message:

  <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
      <ns2:findCustomerByIdResponse xmlns:ns2="http://v1_0.ws.example.com/">
        <return>
          <empty>false</empty>
          <customer>
            <id>449810</id>
            <title xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <name>Jungle Julia</name>
            <email>jj@example.com</email>
            <address />
          </customer>
        </return>
      </ns2:findCustomerByIdResponse>
    </soap:Body>
  </soap:Envelope>

Just pass in the raw XML string like this:

  require 'rubygems'
  require 'apricoteatsgorilla'
  hash = ApricotEatsGorilla.soap_response_to_hash(xml)

And it gets converted into a nice little hash:

  "empty" => false,
  "customer" => {
    "address" => nil,
    "name" => "Jungle Julia",
    "title" => nil,
    "id" => "449810",
    "email" => "jj@example.com"
  }

== The conclusion

* It assumes a root node named "return", but you can pass in an XPath
  expession as the second parameter, to define a different root node.
* All attributes are ignored and won't be included in the hash.
* The value of empty element nodes will be nil.
* Values of "true" or "false" will be converted to boolean objects.

== For more information

Take a look at the tests to see some more examples.

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smacks-apricoteatsgorilla-0.1.2 README.rdoc