Class: Doconomy::Api::Category

Inherits:
Base
  • Object
show all
Defined in:
lib/doconomy/api/category.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

client, #errors

Constructor Details

#initialize(attributes = {}) ⇒ Category

Returns a new instance of Category.



8
9
10
11
12
13
# File 'lib/doconomy/api/category.rb', line 8

def initialize(attributes = {})
  @attributes = attributes.deep_symbolize_keys
  @id = @attributes[:id]
  @main_category = OpenStruct.new(@attributes[:main_category]) if @attributes[:main_category]
  @sub_category = OpenStruct.new(@attributes[:sub_category]) if @attributes[:sub_category]
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/doconomy/api/category.rb', line 6

def id
  @id
end

#main_categoryObject

Returns the value of attribute main_category.



6
7
8
# File 'lib/doconomy/api/category.rb', line 6

def main_category
  @main_category
end

#sub_categoryObject

Returns the value of attribute sub_category.



6
7
8
# File 'lib/doconomy/api/category.rb', line 6

def sub_category
  @sub_category
end

Class Method Details

.allArray<Doconomy::Api::Category>

Get all categories

Returns:



20
21
22
23
# File 'lib/doconomy/api/category.rb', line 20

def all
  response = client.get("/aland-index/#{Doconomy::Api.configuration.api_version}/categories")
  response[:categories].map { |attributes| new(attributes) }
end

.find(id) ⇒ Doconomy::Api::Category

Get a category with the given ID



29
30
31
# File 'lib/doconomy/api/category.rb', line 29

def find(id)
  new(client.get("/aland-index/#{Doconomy::Api.configuration.api_version}/categories/#{id}"))
end