Sha256: 468b7e890ba720f784950c260398bbb14b935b6812905c4509a2773b21321d5e

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'time'

module Notifications
  class Client
    class Notification
      FIELDS = %i(
        id
        reference
        email_address
        phone_number
        line_1
        line_2
        line_3
        line_4
        line_5
        line_6
        postcode
        postage
        type
        status
        template
        body
        subject
        sent_at
        created_at
        completed_at
        created_by_name
        one_click_unsubscribe_url
        cost_in_pounds
        is_cost_data_ready
        cost_details
      ).freeze

      attr_reader(*FIELDS)

      def initialize(notification)
        FIELDS.each do |field|
          instance_variable_set(:"@#{field}", notification.fetch(field.to_s, nil))
        end
      end

      %i(
        sent_at
        created_at
        completed_at
      ).each do |field|
        define_method field do
          begin
            value = instance_variable_get(:"@#{field}")
            Time.parse value
          rescue StandardError
            value
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
notifications-ruby-client-6.2.0 lib/notifications/client/notification.rb