Class: GovFakeNotify::SendEmailCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/gov_fake_notify/commands/send_email_command.rb

Overview

A service used when the sending of an email is requested

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, base_url:, service:, store: Store.instance, attachment_store: AttachmentStore.instance) ⇒ SendEmailCommand



17
18
19
20
21
22
23
# File 'lib/gov_fake_notify/commands/send_email_command.rb', line 17

def initialize(params, base_url:, service:, store: Store.instance, attachment_store: AttachmentStore.instance)
  @params = params.dup
  @store = store
  @attachment_store = attachment_store
  @base_url = base_url
  @service = service
end

Class Method Details

.call(params, **kwargs) ⇒ Object

rubocop:disable Metrics/ClassLength



12
13
14
15
# File 'lib/gov_fake_notify/commands/send_email_command.rb', line 12

def self.call(params, **kwargs)
  # do nothing yet
  new(params, **kwargs).call
end

Instance Method Details

#callObject



25
26
27
28
29
30
# File 'lib/gov_fake_notify/commands/send_email_command.rb', line 25

def call
  template_data = store.transaction { store["template-#{params['template_id']}"] }
  send_email_from_template(template_data)
  persist_status(template_data)
  self
end

#success?Boolean



32
33
34
# File 'lib/gov_fake_notify/commands/send_email_command.rb', line 32

def success?
  true
end

#to_json(*_args) ⇒ Object

rubocop:disable Metrics/MethodLength



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gov_fake_notify/commands/send_email_command.rb', line 36

def to_json(*_args) # rubocop:disable Metrics/MethodLength
  ::JSON.generate({
                    "id": id,
                    "reference": 'STRING',
                    "content": {
                      "body": message_body,
                      "from_number": '[email protected]'
                    },
                    "uri": "#{base_url}/v2/notifications/#{id}",
                    "template": {
                      "id": 'f33517ff-2a88-4f6e-b855-c550268ce08a',
                      "version": 1,
                      "uri": "#{base_url}/v2/template/ceb50d92-100d-4b8b-b559-14fa3b091cd"
                    }
                  })
end