Class: Sorenson::Services::Group

Inherits:
Base show all
Defined in:
lib/sorenson/services/group.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(attributes) ⇒ Group

Returns a new instance of Group.



62
63
64
65
66
67
# File 'lib/sorenson/services/group.rb', line 62

def initialize(attributes)
  @name        = attributes["name"]
  @description = attributes["description"]
  @account_id  = attributes["account_id"]
  @id          = attributes["guid"]
end

Instance Attribute Details

#account_idObject

Returns the value of attribute account_id.



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

def 
  @account_id
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#guidObject

Returns the value of attribute guid.



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

def guid
  @guid
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.allObject



22
23
24
25
# File 'lib/sorenson/services/group.rb', line 22

def self.all
  collection = Base.get_from("/groups")
  collection.collect { |data| new(data['group'])}
end

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



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

def self.create(name, attributes={})
  data = post_to("/groups", :group => attributes.merge(:name => name))
  new(data['group'])
end

.find(id) ⇒ Object



27
28
29
30
31
# File 'lib/sorenson/services/group.rb', line 27

def self.find(id)
  data = Base.get_from("/groups/#{id}")
  return new(data['group']) if data['group']
  nil
end

.find_by_name(name) ⇒ Object



33
34
35
36
37
# File 'lib/sorenson/services/group.rb', line 33

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

.presets(group_id) ⇒ Object



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

def self.presets(group_id)
  get_from("/groups/#{group_id}/presets")
end

.update(name, attributes = {}) ⇒ Object



15
16
17
18
19
20
# File 'lib/sorenson/services/group.rb', line 15

def self.update(name, attributes={})
  attributes[:preset_ids] = (attributes[:preset_ids] || []).join(",")
  guid = attributes.delete(:group_id)
  data = put_to("/groups/#{guid}", :group => attributes.merge({:name => name, :id => guid}))
  new(data['group'])
end

Instance Method Details

#add_asset(asset) ⇒ Object



39
40
41
42
43
# File 'lib/sorenson/services/group.rb', line 39

def add_asset(asset)
  # If you have an Asset it memory, using this method does not update the assets state
  # You would need to "Re"-find the asset to get the update to date state
  Base.put_to("/groups/#{id}/assets/#{asset.id}")
end

#add_user(user_id) ⇒ Object



45
46
47
# File 'lib/sorenson/services/group.rb', line 45

def add_user(user_id)
  Base.put_to("/groups/#{id}/users/#{user_id}")
end

#assetsObject



49
50
51
52
# File 'lib/sorenson/services/group.rb', line 49

def assets
  collection = Base.get_from("/groups/#{id}/assets")
  collection.collect { |data| Sorenson::Services::Asset.new(data) }
end

#deleteObject



58
59
60
# File 'lib/sorenson/services/group.rb', line 58

def delete
  Base.delete_from("/groups/#{id}")
end

#usersObject



54
55
56
# File 'lib/sorenson/services/group.rb', line 54

def users
  Base.get_from("/groups/#{id}/users")
end