README.rdoc in smacks-apricoteatsgorilla-0.2.8 vs README.rdoc in smacks-apricoteatsgorilla-0.3.2

- old
+ new

@@ -1,68 +1,37 @@ = Apricot eats Gorilla -Apricot eats Gorilla is a helper for working with XML and SOAP messages. -It's based on CobraVsMongoose but without REXML and the BadgerFish convention. -Also it offers some extras for working with SOAP messages. +Apricot eats Gorilla is a SOAP communication helper. +It translates between SOAP response messages (XML) and Ruby Hashes and may +be used to build a SOAP request envelope. It is based on CobraVsMongoose but +uses Hpricot instead of REXML and doesn't follow the BadgerFish convention. + == Install - $ sudo gem install smacks-apricoteatsgorilla --source http://gems.github.com + $ gem install smacks-apricoteatsgorilla -s http://gems.github.com == Dependencies Hpricot 0.6.164 (also available for JRuby) -== An example +== Translating an XML String into a Ruby Hash -Let's assume you receive the following SOAP response: + xml = "<apricot><eats>Gorilla</eats></apricot>" + ApricotEatsGorilla[xml] + # => { :eats => "Gorilla" } -xml = '<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>' +== Translating a Ruby Hash into an XML String -Just pass in the raw XML string: + hash = { :apricot => { :eats => "Gorilla" } } + ApricotEatsGorilla[hash] + # => "<apricot><eats>Gorilla</eats></apricot>" - require "rubygems" - require "apricoteatsgorilla - hash = ApricotEatsGorilla.xml_to_hash(xml, "//return") +== Creating a SOAP request envelope -Or use the shortcut: + ApricotEatsGorilla.soap_envelope { "<authenticate>me</authenticate>" } - hash = ApricotEatsGorilla(xml, "//return") - -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" - } - -== Conclusions - -* The xml_to_hash method starts parsing the XML at the root node by default. - By calling the method with an XPath expression as second parameter, we're - able to define a custom root node. -* Node attributes are ignored and won't be included in the hash. -* The value of empty element nodes will be nil. -* Node values of "true" or "false" will be converted to boolean objects. - -== More information - -Take a look at the tests for some more examples. + # => '<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"> + # => <env:Body> + # => <authenticate>me</authenticate> + # => </env:Body> + # => </env:Envelope>' \ No newline at end of file