Sha256: c52334d0e672e05e6865c129f9659176852f3ccc0f49c16ff20414b5abc61a3d

Contents?: true

Size: 1.48 KB

Versions: 6

Compression:

Stored size: 1.48 KB

Contents

module Sorenson
  module Services
    class Group < Base
      attr_accessor :name, :description, :account_id, :id, :guid

      def self.create(name, attributes={})
        data = post_to("/groups", :group => attributes.merge(:name => name))
        new(data['group'])
      end
      
      def self.all
        collection = Base.get_from("/groups")
        collection.collect { |data| new(data['group'])}
      end
      
      def self.find(id)
        data = Base.get_from("/groups/#{id}")
        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)
        return new(data['group']) if data['group']
        nil
      end
      
      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["name"]
        @description = attributes["description"]
        @account_id  = attributes["account_id"]
        @id          = attributes["guid"]
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
360_services-0.0.5 lib/sorenson/services/group.rb
360_services-1.0.1 lib/sorenson/services/group.rb
360_services-1.0.0 lib/sorenson/services/group.rb
360_services-0.0.4 lib/sorenson/services/group.rb
360_services-0.0.3 lib/sorenson/services/group.rb
360_services-0.0.2 lib/sorenson/services/group.rb