Class: Svpply::Category

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Category

Returns a new instance of Category.



9
10
11
12
13
14
15
# File 'lib/svpply/category.rb', line 9

def initialize(hash)
  @name = hash["name"]
  @url = hash["url"]
  @children = hash["children"].nil? ? [] : hash["children"].map { |c| Category.new(c) }
  @api_url = @url[25, 1000]
  self
end

Instance Attribute Details

#api_urlObject (readonly)

Returns the value of attribute api_url.



3
4
5
# File 'lib/svpply/category.rb', line 3

def api_url
  @api_url
end

#childrenObject (readonly)

Returns the value of attribute children.



3
4
5
# File 'lib/svpply/category.rb', line 3

def children
  @children
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/svpply/category.rb', line 3

def name
  @name
end

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/svpply/category.rb', line 3

def url
  @url
end

Class Method Details

.allObject



5
6
7
# File 'lib/svpply/category.rb', line 5

def self.all
  CategoryCollection.new(Client.get_response('/shop/categories.json')).categories
end

Instance Method Details

#products(attrs = nil) ⇒ Object



17
18
19
# File 'lib/svpply/category.rb', line 17

def products(attrs=nil)
  ProductCollection.new(Client.get_response(@api_url, attrs)).products
end