Module: WorkOS::DirectorySync

Extended by:
Client
Defined in:
lib/workos/directory_sync.rb

Overview

The Directory Sync module provides convenience methods for working with the WorkOS Directory Sync platform. You’ll need a valid API key and to have created a Directory Sync connection on your WorkOS dashboard.

Class Method Summary collapse

Methods included from Client

client, delete_request, execute_request, get_request, handle_error_response, post_request, put_request, user_agent

Class Method Details

.delete_directory(id) ⇒ Object

Delete the directory with the given ID.

Parameters:

  • id (String)

    The ID of the directory.

Returns:

  • Boolean



186
187
188
189
190
191
192
193
194
195
# File 'lib/workos/directory_sync.rb', line 186

def delete_directory(id)
  request = delete_request(
    auth: true,
    path: "/directories/#{id}",
  )

  response = execute_request(request: request)

  response.is_a? Net::HTTPSuccess
end

.get_directory(id:) ⇒ WorkOS::Directory

Retrieve directory.

Examples:

WorkOS::SSO.get_directory(id: 'directory_01FK17DWRHH7APAFXT5B52PV0W')
=> #<WorkOS::Directory:0x00007fb6e4193d20
      @id="directory_01FK17DWRHH7APAFXT5B52PV0W",
      @name="Foo Corp",
      @domain="foo-corp.com",
      @type="okta scim v2.0",
      @state="linked",
      @organization_id="org_01F6Q6TFP7RD2PF6J03ANNWDKV",
      @created_at="2021-10-27T15:55:47.856Z",
      @updated_at="2021-10-27T16:03:43.990Z"

Parameters:

  • id (String)

    Directory unique identifier

Returns:



66
67
68
69
70
71
72
73
74
75
# File 'lib/workos/directory_sync.rb', line 66

def get_directory(id:)
  request = get_request(
    auth: true,
    path: "/directories/#{id}",
  )

  response = execute_request(request: request)

  WorkOS::Directory.new(response.body)
end

.get_group(id) ⇒ Object

Retrieve the directory group with the given ID.

Parameters:

  • id (String)

    The ID of the directory group.

Returns:

  • WorkOS::DirectoryGroup



154
155
156
157
158
159
160
161
162
163
# File 'lib/workos/directory_sync.rb', line 154

def get_group(id)
  response = execute_request(
    request: get_request(
      path: "/directory_groups/#{id}",
      auth: true,
    ),
  )

  ::WorkOS::DirectoryGroup.new(response.body)
end

.get_user(id) ⇒ Object

Retrieve the directory user with the given ID.

Parameters:

  • id (String)

    The ID of the directory user.

Returns:

  • WorkOS::DirectoryUser



170
171
172
173
174
175
176
177
178
179
# File 'lib/workos/directory_sync.rb', line 170

def get_user(id)
  response = execute_request(
    request: get_request(
      path: "/directory_users/#{id}",
      auth: true,
    ),
  )

  ::WorkOS::DirectoryUser.new(response.body)
end

.list_directories(options = {}) ⇒ Hash

Retrieve directories.

Parameters:

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

    An options hash

Options Hash (options):

  • search (String)

    A search term for direcory names.

  • limit (String)

    Maximum number of records to return.

  • order (String)

    The order in which to paginate records

  • before (String)

    Pagination cursor to receive records before a provided Directory ID.

  • after (String)

    Pagination cursor to receive records before a provided Directory ID.

  • organization_id (String)

    The ID for an Organization configured on WorkOS.

Returns:

  • (Hash)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/workos/directory_sync.rb', line 28

def list_directories(options = {})
  options[:order] ||= 'desc'
  response = execute_request(
    request: get_request(
      path: '/directories',
      auth: true,
      params: options,
    ),
  )

  parsed_response = JSON.parse(response.body)
  directories = parsed_response['data'].map do |directory|
    ::WorkOS::Directory.new(directory.to_json)
  end

  WorkOS::Types::ListStruct.new(
    data: directories,
    list_metadata: parsed_response['listMetadata'],
  )
end

.list_groups(options = {}) ⇒ WorkOS::DirectoryGroup

Retrieve directory groups.

Parameters:

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

    An options hash

Options Hash (options):

  • directory (String)

    The ID of the directory whose directory groups will be retrieved.

  • user (String)

    The ID of the directory user whose directory groups will be retrieved.

  • limit (String)

    Maximum number of records to return.

  • order (String)

    The order in which to paginate records

  • before (String)

    Pagination cursor to receive records before a provided Directory Group ID.

  • after (String)

    Pagination cursor to receive records before a provided Directory Group ID.

Returns:



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/workos/directory_sync.rb', line 92

def list_groups(options = {})
  options[:order] ||= 'desc'
  response = execute_request(
    request: get_request(
      path: '/directory_groups',
      auth: true,
      params: options,
    ),
  )

  parsed_response = JSON.parse(response.body)
  groups = parsed_response['data'].map do |group|
    ::WorkOS::DirectoryGroup.new(group.to_json)
  end

  WorkOS::Types::ListStruct.new(
    data: groups,
    list_metadata: parsed_response['listMetadata'],
  )
end

.list_users(options = {}) ⇒ WorkOS::DirectoryUser

Retrieve directory users.

Parameters:

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

    An options hash

Options Hash (options):

  • directory (String)

    The ID of the directory whose directory users will be retrieved.

  • user (String)

    The ID of the directory group whose directory users will be retrieved.

  • limit (String)

    Maximum number of records to return.

  • order (String)

    The order in which to paginate records

  • before (String)

    Pagination cursor to receive records before a provided Directory User ID.

  • after (String)

    Pagination cursor to receive records before a provided Directory User ID.

Returns:



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/workos/directory_sync.rb', line 128

def list_users(options = {})
  options[:order] ||= 'desc'
  response = execute_request(
    request: get_request(
      path: '/directory_users',
      auth: true,
      params: options,
    ),
  )

  parsed_response = JSON.parse(response.body)
  users = parsed_response['data'].map do |user|
    ::WorkOS::DirectoryUser.new(user.to_json)
  end

  WorkOS::Types::ListStruct.new(
    data: users,
    list_metadata: parsed_response['listMetadata'],
  )
end