Class: WorkOS::DirectorySync

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ DirectorySync

Returns a new instance of DirectorySync.



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

def initialize(client)
  @client = client
end

Instance Method Details

#create_directory_sync(id:, request_options: {}) ⇒ WorkOS::DirectorySyncResponse

Sync a Directory

Parameters:

  • id (String) —

    Unique identifier for the Directory.

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

    (see WorkOS::Types::RequestOptions)

Returns:



109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/workos/directory_sync.rb', line 109

def create_directory_sync(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :post,
    path: "/directories/#{WorkOS::Util.encode_path(id)}/sync",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::DirectorySyncResponse.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_directory(id:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete a Directory

Parameters:

  • id (String) —

    Unique identifier for the Directory.

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

    (see WorkOS::Types::RequestOptions)



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/workos/directory_sync.rb', line 92

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

#get_directory(id:, request_options: {}) ⇒ WorkOS::Directory

Get a Directory

Parameters:

  • id (String) —

    Unique identifier for the Directory.

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

    (see WorkOS::Types::RequestOptions)

Returns:



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/workos/directory_sync.rb', line 73

def get_directory(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/directories/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::Directory.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

#get_directory_group(directory_id:, group_id:, request_options: {}) ⇒ WorkOS::DirectoryGroup

Get a Group for a Directory

Parameters:

  • directory_id (String) —

    Unique identifier of the Directory.

  • group_id (String) —

    Unique identifier for the Directory Group.

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

    (see WorkOS::Types::RequestOptions)

Returns:



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/workos/directory_sync.rb', line 180

def get_directory_group(
  directory_id:,
  group_id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/directories/#{WorkOS::Util.encode_path(directory_id)}/groups/#{WorkOS::Util.encode_path(group_id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::DirectoryGroup.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

#get_directory_user(directory_id:, user_id:, request_options: {}) ⇒ WorkOS::DirectoryUser

Get a User for a Directory

Parameters:

  • directory_id (String) —

    Unique identifier of the Directory.

  • user_id (String) —

    Unique identifier for the Directory User.

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

    (see WorkOS::Types::RequestOptions)

Returns:



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/workos/directory_sync.rb', line 260

def get_directory_user(
  directory_id:,
  user_id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/directories/#{WorkOS::Util.encode_path(directory_id)}/users/#{WorkOS::Util.encode_path(user_id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::DirectoryUser.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

#get_group(id:, request_options: {}) ⇒ WorkOS::DirectoryGroup

Deprecated.

Get a Directory Group

Parameters:

  • id (String) —

    Unique identifier for the Directory Group.

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

    (see WorkOS::Types::RequestOptions)

Returns:



335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/workos/directory_sync.rb', line 335

def get_group(
  id:,
  request_options: {}
)
  warn "[DEPRECATION] `get_group` is deprecated.", uplevel: 1
  response = @client.request(
    method: :get,
    path: "/directory_groups/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::DirectoryGroup.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

#get_user(id:, request_options: {}) ⇒ WorkOS::DirectoryUserWithGroups

Deprecated.

Get a Directory User

Parameters:

  • id (String) —

    Unique identifier for the Directory User.

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

    (see WorkOS::Types::RequestOptions)

Returns:



418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/workos/directory_sync.rb', line 418

def get_user(
  id:,
  request_options: {}
)
  warn "[DEPRECATION] `get_user` is deprecated.", uplevel: 1
  response = @client.request(
    method: :get,
    path: "/directory_users/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::DirectoryUserWithGroups.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_directories(before: nil, after: nil, limit: 10, order: "desc", organization_id: nil, search: nil, domain: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::Directory>

List Directories

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.

  • 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.

  • 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.

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

    Filter Directories by their associated organization.

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

    Searchable text to match against Directory names.

  • domain (String, nil) (defaults to: nil) —

    (deprecated) Filter Directories by their associated domain.

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

    (see WorkOS::Types::RequestOptions)

Returns:



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
63
64
65
66
67
# File 'lib/workos/directory_sync.rb', line 23

def list_directories(
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  organization_id: nil,
  search: nil,
  domain: nil,
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "organization_id" => organization_id,
    "search" => search,
    "domain" => domain
  }.compact
  response = @client.request(
    method: :get,
    path: "/directories",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_directories(
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      organization_id: organization_id,
      search: search,
      domain: domain,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::Directory,
    filters: {before: before, limit: limit, order: order, organization_id: organization_id, search: search, domain: domain},
    fetch_next: fetch_next
  )
end

#list_directory_groups(directory_id:, before: nil, after: nil, limit: 10, order: "desc", user: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::DirectoryGroup>

List Groups for a Directory

Parameters:

  • directory_id (String) —

    Unique identifier of the Directory.

  • 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).

  • user (String, nil) (defaults to: nil) —

    Filter Directory Groups to those this Directory User belongs to.

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

    (see WorkOS::Types::RequestOptions)

Returns:



133
134
135
136
137
138
139
140
141
142
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
170
171
172
173
# File 'lib/workos/directory_sync.rb', line 133

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

#list_directory_users(directory_id:, before: nil, after: nil, limit: 10, order: "desc", group: nil, idp_id: nil, email: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::DirectoryUser>

List Users for a Directory

Parameters:

  • directory_id (String) —

    Unique identifier of the Directory.

  • 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).

  • group (String, nil) (defaults to: nil) —

    Filter Directory Users to the members of this Directory Group.

  • idp_id (String, nil) (defaults to: nil) —

    Filter Directory Users by the identity provider's unique identifier (idp_id).

  • email (String, nil) (defaults to: nil) —

    Filter Directory Users by their primary email address.

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

    (see WorkOS::Types::RequestOptions)

Returns:



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/workos/directory_sync.rb', line 207

def list_directory_users(
  directory_id:,
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  group: nil,
  idp_id: nil,
  email: nil,
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "group" => group,
    "idp_id" => idp_id,
    "email" => email
  }.compact
  response = @client.request(
    method: :get,
    path: "/directories/#{WorkOS::Util.encode_path(directory_id)}/users",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_directory_users(
      directory_id: directory_id,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      group: group,
      idp_id: idp_id,
      email: email,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::DirectoryUser,
    filters: {directory_id: directory_id, before: before, limit: limit, order: order, group: group, idp_id: idp_id, email: email},
    fetch_next: fetch_next
  )
end

#list_groups(before: nil, after: nil, limit: 10, order: "desc", directory: nil, user: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::DirectoryGroup>

Deprecated.

List Directory Groups

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).

  • directory (String, nil) (defaults to: nil) —

    Unique identifier of the WorkOS Directory. This value can be obtained from the WorkOS dashboard or from the WorkOS API.

  • user (String, nil) (defaults to: nil) —

    Unique identifier of the WorkOS Directory User. This value can be obtained from the WorkOS API.

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

    (see WorkOS::Types::RequestOptions)

Returns:



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/workos/directory_sync.rb', line 286

def list_groups(
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  directory: nil,
  user: nil,
  request_options: {}
)
  warn "[DEPRECATION] `list_groups` is deprecated.", uplevel: 1
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "directory" => directory,
    "user" => user
  }.compact
  response = @client.request(
    method: :get,
    path: "/directory_groups",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_groups(
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      directory: directory,
      user: user,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::DirectoryGroup,
    filters: {before: before, limit: limit, order: order, directory: directory, user: user},
    fetch_next: fetch_next
  )
end

#list_users(before: nil, after: nil, limit: 10, order: "desc", directory: nil, group: nil, idp_id: nil, email: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::DirectoryUserWithGroups>

Deprecated.

List Directory Users

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).

  • directory (String, nil) (defaults to: nil) —

    Unique identifier of the WorkOS Directory. This value can be obtained from the WorkOS dashboard or from the WorkOS API.

  • group (String, nil) (defaults to: nil) —

    Unique identifier of the WorkOS Directory Group. This value can be obtained from the WorkOS API.

  • idp_id (String, nil) (defaults to: nil) —

    Filter Directory Users by the identity provider's unique identifier (idp_id). Requires the directory parameter to also be provided.

  • email (String, nil) (defaults to: nil) —

    Filter Directory Users by their primary email address. Requires the directory parameter to also be provided.

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

    (see WorkOS::Types::RequestOptions)

Returns:



363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# File 'lib/workos/directory_sync.rb', line 363

def list_users(
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  directory: nil,
  group: nil,
  idp_id: nil,
  email: nil,
  request_options: {}
)
  warn "[DEPRECATION] `list_users` is deprecated.", uplevel: 1
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "directory" => directory,
    "group" => group,
    "idp_id" => idp_id,
    "email" => email
  }.compact
  response = @client.request(
    method: :get,
    path: "/directory_users",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_users(
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      directory: directory,
      group: group,
      idp_id: idp_id,
      email: email,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::DirectoryUserWithGroups,
    filters: {before: before, limit: limit, order: order, directory: directory, group: group, idp_id: idp_id, email: email},
    fetch_next: fetch_next
  )
end