Class: Sorenson::Services::Category
- Defined in:
- lib/sorenson/services/category.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#parent_id ⇒ Object
Returns the value of attribute parent_id.
Class Method Summary collapse
- .all ⇒ Object
- .all_roots ⇒ Object
- .create(name, options = {}) ⇒ Object
- .find(id) ⇒ Object
- .find_by_name(name) ⇒ Object
Instance Method Summary collapse
- #assets ⇒ Object
- #destroy ⇒ Object
-
#initialize(data) ⇒ Category
constructor
A new instance of Category.
- #save ⇒ Object
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
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/sorenson/services/category.rb', line 4 def description @description end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/sorenson/services/category.rb', line 4 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/sorenson/services/category.rb', line 4 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
4 5 6 |
# File 'lib/sorenson/services/category.rb', line 4 def parent @parent end |
#parent_id ⇒ Object
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
.all ⇒ Object
6 7 8 |
# File 'lib/sorenson/services/category.rb', line 6 def self.all get_from("/categories").map{|c| c["name"]} end |
.all_roots ⇒ Object
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, = {}) new(post_to("/categories", :category => {:name => name}.merge())) 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
#assets ⇒ Object
33 34 35 |
# File 'lib/sorenson/services/category.rb', line 33 def assets Base.get_from("/categories/#{id}/assets") end |
#destroy ⇒ Object
29 30 31 |
# File 'lib/sorenson/services/category.rb', line 29 def destroy Base.delete_from("/categories/#{id}")["status"] end |