Class: Apress::YandexMarket::Readers::Category

Inherits:
Base
  • Object
show all
Defined in:
lib/apress/yandex_market/readers/category.rb

Overview

Ридер категорий. Читает из API Яндекс.Маркета переданные категории и их подкатегории

Examples

reader = Apress::YandexMarket::Readers::Category.new(region_id: 225,
                                                     token: 'qwerty',
                                                     categories: 'Авто; Дом и дача')
# => #<Apress::YandexMarket::Readers::Category ...>

reader.each_row |category|
  puts category
end
# => {
       :id=>90402,
       :name=>"Авто",
       :fullName=>"Товары для авто- и мототехники",
       :link=>
         "https://market.yandex.ru/catalog/90402/list?hid=90402&onstock=1&pp=1001&clid=2326601&distr_type=7",
       :childCount=>12,
       :advertisingModel=>"HYBRID",
       :viewType=>"LIST"
     }
     {
       :id=>90403,
       ...
     }

Constant Summary collapse

FIELDS =
%w(PARENT).join(',').freeze

Constants inherited from Base

Base::DEFAULT_REGION_ID, Base::PAGE_SIZE, Base::RETRY_ATTEMPTS, Base::RETRY_ATTEMPTS_SLEEP_TIME, Base::RETRY_CODES, Base::SLEEP_TIME

Instance Attribute Summary

Attributes inherited from Base

#client

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Category

Public: инициализация ридера

options - Hash, параметры ридера

:region_id  - 

Returns an instance of Readers::Category



50
51
52
53
# File 'lib/apress/yandex_market/readers/category.rb', line 50

def initialize(options)
  super
  @categories = options.fetch(:categories).split(';').map(&:squish)
end

Class Method Details

.allowed_optionsObject



37
38
39
# File 'lib/apress/yandex_market/readers/category.rb', line 37

def allowed_options
  super + i(categories)
end

Instance Method Details

#each_rowObject

Public: читаем категории из API и для каждой выполняем блок

Returns nothing



58
59
60
61
62
63
64
65
66
# File 'lib/apress/yandex_market/readers/category.rb', line 58

def each_row
  root_categories.each do |root_category|
    yield root_category

    get_children_categories(root_category[:id]) do |category|
      yield category
    end
  end
end