Sha256: ba60c2bbf4678b10ed9a29f695f53c9bf8aea6cc320fabe7b709488db027b55b

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module Rapa
  module Responses
    class SearchItemsResponse < MultipleResourcesResponse
      # @return [Rapa::Error]
      def error
        if value = body.dig("ItemSearchResponse", "Items", "Request", "Errors", "Error")
          ::Rapa::Error.new(value)
        end
      end

      # @return [Boolean]
      def has_error?
        !error.nil?
      end

      # @return [Boolean]
      def has_valid_request?
        body.dig("ItemSearchResponse", "Items", "Request", "IsValid") == "True"
      end

      # @return [Integer, nil]
      def total_pages
        if value = body.dig("ItemSearchResponse", "Items", "TotalPages")
          value.to_i
        end
      end

      # @return [Integer, nil]
      def total_results
        if value = body.dig("ItemSearchResponse", "Items", "TotalResults")
          value.to_i
        end
      end

      private

      # @note Override
      def resource_class
        ::Rapa::Resources::ItemResource
      end

      # @note Override
      def source_or_sources
        body.dig("ItemSearchResponse", "Items", "Item")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rapa-0.6.0 lib/rapa/responses/multiple_resources_response/search_items_response.rb