Class: RubyIsds::DataMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_isds/data_message.rb

Constant Summary collapse

ATTRIBUTES =
%w[dmType dmOrdinal dmID dbIDSender dmSender
dmSenderAddress dmSenderType dmRecipient dmRecipientAddress
dmSenderOrgUnit dmSenderOrgUnitNum dbIDRecipient dmRecipientOrgUnit
dmRecipientOrgUnitNum dmToHands dmAnnotation dmRecipientRefNumber
dmSenderRefNumber dmRecipientIdent dmSenderIdent dmLegalTitleLaw
dmLegalTitleYear dmLegalTitleSect dmLegalTitlePar dmLegalTitlePoint
dmPersonalDelivery dmAllowSubstDelivery dmMessageStatus
dmAttachmentSize dmDeliveryTime dmAcceptanceTime dmHash
dmQTimestamp dmAttachments dmAmbiguousRecipient].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ DataMessage

Returns a new instance of DataMessage.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ruby_isds/data_message.rb', line 27

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

Class Method Details

.find(dmID) ⇒ Object



16
17
18
19
# File 'lib/ruby_isds/data_message.rb', line 16

def self.find(dmID)
  RubyIsds::WebServices::DmOperations::MessageDownload
    .call(dmID: dmID)
end

Instance Method Details

#authenticateObject



44
45
46
47
# File 'lib/ruby_isds/data_message.rb', line 44

def authenticate
  RubyIsds::WebServices::DmOperations::AuthenticateMessage
    .call(dmMessage: signed.body.dmSignature)
end

#authorObject



54
55
56
57
# File 'lib/ruby_isds/data_message.rb', line 54

def author
  RubyIsds::WebServices::DmInfo::GetMessageAuthor
    .call(dmID: dmID)
end

#confirm_deliveryObject



69
70
71
72
# File 'lib/ruby_isds/data_message.rb', line 69

def confirm_delivery
  RubyIsds::WebServices::DmInfo::ConfirmDelivery
    .call(dmID: dmID)
end

#delivery_infoObject



59
60
61
62
# File 'lib/ruby_isds/data_message.rb', line 59

def delivery_info
  RubyIsds::WebServices::DmInfo::GetDeliveryInfo
    .call(dmID: dmID)
end

#destroy(options = {}) ⇒ Object



79
80
81
82
# File 'lib/ruby_isds/data_message.rb', line 79

def destroy(options = {})
  RubyIsds::WebServices::DmInfo::EraseMessage
    .call(options.merge(dmID: dmID))
end

#download(destination = '/tmp') ⇒ Object



21
22
23
24
25
# File 'lib/ruby_isds/data_message.rb', line 21

def download(destination = '/tmp')
  File.open("#{destination}/#{dmID}.zfo", 'wb') do |f|
    f.write(Base64.decode64(signed.body.dmSignature))
  end
end

#envelopeObject



64
65
66
67
# File 'lib/ruby_isds/data_message.rb', line 64

def envelope
  RubyIsds::WebServices::DmInfo::MessageEnvelopeDownload
    .call(dmID: dmID)
end

#mark_as_downloadedObject



74
75
76
77
# File 'lib/ruby_isds/data_message.rb', line 74

def mark_as_downloaded
  RubyIsds::WebServices::DmInfo::MarkMessageAsDownloaded
    .call(dmID: dmID)
end

#received?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/ruby_isds/data_message.rb', line 88

def received?
  dbIDSender != ::RubyIsds.configuration.data_box
end

#sent?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/ruby_isds/data_message.rb', line 84

def sent?
  dbIDSender == ::RubyIsds.configuration.data_box
end

#signedObject



49
50
51
52
# File 'lib/ruby_isds/data_message.rb', line 49

def signed
  RubyIsds::WebServices::DmOperations::SignedMessageDownload
    .call(dmID: dmID)
end

#verifyObject



39
40
41
42
# File 'lib/ruby_isds/data_message.rb', line 39

def verify
  RubyIsds::WebServices::DmInfo::VerifyMessage
    .call(dmID: dmID)
end