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.



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

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



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

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

#authorObject



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

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

#confirm_deliveryObject



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

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

#delivery_infoObject



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

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

#destroy(options = {}) ⇒ Object



86
87
88
89
# 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') ⇒ Object



21
22
23
24
25
26
27
# 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

#envelopeObject



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

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

#mark_as_downloadedObject



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

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

#received?Boolean

Returns:

  • (Boolean)


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

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

#sent?Boolean

Returns:

  • (Boolean)


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

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

#signedObject



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

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

#signed_delivery_infoObject



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

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

#verifyObject



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

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