Sha256: 9a255a39228f716a361d3a0cc98dda847b025cd3f545503fab6d7c8595fd422a

Contents?: true

Size: 883 Bytes

Versions: 1

Compression:

Stored size: 883 Bytes

Contents

# frozen_string_literal: true

require_relative "responses/message_data_response"
require_relative "responses/phone_number_data_response"
require_relative "responses/phone_numbers_data_response"
require_relative "responses/error_response"

module WhatsappSdk
  module Api
    class Response
      attr_accessor :error, :data

      CLASS_TYPE = {
        message_data_response: Responses::MessageDataResponse,
        phone_number_data_response: Responses::PhoneNumberDataResponse,
        phone_numbers_data_response: Responses::PhoneNumbersDataResponse
      }.freeze

      def initialize(response:, class_type:)
        @data = class_type.build_from_response(response: response)
        @error = Responses::ErrorResponse.build_from_response(response: response)
      end

      def ok?
        @error.nil?
      end

      def error?
        !!@error
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
whatsapp_sdk-0.0.1 lib/whatsapp_sdk/api/response.rb