Class: EcwidApi::Api::Categories

Inherits:
Base
  • Object
show all
Defined in:
lib/ecwid_api/api/categories.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from EcwidApi::Api::Base

Instance Method Details

#all(params = {}) ⇒ Object

Public: Returns all of the sub-categories for a given category

See: kb.ecwid.com/w/page/25285101/Product%20API#RESTAPIMethodcategories

parent - The Category ID of the parent category. If the parent is 0 then

a list of the root categories will be returned. If the parent is
nil, then all of the categories will be returned

Returns an array of EcwidApi::Category objects



15
16
17
18
19
# File 'lib/ecwid_api/api/categories.rb', line 15

def all(params = {})
  PagedEcwidResponse.new(client, "categories", params) do |category_hash|
    Category.new(category_hash, client: client)
  end.sort_by(&:order_by)
end

#create(params) ⇒ Object

Public: Creates a new Category

params - a Hash of API keys and their corresponding values

Returns a new Category entity



50
51
52
53
# File 'lib/ecwid_api/api/categories.rb', line 50

def create(params)
  response = client.post("categories", params)
  find(response.body["id"])
end

#find(id) ⇒ Object

Public: Returns a single EcwidApi::Category

See: kb.ecwid.com/w/page/25285101/Product%20API#RESTAPIMethodcategory

category_id - A Category ID to get

Returns an EcwidApi::Category, or nil if it can’t be found



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ecwid_api/api/categories.rb', line 33

def find(id)
  response = client.get("categories/#{id}")

  if response.success?
    Category.new(response.body, client: client)
  else
    nil
  end
rescue Zlib::BufError
  nil
end

#root(params = {}) ⇒ Object

Public: Returns an Array of the root level EcwidApi::Category objects



22
23
24
# File 'lib/ecwid_api/api/categories.rb', line 22

def root(params = {})
  all(params.merge(parent: 0))
end