Class: Gentle::Message
- Inherits:
-
Object
- Object
- Gentle::Message
- Defined in:
- lib/gentle/message.rb
Defined Under Namespace
Classes: MissingClientError, MissingDocumentError
Constant Summary collapse
- NAMESPACE =
"http://schemas.quietlogistics.com/V2/EventMessage.xsd"
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
Instance Method Summary collapse
- #attributes ⇒ Object
- #document_name ⇒ Object
- #document_type ⇒ Object
-
#initialize(options = {}) ⇒ Message
constructor
A new instance of Message.
- #to_xml ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Message
Returns a new instance of Message.
11 12 13 14 15 |
# File 'lib/gentle/message.rb', line 11 def initialize( = {}) @xml = Nokogiri::XML::Document.parse([:xml]) if [:xml] @client = [:client] @document = [:document] end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/gentle/message.rb', line 9 def client @client end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
9 10 11 |
# File 'lib/gentle/message.rb', line 9 def document @document end |
#xml ⇒ Object (readonly)
Returns the value of attribute xml.
9 10 11 |
# File 'lib/gentle/message.rb', line 9 def xml @xml end |
Instance Method Details
#attributes ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/gentle/message.rb', line 32 def attributes raise(MissingClientError.new("client cannot be missing")) unless @client raise(MissingDocumentError.new("document cannot be missing")) unless @document { ClientId: @client.client_id, BusinessUnit: @client.business_unit, DocumentName: @document.filename, DocumentType: @document.type, Warehouse: @document.warehouse, MessageDate: @document.date.utc.iso8601, MessageId: @document., xmlns: NAMESPACE } end |
#document_name ⇒ Object
28 29 30 |
# File 'lib/gentle/message.rb', line 28 def document_name @document ? @document.filename : @xml.css('EventMessage').first['DocumentName'] end |
#document_type ⇒ Object
24 25 26 |
# File 'lib/gentle/message.rb', line 24 def document_type @document ? @document.type : @xml.css('EventMessage').first['DocumentType'] end |
#to_xml ⇒ Object
17 18 19 20 21 22 |
# File 'lib/gentle/message.rb', line 17 def to_xml builder = Nokogiri::XML::Builder.new do |xml| xml.EventMessage(attributes) end builder.to_xml end |