Class: SFRest::Group
- Inherits:
-
Object
- Object
- SFRest::Group
- Defined in:
- lib/sfrest/group.rb
Overview
SF Group management
Instance Method Summary collapse
-
#add_members(group_id, uids) ⇒ Hash
Add users to this group.
-
#add_sites(group_id, site_ids) ⇒ Hash
Add sites to this group.
-
#create_group(groupname) ⇒ Object
Creates a site group with specified group name.
-
#delete_group(group_id) ⇒ Object
Deletes the group with the specified id.
-
#demote_from_admins(group_id, uids) ⇒ Hash
Demote users from group admins.
-
#get_group(group_id = 0) ⇒ Hash
Gets a site group with a specified group id.
-
#get_members(group_id = 0) ⇒ Hash
Gets all users that are members of this group.
-
#group_list ⇒ Hash
Gets a list of all site groups.
-
#initialize(conn) ⇒ Group
constructor
A new instance of Group.
-
#promote_to_admins(group_id, uids) ⇒ Hash
Promote users to group admins.
-
#remove_members(group_id, uids) ⇒ Hash
Remove members from this group.
-
#remove_sites(group_id, site_ids) ⇒ Hash
Remove sites from this group.
-
#rename_group(group_id, groupname) ⇒ Object
Renames existing group.
Constructor Details
#initialize(conn) ⇒ Group
Returns a new instance of Group.
5 6 7 |
# File 'lib/sfrest/group.rb', line 5 def initialize(conn) @conn = conn end |
Instance Method Details
#add_members(group_id, uids) ⇒ Hash
Add users to this group
54 55 56 57 58 |
# File 'lib/sfrest/group.rb', line 54 def add_members(group_id, uids) current_path = '/api/v1/groups/' + group_id.to_s + '/members' payload = { 'uids' => uids.map(&:to_i) }.to_json @conn.post(current_path, payload) end |
#add_sites(group_id, site_ids) ⇒ Hash
Add sites to this group
94 95 96 97 98 |
# File 'lib/sfrest/group.rb', line 94 def add_sites(group_id, site_ids) current_path = '/api/v1/groups/' + group_id.to_s + '/sites' payload = { 'site_ids' => site_ids }.to_json @conn.post(current_path, payload) end |
#create_group(groupname) ⇒ Object
Creates a site group with specified group name. This currently will only create a group in the root
12 13 14 15 16 |
# File 'lib/sfrest/group.rb', line 12 def create_group(groupname) current_path = '/api/v1/groups' payload = { 'group_name' => groupname }.to_json @conn.post(current_path, payload) end |
#delete_group(group_id) ⇒ Object
Deletes the group with the specified id
20 21 22 23 |
# File 'lib/sfrest/group.rb', line 20 def delete_group(group_id) current_path = '/api/v1/groups/' << group_id.to_s @conn.delete(current_path) end |
#demote_from_admins(group_id, uids) ⇒ Hash
Demote users from group admins
84 85 86 87 88 |
# File 'lib/sfrest/group.rb', line 84 def demote_from_admins(group_id, uids) current_path = '/api/v1/groups/' + group_id.to_s + '/admins' payload = { 'uids' => uids.map(&:to_i) }.to_json @conn.delete(current_path, payload) end |
#get_group(group_id = 0) ⇒ Hash
Gets a site group with a specified group id.
37 38 39 40 |
# File 'lib/sfrest/group.rb', line 37 def get_group(group_id = 0) current_path = '/api/v1/groups/' << group_id.to_s @conn.get(current_path) end |
#get_members(group_id = 0) ⇒ Hash
Gets all users that are members of this group
45 46 47 48 |
# File 'lib/sfrest/group.rb', line 45 def get_members(group_id = 0) current_path = '/api/v1/groups/' + group_id.to_s + '/members' @conn.get(current_path) end |
#group_list ⇒ Hash
Gets a list of all site groups. this will iterate through the group pages
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/sfrest/group.rb', line 114 def group_list page = 1 not_done = true count = 0 while not_done current_path = '/api/v1/groups?page=' << page.to_s res = @conn.get(current_path) if res['groups'] == [] not_done = false elsif !res['message'].nil? return { 'message' => res['message'] } elsif page == 1 count = res['count'] groups = res['groups'] else res['groups'].each do |group| groups << group end end page += 1 end { 'count' => count, 'groups' => groups } end |
#promote_to_admins(group_id, uids) ⇒ Hash
Promote users to group admins
74 75 76 77 78 |
# File 'lib/sfrest/group.rb', line 74 def promote_to_admins(group_id, uids) current_path = '/api/v1/groups/' + group_id.to_s + '/admins' payload = { 'uids' => uids.map(&:to_i) }.to_json @conn.post(current_path, payload) end |
#remove_members(group_id, uids) ⇒ Hash
Remove members from this group
64 65 66 67 68 |
# File 'lib/sfrest/group.rb', line 64 def remove_members(group_id, uids) current_path = '/api/v1/groups/' + group_id.to_s + '/members' payload = { 'uids' => uids.map(&:to_i) }.to_json @conn.delete(current_path, payload) end |
#remove_sites(group_id, site_ids) ⇒ Hash
Remove sites from this group
104 105 106 107 108 |
# File 'lib/sfrest/group.rb', line 104 def remove_sites(group_id, site_ids) current_path = '/api/v1/groups/' + group_id.to_s + '/sites' payload = { 'site_ids' => site_ids }.to_json @conn.delete(current_path, payload) end |
#rename_group(group_id, groupname) ⇒ Object
Renames existing group.
28 29 30 31 32 |
# File 'lib/sfrest/group.rb', line 28 def rename_group(group_id, groupname) current_path = '/api/v1/groups/' + group_id.to_s + '/update' payload = { 'group_name' => groupname }.to_json @conn.put(current_path, payload) end |