Sha256: c8b879d97166a4bac6d5946b37aa9a2b4f81e25cd350572763fef2f1ae47957f

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

module Awis
  module Models
    class CategoryListings < Base
      attr_accessor :count, :recursive_count, :listings

      def initialize(response)
        @listings = []

        super(response)
      end

      def setup_data!(response)
        category_listings = []

        response.each_node do |node, path|
          text = node.inner_xml
          text = text.to_i if text.to_i.to_s == text
          text = nil if text.class == String && text.empty?

          if node.name == 'aws:RequestId'
            @request_id ||= text
          elsif node.name == 'aws:StatusCode'
            @status_code ||= text
          elsif node.name == 'aws:Count'
            @count ||= text
          elsif node.name == 'aws:RecursiveCount'
            @recursive_count ||= text
          elsif node.name == 'aws:DataUrl' && path == "#{base_node_name}/aws:DataUrl"
            category_listings << { data_url: text }
          elsif node.name == 'aws:Title' && path == "#{base_node_name}/aws:Title"
            category_listings << { title: text }
          elsif node.name == 'aws:PopularityRank' && path == "#{base_node_name}/aws:PopularityRank"
            category_listings << { popularity_rank: text }
          elsif node.name == 'aws:Description' && path == "#{base_node_name}/aws:Description"
            category_listings << { description: text }
          end
        end

        relationship_collections(@listings, category_listings, 4, Listing)
      end

      def base_node_name
        "#{root_node_name}/aws:CategoryListings/aws:Listings/aws:Listing"
      end
    end

    class Listing < BaseEntity
      attr_accessor :data_url, :title, :popularity_rank, :description
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
awis-sdk-ruby-2.1.0 lib/awis/models/category_listings.rb