Sha256: 8c661923a10efa2c3ea79307d2fd5ce162e3cded4c1bcf4e0c26cf5e39436024

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

module CmSms
  module Webhook
    class Response

      ATTRIBUTE_NAMES = %w(sent received to reference statuscode errorcode errordescription)
      
      attr_reader *ATTRIBUTE_NAMES
      
      def initialize(attributes = {})
        attributes.each { |attr, value| instance_variable_set("@#{attr}", value) } if attributes
      end
      
      def sent?
        !sent.to_s.strip.empty?
      end
      
      def received?
        !received.to_s.strip.empty?
      end
      
      def statuscode?
        !statuscode.to_s.strip.empty?
      end
      
      def errorcode?
        !errorcode.to_s.strip.empty?
      end
      
      def sent_at
        Time.parse(sent) if sent?
      end
      
      def received_at
        Time.parse(received) if received?
      end
      
      def accepted?
        statuscode? && statuscode.to_s == '0'
      end
      
      def rejected?
        statuscode? && statuscode.to_s == '1'
      end
      
      def delivered?
        statuscode? && statuscode.to_s == '2'
      end
      
      def failed?
        statuscode? && statuscode.to_s == '3'
      end
      
      def error?
        errorcode? || rejected? || failed?
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cm-sms-0.2.3 lib/cm_sms/webhook/response.rb
cm-sms-0.2.2 lib/cm_sms/webhook/response.rb
cm-sms-0.2.1 lib/cm_sms/webhook/response.rb
cm-sms-0.2.0 lib/cm_sms/webhook/response.rb