class Reactor::Cm::MultiXmlRequest

Public Class Methods

execute() { |instance| ... } click to toggle source
# File lib/reactor/cm/multi_xml_request.rb, line 19
def self.execute
  access = Configuration::xml_access
  sanity_check(access)
  xml = XmlMarkup.new
  xml2 = nil
  ret = nil
  xml.instruct!
  req = nil
  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
    req = self.new(xml).tap do |instance|
      yield instance
    end
  end
  req.execute!(ret)
end
generate_id() click to toggle source
# File lib/reactor/cm/multi_xml_request.rb, line 71
def generate_id
  rand(10000)
end
new(builder) click to toggle source
# File lib/reactor/cm/multi_xml_request.rb, line 84
def initialize(builder)
  @builder = builder
  @mandatory = []
  @optional = []
end
timeout() click to toggle source
# File lib/reactor/cm/multi_xml_request.rb, line 11
def self.timeout
  Reactor::Cm::XmlRequest.timeout
end
token(login, instance_secret) click to toggle source
# File lib/reactor/cm/multi_xml_request.rb, line 15
def self.token(login, instance_secret)
  Digest::MD5.hexdigest(login + instance_secret)
end

Protected Class Methods

sanity_check(access) click to toggle source
# File lib/reactor/cm/multi_xml_request.rb, line 77
def sanity_check(access)
  raise Reactor::Cm::MissingCredentials if access[:username].nil? || access[:username].empty?
end

Public Instance Methods

execute!(xml) click to toggle source
# File lib/reactor/cm/multi_xml_request.rb, line 55
def execute!(xml)
  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')
    req.body = payload
    http.request(req)
  end

  result = MultiXmlResponse.new(res.body, @mandatory, @optional)
end
mandatory() { |xml2| ... } click to toggle source
# File lib/reactor/cm/multi_xml_request.rb, line 39
def mandatory(&block)
  req_id = self.class.generate_id
  @mandatory << req_id
  @builder.tag!('cm-request', 'request-id' => req_id, 'preclusive' => 'true') do |xml2|
    yield xml2
  end
end
optional() { |xml2| ... } click to toggle source
# File lib/reactor/cm/multi_xml_request.rb, line 47
def optional(&block)
  req_id = self.class.generate_id
  @optional << req_id
  @builder.tag!('cm-request', 'request-id' => req_id, 'preclusive' => 'false') do |xml2|
    yield xml2
  end
end