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

#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_group(id:, request_options: {}) ⇒ WorkOS::DirectoryGroup

Get a Directory Group

Parameters:

  • id (String)

    Unique identifier for the Directory Group.

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

    (see WorkOS::Types::RequestOptions)

Returns:



161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/workos/directory_sync.rb', line 161

def get_group(
  id:,
  request_options: {}
)
  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

Get a Directory User

Parameters:

  • id (String)

    Unique identifier for the Directory User.

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

    (see WorkOS::Types::RequestOptions)

Returns:



232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/workos/directory_sync.rb', line 232

def get_user(
  id:,
  request_options: {}
)
  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: nil, 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: nil)

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

  • order (WorkOS::Types::DirectoriesOrder, 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: nil,
  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_groups(before: nil, after: nil, limit: nil, order: "desc", directory: nil, user: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::DirectoryGroup>

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

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

  • order (WorkOS::Types::DirectoryGroupsOrder, 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.

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



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/workos/directory_sync.rb', line 114

def list_groups(
  before: nil,
  after: nil,
  limit: nil,
  order: "desc",
  directory: nil,
  user: nil,
  request_options: {}
)
  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: nil, order: "desc", directory: nil, group: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::DirectoryUserWithGroups>

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

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

  • order (WorkOS::Types::DirectoryUsersOrder, 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.

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

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

    (see WorkOS::Types::RequestOptions)

Returns:



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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/workos/directory_sync.rb', line 185

def list_users(
  before: nil,
  after: nil,
  limit: nil,
  order: "desc",
  directory: nil,
  group: nil,
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "directory" => directory,
    "group" => group
  }.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,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::DirectoryUserWithGroups,
    filters: {before: before, limit: limit, order: order, directory: directory, group: group},
    fetch_next: fetch_next
  )
end