Sha256: dcc4d8b1005207e75428dcc407ae5887642c2dafe14f534177b0ba759d0d7536
Contents?: true
Size: 1.42 KB
Versions: 22
Compression:
Stored size: 1.42 KB
Contents
module Sorenson module Services class Category < Base attr_accessor :description, :name, :parent_id, :parent, :id def self.all get_from("/categories").map{|c| c["name"]} end def self.find_by_name(name) data = get_from("/categories/find_by_name", :category => {:name => name}) return new(data) unless data.blank? nil end def self.find(id) data = get_from("/categories/#{id}") return new(data) unless data.blank? end def self.create(name, options = {}) new(post_to("/categories", :category => {:name => name}.merge(options))) end def save Base.put_to("/categories/#{id}", :category => {:name => name, :description => description}, :parent_name => parent) end def destroy Base.delete_from("/categories/#{id}")["status"] end def assets Base.get_from("/categories/#{id}/assets") end def self.all_roots Base.get_from("/categories/roots").map{|category| category['name']} end def parent parent_id ? Sorenson::Services::Category.find(parent_id).name : @parent end def initialize(data) self.description = data['description'] self.name = data['name'] self.parent_id = data["parent_id"] self.id = data["id"] end end end end
Version data entries
22 entries across 22 versions & 1 rubygems
Version | Path |
---|---|
360_services-0.0.3 | lib/sorenson/services/category.rb |
360_services-0.0.2 | lib/sorenson/services/category.rb |