Class: Hushed::Message
- Inherits:
-
Object
- Object
- Hushed::Message
- Defined in:
- lib/hushed/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.
-
#message_object ⇒ Object
Returns the value of attribute message_object.
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
Instance Method Summary collapse
- #attributes ⇒ Object
- #delete ⇒ 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.
12 13 14 15 16 |
# File 'lib/hushed/message.rb', line 12 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/hushed/message.rb', line 9 def client @client end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
9 10 11 |
# File 'lib/hushed/message.rb', line 9 def document @document end |
#message_object ⇒ Object
Returns the value of attribute message_object.
10 11 12 |
# File 'lib/hushed/message.rb', line 10 def @message_object end |
#xml ⇒ Object (readonly)
Returns the value of attribute xml.
9 10 11 |
# File 'lib/hushed/message.rb', line 9 def xml @xml end |
Instance Method Details
#attributes ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/hushed/message.rb', line 39 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, MessageId: @document., xmlns: NAMESPACE } end |
#delete ⇒ Object
25 26 27 28 29 |
# File 'lib/hushed/message.rb', line 25 def delete return false unless .delete true end |
#document_name ⇒ Object
35 36 37 |
# File 'lib/hushed/message.rb', line 35 def document_name @document ? @document.filename : @xml.css('EventMessage').first['DocumentName'] end |
#document_type ⇒ Object
31 32 33 |
# File 'lib/hushed/message.rb', line 31 def document_type @document ? @document.type : @xml.css('EventMessage').first['DocumentType'] end |
#to_xml ⇒ Object
18 19 20 21 22 23 |
# File 'lib/hushed/message.rb', line 18 def to_xml builder = Nokogiri::XML::Builder.new do |xml| xml.EventMessage(attributes) end builder.to_xml end |