Class: Reactor::Cm::XmlRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/reactor/cm/xml_request.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepareObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/reactor/cm/xml_request.rb', line 28

def self.prepare
  access = Configuration::xml_access
  sanity_check(access)
  xml = XmlMarkup.new
  ret = nil
  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 = self.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



24
25
26
# File 'lib/reactor/cm/xml_request.rb', line 24

def self.token(, instance_secret)
  Digest::MD5.hexdigest( + instance_secret)
end

Instance Method Details

#execute!Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/reactor/cm/xml_request.rb', line 47

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