Class: DefraRubyEmail::LastNotifyMessage

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/defra_ruby_email/last_notify_message.rb

Constant Summary collapse

LETTER_ATTRIBUTES =
%i[line_1 line_2 line_3 line_4 line_5 line_6 postcode].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#last_notify_messageObject

Returns the value of attribute last_notify_message.



11
12
13
# File 'lib/defra_ruby_email/last_notify_message.rb', line 11

def last_notify_message
  @last_notify_message
end

Instance Method Details

#last_notify_message_jsonObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/defra_ruby_email/last_notify_message.rb', line 24

def last_notify_message_json
  return JSON.generate(error: "No messages sent.") unless last_notify_message.present?

  message_hash = {}
  message_hash[:type] = last_notify_message.type
  message_hash[:template] = last_notify_message.template
  message_hash[:subject] = last_notify_message.subject
  message_hash[:body] = last_notify_message.body
  message_hash[:date] = last_notify_message.sent_at

  # Email and phone-specific attributes
  message_hash[:to] = last_notify_message.email_address || last_notify_message.phone_number
  # Letter-specific attributes
  LETTER_ATTRIBUTES.each do |attribute|
    message_hash[attribute] = last_notify_message.public_send(attribute)
  end

  JSON.generate(last_notify_message: message_hash)
end

#resetObject

This is necessary to properly test the service functionality



14
15
16
# File 'lib/defra_ruby_email/last_notify_message.rb', line 14

def reset
  @last_notify_message = nil
end

#retrieve_last_notify_messageObject



18
19
20
21
22
# File 'lib/defra_ruby_email/last_notify_message.rb', line 18

def retrieve_last_notify_message
  client = Notifications::Client.new(DefraRubyEmail.configuration.notify_api_key)
  response = client.get_notifications
  @last_notify_message = response.collection.first
end