Sha256: 27d714c93911572d055678b3dda77130b1f7220b0e9037475c74741d56efb315

Contents?: true

Size: 768 Bytes

Versions: 5

Compression:

Stored size: 768 Bytes

Contents

# frozen_string_literal: true

require 'mail'
require 'erb'
require 'tilt'
require 'gov_fake_notify/store'

module GovFakeNotify
  # A service used to fetch a message status
  class FetchMessageStatusCommand

    attr_reader :errors

    def self.call(id, **kwargs)
      new(id, **kwargs).call
    end

    def initialize(id, store: Store.instance)
      @id = id
      @store = store
      @errors = []
      @message = nil
    end

    def call
      @message = store.transaction { store.fetch("message-#{id}") }
      errors << 'Message not found' and return if message.nil?

      self
    end

    def success?
      errors.empty?
    end

    def to_json
      JSON.pretty_generate(message)
    end

    private

    attr_reader :id, :store, :message
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gov_fake_notify-2.0.0 lib/gov_fake_notify/commands/fetch_message_status_command.rb
gov_fake_notify-1.2.0 lib/gov_fake_notify/commands/fetch_message_status_command.rb
gov_fake_notify-1.1.3 lib/gov_fake_notify/commands/fetch_message_status_command.rb
gov_fake_notify-1.1.2 lib/gov_fake_notify/commands/fetch_message_status_command.rb
gov_fake_notify-1.1.1 lib/gov_fake_notify/commands/fetch_message_status_command.rb