Sha256: ecdb646f2cfe478f63fbc0d053252f7f875a4ae4a714d0742c650aec74ce0901

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

module Awis
  module API
    class CategoryBrowse < Base
      DEFAULT_RESPONSE_GROUP = %w(categories related_categories language_categories letter_bars).freeze

      def fetch(arguments = {})
        raise ArgumentError.new("Valid category path (Top/Arts, Top/Business/Automotive)") unless arguments.has_key?(:path)
        @arguments = arguments

        @arguments[:response_group] = Array(arguments.fetch(:response_group, DEFAULT_RESPONSE_GROUP))
        @arguments[:descriptions]   = arguments.fetch(:descriptions, true)

        @response_body = Awis::Connection.new.get(params)
        self
      end

      private
      def params
        {
          "Action"        => action_name,
          "ResponseGroup" => response_groups,
          "Path"          => arguments[:path],
          "Descriptions"  => descriptions_params
        }
      end

      def response_groups
        arguments[:response_group].sort.map { |group| camelize(group) }.join(",")
      end

      def descriptions_params
        arguments[:descriptions].to_s.capitalize
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
awis-sdk-ruby-0.0.4 lib/awis/api/category_browse.rb
awis-sdk-ruby-0.0.3 lib/awis/api/category_browse.rb
awis-sdk-ruby-0.0.1 lib/awis/api/category_browse.rb