Class: Reactor::Cm::MultiXmlRequest
- Inherits:
-
Object
- Object
- Reactor::Cm::MultiXmlRequest
show all
- Defined in:
- lib/reactor/cm/multi_xml_request.rb
Defined Under Namespace
Classes: MultiXmlResponse
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.execute ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/reactor/cm/multi_xml_request.rb', line 18
def self.execute
access = Configuration.xml_access
sanity_check(access)
xml = XmlMarkup.new
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 = new(xml).tap do |instance|
yield instance
end
end
req.execute!(ret)
end
|
.generate_id ⇒ Object
67
68
69
|
# File 'lib/reactor/cm/multi_xml_request.rb', line 67
def generate_id
rand(10_000)
end
|
.timeout ⇒ Object
10
11
12
|
# File 'lib/reactor/cm/multi_xml_request.rb', line 10
def self.timeout
Reactor::Cm::XmlRequest.timeout
end
|
.token(login, instance_secret) ⇒ Object
14
15
16
|
# File 'lib/reactor/cm/multi_xml_request.rb', line 14
def self.token(login, instance_secret)
Digest::MD5.hexdigest(login + instance_secret)
end
|
Instance Method Details
#execute!(xml) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/reactor/cm/multi_xml_request.rb', line 52
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
MultiXmlResponse.new(res.body, @mandatory, @optional)
end
|
#mandatory ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/reactor/cm/multi_xml_request.rb', line 36
def mandatory
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 ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/reactor/cm/multi_xml_request.rb', line 44
def optional
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
|