Sha256: 3dbc152f81a2cb280ba1fe99157b052e839f3a21e665d431d3aaa0d38d5d2829

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

# typed: strict
# frozen_string_literal: true

require_relative "data_response"
require_relative "template_data_response"

module WhatsappSdk
  module Api
    module Responses
      class TemplatesDataResponse < DataResponse
        sig { returns(T::Array[TemplateDataResponse]) }
        attr_reader :templates

        sig { params(response: T::Hash[T.untyped, T.untyped]).void }
        def initialize(response)
          @templates = T.let(
            response['data']&.map { |template| parse_templates(template) },
            T::Array[TemplateDataResponse]
          )
          super(response)
        end

        sig { override.params(response: T::Hash[T.untyped, T.untyped]).returns(T.nilable(TemplatesDataResponse)) }
        def self.build_from_response(response:)
          return unless response["data"]

          new(response)
        end

        private

        sig { params(template: T::Hash[T.untyped, T.untyped]).returns(TemplateDataResponse) }
        def parse_templates(template)
          TemplateDataResponse.new(response: template)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
whatsapp_sdk-0.12.1 lib/whatsapp_sdk/api/responses/templates_data_response.rb
whatsapp_sdk-0.12.0 lib/whatsapp_sdk/api/responses/templates_data_response.rb
whatsapp_sdk-0.11.0 lib/whatsapp_sdk/api/responses/templates_data_response.rb
whatsapp_sdk-0.10.0 lib/whatsapp_sdk/api/responses/templates_data_response.rb