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:



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/workos/groups.rb', line 214

def create_group_organization_membership(
  organization_id:,
  group_id:,
  organization_membership_id:,
  request_options: {}
)
  body = {
    "organization_membership_id" => organization_membership_id
  }.compact
  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: nil, 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: nil)

    An optional description of the Group.

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

    (see WorkOS::Types::RequestOptions)

Returns:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/workos/groups.rb', line 66

def create_organization_group(
  organization_id:,
  name:,
  description: nil,
  request_options: {}
)
  body = {
    "name" => name,
    "description" => description
  }.compact
  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)



241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/workos/groups.rb', line 241

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)



144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/workos/groups.rb', line 144

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:



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/workos/groups.rb', line 93

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: nil, 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: nil)

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

  • order (WorkOS::Types::GroupsOrder, 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). Defaults to descending.

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

    (see WorkOS::Types::RequestOptions)

Returns:



167
168
169
170
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
# File 'lib/workos/groups.rb', line 167

def list_group_organization_memberships(
  organization_id:,
  group_id:,
  before: nil,
  after: nil,
  limit: nil,
  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: nil, order: "desc", 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: nil)

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

  • order (WorkOS::Types::GroupsOrder, 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). Defaults to descending.

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

    (see WorkOS::Types::RequestOptions)

Returns:



21
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
# File 'lib/workos/groups.rb', line 21

def list_organization_groups(
  organization_id:,
  before: nil,
  after: nil,
  limit: nil,
  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",
    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,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::Group,
    filters: {organization_id: organization_id, before: before, limit: limit, order: order},
    fetch_next: fetch_next
  )
end

#update_organization_group(organization_id:, group_id:, name: nil, description: nil, 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: nil)

    An optional description of the Group.

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

    (see WorkOS::Types::RequestOptions)

Returns:



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/workos/groups.rb', line 116

def update_organization_group(
  organization_id:,
  group_id:,
  name: nil,
  description: nil,
  request_options: {}
)
  body = {
    "name" => name,
    "description" => description
  }.compact
  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