Class: Reactor::Cm::XmlRequest
- Inherits:
-
Object
- Object
- Reactor::Cm::XmlRequest
- Defined in:
- lib/reactor/cm/xml_request.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.prepare ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/reactor/cm/xml_request.rb', line 21 def self.prepare access = Configuration.xml_access sanity_check(access) xml = XmlMarkup.new xml.instruct! ret = xml.tag!("cm-payload", "payload-id" => "abcabc", "timestamp" => Time.now.getutc.strftime("%Y%m%d%H%M%S"), "version" => "6.7.3") do xml.tag!("cm-header") do xml.tag!("cm-sender", "sender-id" => access[:id], "name" => "ruby-simple-client") xml.tag!("cm-authentication", "login" => access[:username], "token" => token(access[:username], access[:secret])) end id = generate_id xml.tag!("cm-request", "request-id" => id) do |xml2| yield xml2 if block_given? end end XmlRequest.new(ret) end |
.token(login, instance_secret) ⇒ Object
17 18 19 |
# File 'lib/reactor/cm/xml_request.rb', line 17 def self.token(login, instance_secret) Digest::MD5.hexdigest(login + instance_secret) end |
Instance Method Details
#execute! ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/reactor/cm/xml_request.rb', line 39 def execute! access = Configuration.xml_access payload = @xml res = Net::HTTP.new(access[:host], access[:port]).start do |http| http.read_timeout = self.class.timeout req = Net::HTTP::Post.new("/xml") Reactor::Cm::LOGGER.log("REQUEST:") Reactor::Cm::LOGGER.log_xml(:request, payload) req.body = payload http.request(req) end Reactor::Cm::LOGGER.log("RESPONSE:") Reactor::Cm::LOGGER.log_xml(:response, res.body) response = XmlResponse.new(res.body) raise XmlSingleRequestError, response unless response.ok? response end |