class RubyIsds::DataMessage
Constants
- ATTRIBUTES
Public Class Methods
find(dmID)
click to toggle source
# File lib/ruby_isds/data_message.rb, line 16 def self.find(dmID) RubyIsds::WebServices::DmOperations::MessageDownload .call(dmID: dmID) end
new(params = {})
click to toggle source
# File lib/ruby_isds/data_message.rb, line 29 def initialize(params = {}) @params = params.dup @status_info = @params.delete('dmDm') @dmAttachments = load_attachments @dmEvents = load_events unified_params = @status_info ? @status_info.merge(@params) : params unified_params.each do |key, value| raise "Not valid attribute of DataMessage #{key}" unless ATTRIBUTES.include?(key) instance_variable_set("@#{key}", parsed_value(value)) end end
Public Instance Methods
authenticate()
click to toggle source
# File lib/ruby_isds/data_message.rb, line 46 def authenticate RubyIsds::WebServices::DmOperations::AuthenticateMessage .call(dmMessage: signed.body.dmSignature) end
confirm_delivery()
click to toggle source
# File lib/ruby_isds/data_message.rb, line 76 def confirm_delivery RubyIsds::WebServices::DmInfo::ConfirmDelivery .call(dmID: dmID) end
delivery_info()
click to toggle source
# File lib/ruby_isds/data_message.rb, line 61 def delivery_info RubyIsds::WebServices::DmInfo::GetDeliveryInfo .call(dmID: dmID) end
destroy(options = {})
click to toggle source
# File lib/ruby_isds/data_message.rb, line 86 def destroy(options = {}) RubyIsds::WebServices::DmInfo::EraseMessage .call(options.merge(dmID: dmID)) end
download(destination = '/tmp')
click to toggle source
# File lib/ruby_isds/data_message.rb, line 21 def download(destination = '/tmp') path = "#{destination}/#{dmID}.zfo" File.open(path, 'wb') do |f| f.write(Base64.decode64(signed.body.dmSignature)) end path end
envelope()
click to toggle source
# File lib/ruby_isds/data_message.rb, line 71 def envelope RubyIsds::WebServices::DmInfo::MessageEnvelopeDownload .call(dmID: dmID) end
mark_as_downloaded()
click to toggle source
# File lib/ruby_isds/data_message.rb, line 81 def mark_as_downloaded RubyIsds::WebServices::DmInfo::MarkMessageAsDownloaded .call(dmID: dmID) end
received?()
click to toggle source
# File lib/ruby_isds/data_message.rb, line 95 def received? dbIDSender != ::RubyIsds.configuration.data_box end
sent?()
click to toggle source
# File lib/ruby_isds/data_message.rb, line 91 def sent? dbIDSender == ::RubyIsds.configuration.data_box end
signed()
click to toggle source
# File lib/ruby_isds/data_message.rb, line 51 def signed RubyIsds::WebServices::DmOperations::SignedMessageDownload .call(dmID: dmID) end
signed_delivery_info()
click to toggle source
# File lib/ruby_isds/data_message.rb, line 66 def signed_delivery_info RubyIsds::WebServices::DmInfo::GetSignedDeliveryInfo .call(dmID: dmID) end
verify()
click to toggle source
# File lib/ruby_isds/data_message.rb, line 41 def verify RubyIsds::WebServices::DmInfo::VerifyMessage .call(dmID: dmID) end
Private Instance Methods
load_attachments()
click to toggle source
# File lib/ruby_isds/data_message.rb, line 113 def load_attachments return {} if @status_info&.dig('dmFiles').blank? attachments_hash = @status_info.delete('dmFiles')['dmFile'] if attachments_hash.is_a?(Array) attachments_hash.map do |attachment| ::RubyIsds::Responses::Messages::Attachment.new(attachment) end else [::RubyIsds::Responses::Messages::Attachment.new(attachments_hash)] end end
load_events()
click to toggle source
# File lib/ruby_isds/data_message.rb, line 101 def load_events return {} if @params['dmEvents'].blank? events_hash = @params.delete('dmEvents')['dmEvent'] if events_hash.is_a?(Array) events_hash.map do |event| ::RubyIsds::Responses::Messages::Event.new(event) end else ::RubyIsds::Responses::Messages::Event.new(events_hash) end end
parsed_value(value)
click to toggle source
# File lib/ruby_isds/data_message.rb, line 125 def parsed_value(value) return value unless value.is_a?(Hash) raise "Missing parse rule for #{value}" if value.keys.size > 1 if value.keys.first == 'xsi:nil' && value.values.first == 'true' nil else false end end