Module: Josef::GoogleWorkspace::Members

Included in:
Group
Defined in:
lib/josef/google_workspace/members.rb

Instance Method Summary collapse

Instance Method Details

#add_member(group_mail_address, member_mail_address) ⇒ Object



23
24
25
26
27
# File 'lib/josef/google_workspace/members.rb', line 23

def add_member(group_mail_address, member_mail_address)
  member = ::Google::Apis::AdminDirectoryV1::Member.new(email: member_mail_address)
  group = groups.find{|g| g.email == group_mail_address}
  client.insert_member(group.id, member)
end

#del_member(group_mail_address, member_mail_address) ⇒ Object



29
30
31
32
33
# File 'lib/josef/google_workspace/members.rb', line 29

def del_member(group_mail_address, member_mail_address)
  group = groups.find{|g| g.email == group_mail_address}
  member = members_by(group).find{ |member| member.email == member_mail_address }
  client.delete_member(group.id, member.id)
end

#member_mail_addreses(group) ⇒ Object



4
5
6
7
8
# File 'lib/josef/google_workspace/members.rb', line 4

def member_mail_addreses(group)
  members_by(group)&.map do | member |
    member.email
  end
end

#members_by(group) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/josef/google_workspace/members.rb', line 10

def members_by(group)
  res = client.list_members(group.id)
  members = res.members
  next_page_token = res.next_page_token
  while next_page_token.nil?.!
    res = client.list_members(group.id, page_token: next_page_token)
    next_page_token = res.next_page_token
    members.concat(res.members)
  end

  members || []
end