Sha256: 996ba85b15e97d2ec0d350fd85c7ac4b5287876794804fd4469a5af5a0dd057e

Contents?: true

Size: 1.71 KB

Versions: 6

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

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

      def initialize(response)
        @listings = []
        setup_data! loading_response(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

6 entries across 6 versions & 2 rubygems

Version Path
awis-sdk-ruby-2.0.0 lib/awis/models/category_listings.rb
awis-sdk-ruby-1.1.2 lib/awis/models/category_listings.rb
awis-sdk-ruby_-1.1.1.1 lib/awis/models/category_listings.rb
awis-sdk-ruby_-1.1.1p1 lib/awis/models/category_listings.rb
awis-sdk-ruby-1.1.1 lib/awis/models/category_listings.rb
awis-sdk-ruby-1.1.0 lib/awis/models/category_listings.rb