Class: Ecircle::Group
- Inherits:
-
Base
- Object
- Base
- Ecircle::Group
show all
- Defined in:
- lib/ecircle/group.rb
Instance Attribute Summary
Attributes inherited from Base
#all_fields, #id, #named_attrs
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#[], #init_with_xml, #method_missing
Constructor Details
#initialize(hsh = nil) ⇒ Group
Returns a new instance of Group.
25
26
27
28
29
|
# File 'lib/ecircle/group.rb', line 25
def initialize(hsh = nil)
super()
@all_fields = hsh || {}
@id = self[:id]
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Ecircle::Base
Class Method Details
.all ⇒ Object
14
15
16
|
# File 'lib/ecircle/group.rb', line 14
def all
find_all_by_name("")
end
|
.find_all_by_name(group_name) ⇒ Object
4
5
6
7
|
# File 'lib/ecircle/group.rb', line 4
def find_all_by_name(group_name)
ary = Ecircle.client.lookup_groups :lookupParams => { :groupName => group_name }
ary.is_a?(Array) ? ary.collect { |a| Ecircle::Group.new(a) } : []
end
|
.find_by_id(idstr) ⇒ Object
18
19
20
21
22
|
# File 'lib/ecircle/group.rb', line 18
def find_by_id(idstr)
all.reject { |a| a.id != idstr }.first
end
|
.find_by_name(group_name) ⇒ Object
9
10
11
12
|
# File 'lib/ecircle/group.rb', line 9
def find_by_name(group_name)
hsh = Ecircle.client.lookup_groups :lookupParams => { :groupName => group_name }
hsh.is_a?(Hash) ? Group.new(hsh) : raise("Group name #{group_name} not unique")
end
|
Instance Method Details
#add_member(user, send_invite = false, send_message = false) ⇒ Object
Make a user a member of a group. Can be called multiple times for the same user, eCircle checks for duplicates based on the email or whatever. Returns a member object.
34
35
36
37
38
39
|
# File 'lib/ecircle/group.rb', line 34
def add_member(user, send_invite = false, send_message = false)
member_id = Ecircle.client.
create_member(:userId => user.id, :groupId => @id,
:invite => send_invite, :sendMessage => send_message)
Ecircle::Member.find_by_id(member_id)
end
|
#clone(with_name, with_email, keep_owner = true) ⇒ Object
53
54
55
56
57
|
# File 'lib/ecircle/group.rb', line 53
def clone(with_name, with_email, keep_owner = true)
Ecircle.client.
clone_group(:templateGroupId => @id, :newGroupEmail => with_email,
:newGroupName => with_name, :keepOwner => keep_owner)
end
|
#delete ⇒ Object
59
60
61
|
# File 'lib/ecircle/group.rb', line 59
def delete
Ecircle.client.delete_group :groupId => @id
end
|
#remove_member(member, send_message = false) ⇒ Object
45
46
47
|
# File 'lib/ecircle/group.rb', line 45
def remove_member(member, send_message = false)
member.user.leave_group(self, send_message)
end
|
#remove_user(user, send_message = false) ⇒ Object
41
42
43
|
# File 'lib/ecircle/group.rb', line 41
def remove_user(user, send_message = false)
user.leave_group(self, send_message)
end
|
#to_xml ⇒ Object
63
64
65
66
67
68
69
70
71
|
# File 'lib/ecircle/group.rb', line 63
def to_xml
Savon::SOAP::XML.new.xml do |x|
x.group(:id => @id) do |u|
u.name(@id)
end
end
end
|