Class: Nuncium::DataMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/nuncium/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.



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/nuncium/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

Class Method Details

.find(dmID) ⇒ Object



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

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

Instance Method Details

#authenticateObject



46
47
48
49
# File 'lib/nuncium/data_message.rb', line 46

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

#authorObject



56
57
58
59
# File 'lib/nuncium/data_message.rb', line 56

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

#confirm_deliveryObject



76
77
78
79
# File 'lib/nuncium/data_message.rb', line 76

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

#delivery_infoObject



61
62
63
64
# File 'lib/nuncium/data_message.rb', line 61

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

#destroy(options = {}) ⇒ Object



86
87
88
89
# File 'lib/nuncium/data_message.rb', line 86

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

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



21
22
23
24
25
26
27
# File 'lib/nuncium/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

#envelopeObject



71
72
73
74
# File 'lib/nuncium/data_message.rb', line 71

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

#mark_as_downloadedObject



81
82
83
84
# File 'lib/nuncium/data_message.rb', line 81

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

#received?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/nuncium/data_message.rb', line 95

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

#sent?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/nuncium/data_message.rb', line 91

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

#signedObject



51
52
53
54
# File 'lib/nuncium/data_message.rb', line 51

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

#signed_delivery_infoObject



66
67
68
69
# File 'lib/nuncium/data_message.rb', line 66

def signed_delivery_info
  Nuncium::WebServices::DmInfo::GetSignedDeliveryInfo
    .call(dmID: dmID)
end

#verifyObject



41
42
43
44
# File 'lib/nuncium/data_message.rb', line 41

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