Module: Gerry::Api::Groups

Included in:
Client
Defined in:
lib/gerry/api/groups.rb

Instance Method Summary collapse

Instance Method Details

#add_to_group(group_id, users) ⇒ Hash

Adds one or more users to a group

Parameters:

  • group_id (String)

    the group id

  • users (Enumberable)

    the list of users identified by email address

Returns:

  • (Hash)

    the account info details for each user added



55
56
57
58
59
60
61
# File 'lib/gerry/api/groups.rb', line 55

def add_to_group(group_id, users)
  url = "/groups/#{group_id}/members"
  body = {
    members: users
  }
  post(url, body)
end

#create_group(name, description, visible, owner_id = nil) ⇒ Hash

Create a new group

Returns:

  • (Hash)

    the group details



40
41
42
43
44
45
46
47
48
# File 'lib/gerry/api/groups.rb', line 40

def create_group(name, description, visible, owner_id=nil)
  url = "/groups/#{name}"
  body = {
    description: description,
    visible_to_all: visible,
  }
  body[:owner_id] = owner_id unless owner_id.nil? || owner_id.empty?
  put(url, body)
end

#group_members(group_id, options = []) ⇒ Array

Get all members for a group

Parameters:

  • options (Array) (defaults to: [])

    the query parameters

Returns:

  • (Array)

    the members



18
19
20
21
22
23
24
25
26
27
# File 'lib/gerry/api/groups.rb', line 18

def group_members(group_id, options = [])
  url = "/groups/#{group_id}/members/"

  if options.empty?
    return get(url)
  end

  options = map_options(options)
  get("#{url}?#{options}")
end

#groupsHash

Get all groups

Returns:

  • (Hash)

    the groups



9
10
11
12
# File 'lib/gerry/api/groups.rb', line 9

def groups
  url = '/groups/'
  get(url)
end

#included_groups(group_id) ⇒ Array

Get the directly included groups of a group

Returns:

  • (Array)

    the included groups



32
33
34
35
# File 'lib/gerry/api/groups.rb', line 32

def included_groups(group_id)
  url = "/groups/#{group_id}/groups/"
  get(url)
end

#remove_from_group(group_id, users) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/gerry/api/groups.rb', line 63

def remove_from_group(group_id, users)
  url = "/groups/#{group_id}/members.delete"
  body = {
    members: users
  }
  post(url, body)
end