Updated to work with latest Savon and be more friendly

This commit is contained in:
Will Bradley 2012-11-06 02:59:25 -07:00
parent f850f0fbbf
commit de8547eeb9

67
edex.rb
View File

@ -5,19 +5,62 @@
# See README for usage info. # See README for usage info.
class UnitsController < ApplicationController
require 'savon' # Silence silly warnings and info. Make these true if you want to see HTTP/SOAP debug info.
HTTPI.log = false
Savon.configure do |config|
config.log = false
end
debug = 2 # Change from 2, to 1, to 0 as you verify things appear sane.
user_id = "YOUR_EDEX_USERID_HERE"
password = "YOUR_EDEX_PASSWORD_HERE"
portfolio_name = "YOUR_COMPANY_NAME_HERE|YOUR_PORTAL_NAME_HERE"
property_id = "YOUR_PROPERTY_ID_HERE"
require "savon"
require 'nokogiri' require 'nokogiri'
# GET /units
def index client = Savon.client("http://amsi.saas.infor.com/AMSIWEBG003/edexweb/esite/leasing.asmx?wsdl")
client = Savon::Client.new "http://amsi.saas.infor.com/AMSIWEBG003/edexweb/esite/leasing.asmx?wsdl"
response = client.get_property_units do |soap| if debug == 2 then
soap.xml = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetPropertyUnits xmlns="http://tempuri.org/"> <UserID>YOUR_EDEX_USERID_HERE</UserID> <Password>YOUR_EDEX_PASSWORD_HERE</Password> <PortfolioName>YOUR_COMPANY_NAME_HERE|YOUR_PORTAL_NAME_HERE</PortfolioName> <XMLData><![CDATA[<edex><propertyid>YOUR_PROPERTY_ID_HERE</propertyid><includeamenities>0</includeamenities></edex>]]></XMLData> </GetPropertyUnits> </soap:Body></soap:Envelope>' puts client.wsdl.soap_actions
end puts "If the above looks good, set debug=1"
end
if debug < 2 then
response = client.request(:get_property_units) do
#WARNING: <?xml must be the first character on the second line below, no indenting allowed.
soap.xml = <<-eos
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetPropertyUnits xmlns="http://tempuri.org/">
<UserID>#{user_id}</UserID>
<Password>#{password}</Password>
<PortfolioName>#{portfolio_name}</PortfolioName>
<XMLData>
<![CDATA[<edex>
<propertyid>#{property_id}</propertyid>
<includeamenities>0</includeamenities>
</edex>]]>
</XMLData>
</GetPropertyUnits>
</soap:Body>
</soap:Envelope>
eos
end
if debug > 0 then
puts response
puts "If the above looks good, set debug=0"
else
property_data = response.to_hash[:get_property_units_response][:get_property_units_result] property_data = response.to_hash[:get_property_units_response][:get_property_units_result]
doc = Nokogiri::XML(property_data) doc = Nokogiri::XML(property_data)
@view = doc.css('Unit')[0]['UnitId'] view = doc.css('Unit')[0]['UnitId']
puts "Success! The first unit's ID is #{view}"
end end
end
end