Class: Itrp::Export::Monitor::Mail

Inherits:
Object
  • Object
show all
Defined in:
lib/itrp/export/monitor/mail.rb

Instance Method Summary collapse

Constructor Details

#initialize(mail) ⇒ Mail

Returns a new instance of Mail.



5
6
7
# File 'lib/itrp/export/monitor/mail.rb', line 5

def initialize(mail)
  @mail = mail
end

Instance Method Details

#download_uriObject



24
25
26
27
28
# File 'lib/itrp/export/monitor/mail.rb', line 24

def download_uri
  return nil unless self.export_id
  # the first match from https:// until a space or the end of the line
  @download_uri ||= @mail.text_part.body.decoded[/(https?:\/\/[^\s$]+)/, 1]
end

#export_idObject

value of mail header: X-ITRP-ExportID, e.g. 2



14
15
16
# File 'lib/itrp/export/monitor/mail.rb', line 14

def export_id
  @export_id ||= @mail.header['X-ITRP-ExportID'].try(:value).try(:to_i)
end

#filenameObject

the filename of the csv or zip file



31
32
33
34
# File 'lib/itrp/export/monitor/mail.rb', line 31

def filename
  return nil if self.download_uri.blank?
  @filename ||= self.download_uri[/\/([^\/]+\.(?:csv|zip))/, 1]
end

#ignoreObject

ignore the message



37
38
39
# File 'lib/itrp/export/monitor/mail.rb', line 37

def ignore
  @mail.skip_deletion
end

#originalObject



9
10
11
# File 'lib/itrp/export/monitor/mail.rb', line 9

def original
  @mail
end

#tokenObject

value of mail header: X-ITRP-Export, e.g. ‘0fad4fc0fd4a0130ad2a12313b0e50759969ab71899d2bb1d3e3d8f66e6e5133’



19
20
21
# File 'lib/itrp/export/monitor/mail.rb', line 19

def token
  @token ||= @mail.header['X-ITRP-Export'].try(:value)
end