Sha256: 6e8090b4efc53eeaeeaa4eab3e46af8e861be2ce77ddcf4b92cc9e78b4c357b8

Contents?: true

Size: 1.03 KB

Versions: 4

Compression:

Stored size: 1.03 KB

Contents

# typed: strict
# frozen_string_literal: true

module WhatsappSdk
  module Resource
    class InteractiveFooter
      extend T::Sig

      # Returns Text string if the parameter object type is text.
      # For the body interactive, the character limit is 60 characters.
      #
      # @returns text [String]
      sig { returns(String) }
      attr_accessor :text

      sig do
        params(text: String).void
      end
      def initialize(text:)
        @text = text
        validate
      end

      sig { returns(T::Hash[T.untyped, T.untyped]) }
      def to_json
        { text: text }
      end

      MAXIMUM_LENGTH = 60

      private

      sig { void }
      def validate
        validate_text
      end

      sig { void }
      def validate_text
        text_length = text.length
        return if text_length <= MAXIMUM_LENGTH

        raise WhatsappSdk::Resource::Error::InvalidInteractiveFooter,
              "Invalid length #{text_length} for text in footer. Maximum length: #{MAXIMUM_LENGTH} characters."
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
whatsapp_sdk-0.9.2 lib/whatsapp_sdk/resource/interactive_footer.rb
whatsapp_sdk-0.9.1 lib/whatsapp_sdk/resource/interactive_footer.rb
whatsapp_sdk-0.9.0 lib/whatsapp_sdk/resource/interactive_footer.rb
whatsapp_sdk-0.8.0 lib/whatsapp_sdk/resource/interactive_footer.rb