class Etsy::Category
Category
¶ ↑
A category of listings for sale, formed from 1 to 3 tags.
A category has the following attributes:
- page_description
-
A short description of the category from the category's landing page
- page_title
-
The title of the category's landing page
- category_name
-
The category's string ID
- short_name
-
A short display name for the category
- long_name
-
A longer display name for the category
- children_count
-
The number of subcategories below this one
Public Class Methods
Retrieve a list of all top-level categories.
Etsy::Category.all
# File lib/etsy/category.rb, line 62 def self.all_top(options = {}) self.get_all("/taxonomy/categories", options) end
# File lib/etsy/category.rb, line 54 def self.find(tag) get("/categories/#{tag}") end
Retrieve a list of all subcategories of the specified category.
Etsy::Category.find_all_subcategories('accessories')
You can also find the subcategories of a subcategory.
Etsy::Category.find_all_subcategories('accessories/apron')
Etsy
categories only go three levels deep, so this will return nil past the third level.
Etsy::Category.find_all_subcategories('accessories/apron/women') => nil
# File lib/etsy/category.rb, line 50 def self.find_all_subcategories(category, options = {}) valid?(category) ? self.get_all("/taxonomy/categories/#{category}", options) : nil end
Retrieve one or more top-level categories by name:
Etsy::Category.find('accessories')
You can find multiple top-level categories by passing an array of identifiers:
Etsy::Category.find(['accessories', 'art'])
# File lib/etsy/category.rb, line 33 def self.find_top(*identifiers_and_options) self.find_one_or_more('categories', identifiers_and_options) end
Private Class Methods
# File lib/etsy/category.rb, line 80 def self.valid?(parent_category) parent_category.count("/") < 2 end
Public Instance Methods
The collection of active listings associated with this category.
# File lib/etsy/category.rb, line 68 def active_listings @active_listings ||= Listing.find_all_active_by_category(category_name) end
The collection of subcategories associated with this category.
# File lib/etsy/category.rb, line 74 def subcategories @subcategories ||= Category.find_all_subcategories(category_name) end