Sha256: 58cf10c1224dbabe18a5602a13ba0ce2fb800d1d79d1e3a99136c000e0bca201

Contents?: true

Size: 969 Bytes

Versions: 2

Compression:

Stored size: 969 Bytes

Contents

module Notifications
  class Client
    class Notification
      FIELDS = [
        :id,
        :reference,
        :email_address,
        :phone_number,
        :line_1,
        :line_2,
        :line_3,
        :line_4,
        :line_5,
        :line_6,
        :postcode,
        :type,
        :status,
        :template,
        :body,
        :subject,
        :sent_at,
        :created_at,
        :completed_at
      ].freeze

      attr_reader(*FIELDS)

      def initialize(notification)

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

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

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
notifications-ruby-client-2.1.0 lib/notifications/client/notification.rb
notifications-ruby-client-2.0.0 lib/notifications/client/notification.rb