Class: Etsy::Category

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
lib/etsy/category.rb

Overview

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model

included, #initialize, #result, #secret, #token

Class Method Details

.all_top(options = {}) ⇒ Object

Retrieve a list of all top-level categories.

Etsy::Category.all


62
63
64
# File 'lib/etsy/category.rb', line 62

def self.all_top(options = {})
  self.get_all("/taxonomy/categories", options)
end

.find(tag) ⇒ Object



54
55
56
# File 'lib/etsy/category.rb', line 54

def self.find(tag)
  get("/categories/#{tag}")
end

.find_all_subcategories(category, options = {}) ⇒ Object

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


50
51
52
# 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

.find_top(*identifiers_and_options) ⇒ Object

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'])


33
34
35
# File 'lib/etsy/category.rb', line 33

def self.find_top(*identifiers_and_options)
  self.find_one_or_more('categories', identifiers_and_options)
end

Instance Method Details

#active_listingsObject

The collection of active listings associated with this category.



68
69
70
# File 'lib/etsy/category.rb', line 68

def active_listings
  @active_listings ||= Listing.find_all_active_by_category(category_name)
end

#subcategoriesObject

The collection of subcategories associated with this category.



74
75
76
# File 'lib/etsy/category.rb', line 74

def subcategories
  @subcategories ||= Category.find_all_subcategories(category_name)
end