Class: WorkOS::Groups

Inherits:
Object
  • Object
show all
Defined in:
lib/workos/groups.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Groups

Returns a new instance of Groups.



9
10
11
# File 'lib/workos/groups.rb', line 9

def initialize(client)
  @client = client
end

Instance Method Details

#create_group_organization_membership(organization_id:, group_id:, organization_membership_id:, request_options: {}) ⇒ WorkOS::Group

Add a member to a Group

Parameters:

  • organization_id (String)

    Unique identifier of the Organization.

  • group_id (String)

    Unique identifier of the Group.

  • organization_membership_id (String)

    The ID of the Organization Membership to add to the group.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/workos/groups.rb', line 218

def create_group_organization_membership(
  organization_id:,
  group_id:,
  organization_membership_id:,
  request_options: {}
)
  body = {
    "organization_membership_id" => organization_membership_id
  }
  response = @client.request(
    method: :post,
    path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/groups/#{WorkOS::Util.encode_path(group_id)}/organization-memberships",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::Group.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#create_organization_group(organization_id:, name:, description: WorkOS::OMIT, request_options: {}) ⇒ WorkOS::Group

Create a group

Parameters:

  • organization_id (String)

    The ID of the organization.

  • name (String)

    The name of the Group.

  • description (String, nil) (defaults to: WorkOS::OMIT)

    An optional description of the Group.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/workos/groups.rb', line 70

def create_organization_group(
  organization_id:,
  name:,
  description: WorkOS::OMIT,
  request_options: {}
)
  body = {
    "name" => name
  }
  body["description"] = description unless description.equal?(WorkOS::OMIT)
  response = @client.request(
    method: :post,
    path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/groups",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::Group.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#delete_group_organization_membership(organization_id:, group_id:, om_id:, request_options: {}) ⇒ void

This method returns an undefined value.

Remove a member from a Group

Parameters:

  • organization_id (String)

    Unique identifier of the Organization.

  • group_id (String)

    Unique identifier of the Group.

  • om_id (String)

    Unique identifier of the Organization Membership.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)



245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/workos/groups.rb', line 245

def delete_group_organization_membership(
  organization_id:,
  group_id:,
  om_id:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/groups/#{WorkOS::Util.encode_path(group_id)}/organization-memberships/#{WorkOS::Util.encode_path(om_id)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#delete_organization_group(organization_id:, group_id:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete a group

Parameters:

  • organization_id (String)

    The ID of the organization.

  • group_id (String)

    The ID of the group.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)



148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/workos/groups.rb', line 148

def delete_organization_group(
  organization_id:,
  group_id:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/groups/#{WorkOS::Util.encode_path(group_id)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#get_organization_group(organization_id:, group_id:, request_options: {}) ⇒ WorkOS::Group

Get a group

Parameters:

  • organization_id (String)

    The ID of the organization.

  • group_id (String)

    The ID of the group.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/workos/groups.rb', line 97

def get_organization_group(
  organization_id:,
  group_id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/groups/#{WorkOS::Util.encode_path(group_id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::Group.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#list_group_organization_memberships(organization_id:, group_id:, before: nil, after: nil, limit: 10, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::UserOrganizationMembershipBaseListData>

List Group members

Parameters:

  • organization_id (String)

    Unique identifier of the Organization.

  • group_id (String)

    Unique identifier of the Group.

  • before (String, nil) (defaults to: nil)

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with "obj_123", your subsequent call can include before="obj_123" to fetch a new batch of objects before "obj_123".

  • after (String, nil) (defaults to: nil)

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with "obj_123", your subsequent call can include after="obj_123" to fetch a new batch of objects after "obj_123".

  • limit (Integer, nil) (defaults to: 10)

    Upper limit on the number of objects to return, between 1 and 100.

  • order (WorkOS::Types::PaginationOrder, nil) (defaults to: "desc")

    Order the results by the creation time. Supported values are "asc" (ascending), "desc" (descending), and "normal" (descending with reversed cursor semantics where before fetches older records and after fetches newer records).

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/workos/groups.rb', line 171

def list_group_organization_memberships(
  organization_id:,
  group_id:,
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order
  }.compact
  response = @client.request(
    method: :get,
    path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/groups/#{WorkOS::Util.encode_path(group_id)}/organization-memberships",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_group_organization_memberships(
      organization_id: organization_id,
      group_id: group_id,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::UserOrganizationMembershipBaseListData,
    filters: {organization_id: organization_id, group_id: group_id, before: before, limit: limit, order: order},
    fetch_next: fetch_next
  )
end

#list_organization_groups(organization_id:, before: nil, after: nil, limit: 10, order: "desc", search: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::Group>

List groups

Parameters:

  • organization_id (String)

    The ID of the organization.

  • before (String, nil) (defaults to: nil)

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with "obj_123", your subsequent call can include before="obj_123" to fetch a new batch of objects before "obj_123".

  • after (String, nil) (defaults to: nil)

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with "obj_123", your subsequent call can include after="obj_123" to fetch a new batch of objects after "obj_123".

  • limit (Integer, nil) (defaults to: 10)

    Upper limit on the number of objects to return, between 1 and 100.

  • order (WorkOS::Types::PaginationOrder, nil) (defaults to: "desc")

    Order the results by the creation time. Supported values are "asc" (ascending), "desc" (descending), and "normal" (descending with reversed cursor semantics where before fetches older records and after fetches newer records).

  • search (String, nil) (defaults to: nil)

    Search groups by name or by group ID.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/workos/groups.rb', line 22

def list_organization_groups(
  organization_id:,
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  search: nil,
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "search" => search
  }.compact
  response = @client.request(
    method: :get,
    path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/groups",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_organization_groups(
      organization_id: organization_id,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      search: search,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::Group,
    filters: {organization_id: organization_id, before: before, limit: limit, order: order, search: search},
    fetch_next: fetch_next
  )
end

#update_organization_group(organization_id:, group_id:, name: nil, description: WorkOS::OMIT, request_options: {}) ⇒ WorkOS::Group

Update a group

Parameters:

  • organization_id (String)

    The ID of the organization.

  • group_id (String)

    The ID of the group.

  • name (String, nil) (defaults to: nil)

    The name of the Group.

  • description (String, nil) (defaults to: WorkOS::OMIT)

    An optional description of the Group.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/workos/groups.rb', line 120

def update_organization_group(
  organization_id:,
  group_id:,
  name: nil,
  description: WorkOS::OMIT,
  request_options: {}
)
  body = {
    "name" => name
  }.compact
  body["description"] = description unless description.equal?(WorkOS::OMIT)
  response = @client.request(
    method: :patch,
    path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/groups/#{WorkOS::Util.encode_path(group_id)}",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::Group.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end