Sha256: e7473083d10982aa2808523650c5c7b1894a045464685b42a196103fbdfb98d4

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module Rapa
  module Responses
    class LookupBrowseNodeResponse < SingleResourceResponse
      # @return [Rapa::Error, nil]
      def error
        if value = body.dig("BrowseNodeLookupErrorResponse", "Error")
          ::Rapa::Error.new(value)
        end
      end

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

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

      # @return [Array<Rapa::Resources::BrowseNodeResource>, nil]
      def response_group(group)
        item = sources.find { |source| source["Type"] == group }
        unless item.nil?
          item["TopItem"].map do |source|
            resource_class.new(source)
          end
        end
      end

      private

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

      # @note Override
      def source_or_sources
        body.dig("BrowseNodeLookupResponse", "BrowseNodes", "BrowseNode", "TopItemSet")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rapa-0.6.0 lib/rapa/responses/single_resource_response/lookup_browse_node_response.rb