lib/sorenson/services/group.rb in 360_services-0.0.1 vs lib/sorenson/services/group.rb in 360_services-0.0.2
- old
+ new
@@ -1,41 +1,57 @@
module Sorenson
module Services
class Group < Base
- attr_accessor :name, :description, :account_id, :id, :assets
+ attr_accessor :name, :description, :account_id, :id, :guid
def self.create(name, attributes={})
- new(post_to("/groups", :group => attributes.merge(:name => name)))
+ data = post_to("/groups", :group => attributes.merge(:name => name))
+ new(data['group'])
end
-
- def add_asset(asset)
- self.assets = Base.put_to("/groups/#{id}/assets/#{asset.id}")
- end
def self.all
- Base.get_from("/groups")
+ collection = Base.get_from("/groups")
+ collection.collect { |data| new(data['group'])}
end
def self.find(id)
data = Base.get_from("/groups/#{id}")
- new(data) if data['group']
+ return new(data['group']) if data['group']
+ nil
end
def self.find_by_name(name)
data = Base.get_from("/groups/find_by_name", :name => name)
- new(data) if data['group']
+ return new(data['group']) if data['group']
+ nil
end
- def destroy
+ def add_asset(asset)
+ Base.put_to("/groups/#{id}/assets/#{asset.id}")
+ end
+
+ def add_user(user_id)
+ Base.put_to("/groups/#{id}/users/#{user_id}")
+ end
+
+ def assets
+ collection = Base.get_from("/groups/#{id}/assets")
+ collection.collect { |data| Sorenson::Services::Asset.new(data) }
+ end
+
+ def users
+ Base.get_from("/groups/#{id}/users")
+ end
+
+ def delete
Base.delete_from("/groups/#{id}")
end
def initialize(attributes)
- @name = attributes['group']["name"]
- @description = attributes['group']["description"]
- @account_id = attributes['group']["account_id"]
- @id = attributes['group']["guid"]
- @assets = attributes['group']["asset_ids"]
+ @name = attributes["name"]
+ @description = attributes["description"]
+ @account_id = attributes["account_id"]
+ @id = attributes["guid"]
end
end
end
end
\ No newline at end of file