Class: WorkOS::OrganizationMembershipService

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

Defined Under Namespace

Classes: RoleMultiple, RoleSingle

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ OrganizationMembershipService

Returns a new instance of OrganizationMembershipService.



21
22
23
# File 'lib/workos/organization_membership_service.rb', line 21

def initialize(client)
  @client = client
end

Instance Attribute Details

#role_slugString (readonly)

Returns:

  • (String)


13
# File 'lib/workos/organization_membership_service.rb', line 13

RoleSingle = Data.define(:role_slug)

#role_slugsArray<String> (readonly)

Returns:

  • (Array<String>)


19
# File 'lib/workos/organization_membership_service.rb', line 19

RoleMultiple = Data.define(:role_slugs)

Instance Method Details

#create_organization_membership(user_id:, organization_id:, role: nil, request_options: {}) ⇒ WorkOS::OrganizationMembership

Create an organization membership

Parameters:

Returns:



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/workos/organization_membership_service.rb', line 87

def create_organization_membership(
  user_id:,
  organization_id:,
  role: nil,
  request_options: {}
)
  body = {
    "user_id" => user_id,
    "organization_id" => organization_id
  }
  if role
    case role
    when WorkOS::OrganizationMembershipService::RoleSingle
      body["role_slug"] = role.role_slug
    when WorkOS::OrganizationMembershipService::RoleMultiple
      body["role_slugs"] = role.role_slugs
    else
      raise ArgumentError, "expected role to be one of: WorkOS::OrganizationMembershipService::RoleSingle, WorkOS::OrganizationMembershipService::RoleMultiple, got #{role.class}"
    end
  end
  response = @client.request(
    method: :post,
    path: "/user_management/organization_memberships",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::OrganizationMembership.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

#deactivate_organization_membership(id:, request_options: {}) ⇒ WorkOS::OrganizationMembership

Deactivate an organization membership

Parameters:

  • id (String)

    The unique ID of the organization membership.

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

    (see WorkOS::Types::RequestOptions)

Returns:



192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/workos/organization_membership_service.rb', line 192

def deactivate_organization_membership(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :put,
    path: "/user_management/organization_memberships/#{WorkOS::Util.encode_path(id)}/deactivate",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::OrganizationMembership.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_organization_membership(id:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete an organization membership

Parameters:

  • id (String)

    The unique ID of the organization membership.

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

    (see WorkOS::Types::RequestOptions)



175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/workos/organization_membership_service.rb', line 175

def delete_organization_membership(
  id:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/user_management/organization_memberships/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#get_organization_membership(id:, request_options: {}) ⇒ WorkOS::UserOrganizationMembership

Get an organization membership

Parameters:

  • id (String)

    The unique ID of the organization membership.

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

    (see WorkOS::Types::RequestOptions)

Returns:



123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/workos/organization_membership_service.rb', line 123

def get_organization_membership(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/user_management/organization_memberships/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::UserOrganizationMembership.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_organization_membership_groups(om_id:, before: nil, after: nil, limit: 10, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::Group>

List groups

Parameters:

  • om_id (String)

    Unique identifier of the Organization Membership.

  • 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). Defaults to descending.

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

    (see WorkOS::Types::RequestOptions)

Returns:



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/workos/organization_membership_service.rb', line 234

def list_organization_membership_groups(
  om_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: "/user_management/organization_memberships/#{WorkOS::Util.encode_path(om_id)}/groups",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_organization_membership_groups(
      om_id: om_id,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::Group,
    filters: {om_id: om_id, before: before, limit: limit, order: order},
    fetch_next: fetch_next
  )
end

#list_organization_memberships(before: nil, after: nil, limit: 10, order: "desc", organization_id: nil, statuses: nil, user_id: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::UserOrganizationMembership>

List organization memberships

Parameters:

  • 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). Defaults to descending.

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

    The ID of the organization which the user belongs to.

  • statuses (Array<WorkOS::Types::UserManagementOrganizationMembershipStatuses>, nil) (defaults to: nil)

    Filter by the status of the organization membership. Array including any of active, inactive, or pending.

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

    The ID of the user.

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

    (see WorkOS::Types::RequestOptions)

Returns:



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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/workos/organization_membership_service.rb', line 35

def list_organization_memberships(
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  organization_id: nil,
  statuses: nil,
  user_id: nil,
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "organization_id" => organization_id,
    "statuses" => statuses,
    "user_id" => user_id
  }.compact
  response = @client.request(
    method: :get,
    path: "/user_management/organization_memberships",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_organization_memberships(
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      organization_id: organization_id,
      statuses: statuses,
      user_id: user_id,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::UserOrganizationMembership,
    filters: {before: before, limit: limit, order: order, organization_id: organization_id, statuses: statuses, user_id: user_id},
    fetch_next: fetch_next
  )
end

#reactivate_organization_membership(id:, request_options: {}) ⇒ WorkOS::UserOrganizationMembership

Reactivate an organization membership

Parameters:

  • id (String)

    The unique ID of the organization membership.

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

    (see WorkOS::Types::RequestOptions)

Returns:



211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/workos/organization_membership_service.rb', line 211

def reactivate_organization_membership(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :put,
    path: "/user_management/organization_memberships/#{WorkOS::Util.encode_path(id)}/reactivate",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::UserOrganizationMembership.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

#update_organization_membership(id:, role: nil, request_options: {}) ⇒ WorkOS::UserOrganizationMembership

Update an organization membership

Parameters:

Returns:



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/workos/organization_membership_service.rb', line 143

def update_organization_membership(
  id:,
  role: nil,
  request_options: {}
)
  body = {}
  if role
    case role
    when WorkOS::OrganizationMembershipService::RoleSingle
      body["role_slug"] = role.role_slug
    when WorkOS::OrganizationMembershipService::RoleMultiple
      body["role_slugs"] = role.role_slugs
    else
      raise ArgumentError, "expected role to be one of: WorkOS::OrganizationMembershipService::RoleSingle, WorkOS::OrganizationMembershipService::RoleMultiple, got #{role.class}"
    end
  end
  response = @client.request(
    method: :put,
    path: "/user_management/organization_memberships/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::UserOrganizationMembership.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