Class: GunBroker::Category

Inherits:
Object
  • Object
show all
Defined in:
lib/gun_broker/category.rb

Constant Summary collapse

ROOT_CATEGORY_ID =

The top-level category ID.

0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Category

Returns a new instance of Category


16
17
18
# File 'lib/gun_broker/category.rb', line 16

def initialize(attrs = {})
  @attrs = attrs
end

Class Method Details

.all(parent = ROOT_CATEGORY_ID) ⇒ Object


7
8
9
10
# File 'lib/gun_broker/category.rb', line 7

def self.all(parent = ROOT_CATEGORY_ID)
  response = GunBroker::API.get('/Categories', { 'ParentCategoryID' => parent })
  response['results'].map { |attrs| new(attrs) }
end

.find(category_id) ⇒ Object


12
13
14
# File 'lib/gun_broker/category.rb', line 12

def self.find(category_id)
  new(GunBroker::API.get("/Categories/#{category_id}"))
end

Instance Method Details

#idObject


20
21
22
# File 'lib/gun_broker/category.rb', line 20

def id
  @attrs['categoryID']
end