Class: Sorenson::Services::Category

Inherits:
Base show all
Defined in:
lib/sorenson/services/category.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

delete_from, get_from, host, login_no_resource, parse_response, post_to, put_to, verify_account_settings

Constructor Details

#initialize(data) ⇒ Category

Returns a new instance of Category.



45
46
47
48
49
50
# File 'lib/sorenson/services/category.rb', line 45

def initialize(data)
  self.description = data['description']
  self.name = data['name']
  self.parent_id = data["parent_id"]
  self.id = data["id"] 
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/sorenson/services/category.rb', line 4

def description
  @description
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/sorenson/services/category.rb', line 4

def id
  @id
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/sorenson/services/category.rb', line 4

def name
  @name
end

#parentObject

Returns the value of attribute parent.



4
5
6
# File 'lib/sorenson/services/category.rb', line 4

def parent
  @parent
end

#parent_idObject

Returns the value of attribute parent_id.



4
5
6
# File 'lib/sorenson/services/category.rb', line 4

def parent_id
  @parent_id
end

Class Method Details

.allObject



6
7
8
# File 'lib/sorenson/services/category.rb', line 6

def self.all
  get_from("/categories").map{|c| c["name"]}
end

.all_rootsObject



37
38
39
# File 'lib/sorenson/services/category.rb', line 37

def self.all_roots
  Base.get_from("/categories/roots").map{|category| category['name']}
end

.create(name, options = {}) ⇒ Object



21
22
23
# File 'lib/sorenson/services/category.rb', line 21

def self.create(name, options = {})
  new(post_to("/categories", :category => {:name => name}.merge(options)))
end

.find(id) ⇒ Object



16
17
18
19
# File 'lib/sorenson/services/category.rb', line 16

def self.find(id)
  data = get_from("/categories/#{id}")
  return new(data) unless data.blank?
end

.find_by_name(name) ⇒ Object



10
11
12
13
14
# File 'lib/sorenson/services/category.rb', line 10

def self.find_by_name(name)
  data = get_from("/categories/find_by_name", :category => {:name => name})
  return new(data) unless data.blank?
  nil
end

Instance Method Details

#assetsObject



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

def assets
  Base.get_from("/categories/#{id}/assets")
end

#destroyObject



29
30
31
# File 'lib/sorenson/services/category.rb', line 29

def destroy
  Base.delete_from("/categories/#{id}")["status"]
end

#saveObject



25
26
27
# File 'lib/sorenson/services/category.rb', line 25

def save
  Base.put_to("/categories/#{id}", :category => {:name => name, :description => description}, :parent_name => parent)
end