workos 0.9.2 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -1
  3. data/.ruby-version +1 -1
  4. data/.semaphore/semaphore.yml +8 -2
  5. data/Gemfile.lock +49 -36
  6. data/README.md +15 -15
  7. data/docs/WorkOS/SSO.html +235 -235
  8. data/docs/file.README.html +20 -20
  9. data/lib/workos.rb +3 -0
  10. data/lib/workos/client.rb +25 -4
  11. data/lib/workos/connection.rb +8 -1
  12. data/lib/workos/directory.rb +53 -0
  13. data/lib/workos/directory_group.rb +44 -0
  14. data/lib/workos/directory_sync.rb +63 -7
  15. data/lib/workos/directory_user.rb +60 -0
  16. data/lib/workos/passwordless.rb +0 -2
  17. data/lib/workos/portal.rb +1 -7
  18. data/lib/workos/profile.rb +3 -4
  19. data/lib/workos/sso.rb +150 -17
  20. data/lib/workos/types.rb +3 -0
  21. data/lib/workos/types/connection_struct.rb +2 -0
  22. data/lib/workos/types/directory_group_struct.rb +13 -0
  23. data/lib/workos/types/directory_struct.rb +16 -0
  24. data/lib/workos/types/directory_user_struct.rb +18 -0
  25. data/lib/workos/types/intent_enum.rb +1 -0
  26. data/lib/workos/version.rb +1 -1
  27. data/sorbet/rbi/gems/addressable.rbi +199 -0
  28. data/sorbet/rbi/gems/ast.rbi +49 -0
  29. data/sorbet/rbi/gems/codecov.rbi +37 -0
  30. data/sorbet/rbi/gems/crack.rbi +62 -0
  31. data/sorbet/rbi/gems/docile.rbi +36 -0
  32. data/sorbet/rbi/gems/hashdiff.rbi +66 -0
  33. data/sorbet/rbi/gems/parallel.rbi +83 -0
  34. data/sorbet/rbi/gems/parser.rbi +1429 -0
  35. data/sorbet/rbi/gems/public_suffix.rbi +104 -0
  36. data/sorbet/rbi/gems/rainbow.rbi +118 -0
  37. data/sorbet/rbi/gems/rake.rbi +644 -0
  38. data/sorbet/rbi/gems/regexp_parser.rbi +926 -0
  39. data/sorbet/rbi/gems/rexml.rbi +628 -0
  40. data/sorbet/rbi/gems/rspec-core.rbi +1898 -0
  41. data/sorbet/rbi/gems/rspec-expectations.rbi +1127 -0
  42. data/sorbet/rbi/gems/rspec-mocks.rbi +1099 -0
  43. data/sorbet/rbi/gems/rspec-support.rbi +280 -0
  44. data/sorbet/rbi/gems/rspec.rbi +15 -0
  45. data/sorbet/rbi/gems/rubocop-ast.rbi +1355 -0
  46. data/sorbet/rbi/gems/rubocop.rbi +7253 -0
  47. data/sorbet/rbi/gems/ruby-progressbar.rbi +304 -0
  48. data/sorbet/rbi/gems/simplecov-html.rbi +35 -0
  49. data/sorbet/rbi/gems/simplecov.rbi +406 -0
  50. data/sorbet/rbi/gems/unicode-display_width.rbi +17 -0
  51. data/sorbet/rbi/gems/vcr.rbi +572 -0
  52. data/sorbet/rbi/gems/webmock.rbi +556 -0
  53. data/sorbet/rbi/gems/yard.rbi +1165 -0
  54. data/sorbet/rbi/sorbet-typed/lib/rake/all/rake.rbi +645 -0
  55. data/sorbet/rbi/sorbet-typed/lib/rspec-core/all/rspec-core.rbi +1891 -0
  56. data/sorbet/rbi/sorbet-typed/lib/rubocop/~>0.85/rubocop.rbi +2072 -0
  57. data/sorbet/rbi/sorbet-typed/lib/yard/all/yard.rbi +1214 -0
  58. data/sorbet/rbi/todo.rbi +1 -3
  59. data/spec/lib/workos/audit_trail_spec.rb +0 -8
  60. data/spec/lib/workos/directory_sync_spec.rb +347 -40
  61. data/spec/lib/workos/passwordless_spec.rb +0 -8
  62. data/spec/lib/workos/portal_spec.rb +18 -11
  63. data/spec/lib/workos/sso_spec.rb +299 -29
  64. data/spec/spec_helper.rb +2 -1
  65. data/spec/support/fixtures/vcr_cassettes/audit_trail/get_events.yml +2 -2
  66. data/spec/support/fixtures/vcr_cassettes/directory_sync/delete_directory.yml +72 -0
  67. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_after.yml +72 -0
  68. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_before.yml +72 -0
  69. data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_directories_with_domain_param.yml → list_directories/with_domain.yml} +19 -9
  70. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_limit.yml +74 -0
  71. data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_directories.yml → list_directories/with_no_options.yml} +1 -1
  72. data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_users_with_directory_param.yml → list_directories/with_search.yml} +22 -11
  73. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_after.yml +76 -0
  74. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_before.yml +74 -0
  75. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_directory.yml +78 -0
  76. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_limit.yml +74 -0
  77. data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_groups.yml → list_groups/with_no_options.yml} +16 -6
  78. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_user.yml +72 -0
  79. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_after.yml +86 -0
  80. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_before.yml +75 -0
  81. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_directory.yml +93 -0
  82. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_group.yml +76 -0
  83. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_limit.yml +75 -0
  84. data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_users.yml → list_users/with_no_options.yml} +16 -6
  85. data/spec/support/fixtures/vcr_cassettes/portal/generate_link_dsync.yml +72 -0
  86. data/spec/support/fixtures/vcr_cassettes/portal/{generate_link.yml → generate_link_sso.yml} +1 -1
  87. data/spec/support/fixtures/vcr_cassettes/sso/create_connection_with_valid_source.yml +3 -3
  88. data/spec/support/fixtures/vcr_cassettes/sso/delete_connection_with_invalid_id.yml +72 -0
  89. data/spec/support/fixtures/vcr_cassettes/sso/delete_connection_with_valid_id.yml +70 -0
  90. data/spec/support/fixtures/vcr_cassettes/{directory_sync/list_groups_with_directory_param.yml → sso/get_connection_with_invalid_id.yml} +21 -11
  91. data/spec/support/fixtures/vcr_cassettes/sso/get_connection_with_valid_id.yml +74 -0
  92. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_after.yml +73 -0
  93. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_before.yml +73 -0
  94. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_connection_type.yml +73 -0
  95. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_domain.yml +72 -0
  96. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_limit.yml +74 -0
  97. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_no_options.yml +73 -0
  98. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_organization_id.yml +72 -0
  99. data/workos.gemspec +2 -0
  100. metadata +109 -28
  101. data/sorbet/rbi/hidden-definitions/errors.txt +0 -24896
  102. data/sorbet/rbi/hidden-definitions/hidden.rbi +0 -38411
  103. data/sorbet/rbi/sorbet-typed/lib/bundler/all/bundler.rbi +0 -8684
  104. data/sorbet/rbi/sorbet-typed/lib/ruby/all/gem.rbi +0 -4222
  105. data/sorbet/rbi/sorbet-typed/lib/ruby/all/open3.rbi +0 -111
  106. data/sorbet/rbi/sorbet-typed/lib/ruby/all/resolv.rbi +0 -543
@@ -5,9 +5,9 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title>
7
7
  File: README
8
-
8
+
9
9
  &mdash; Documentation by YARD 0.9.22
10
-
10
+
11
11
  </title>
12
12
 
13
13
  <link rel="stylesheet" href="css/style.css" type="text/css" />
@@ -35,14 +35,14 @@
35
35
  <div id="main" tabindex="-1">
36
36
  <div id="header">
37
37
  <div id="menu">
38
-
39
- <a href="_index.html">Index</a> &raquo;
38
+
39
+ <a href="_index.html">Index</a> &raquo;
40
40
  <span class="title">File: README</span>
41
-
41
+
42
42
  </div>
43
43
 
44
44
  <div id="search">
45
-
45
+
46
46
  <a class="full_list_link" id="class_list_link"
47
47
  href="class_list.html">
48
48
 
@@ -52,7 +52,7 @@
52
52
  <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
53
53
  </svg>
54
54
  </a>
55
-
55
+
56
56
  </div>
57
57
  <div class="clear"></div>
58
58
  </div>
@@ -139,7 +139,7 @@
139
139
 
140
140
  <p>See our Ruby SSO example app for a <a href="https://github.com/workos-inc/ruby-sso-example">complete example</a>.</p>
141
141
 
142
- <pre class="code ruby"><code class="ruby">WorkOS::SSO.authorization_url(domain:, project_id:, redirect_uri:, state: {})
142
+ <pre class="code ruby"><code class="ruby">WorkOS::SSO.authorization_url(domain:, client_id:, redirect_uri:, state: {})
143
143
  </code></pre>
144
144
 
145
145
  <blockquote>
@@ -150,27 +150,27 @@
150
150
  <ul><li>
151
151
  <p><code>domain</code> (string) — the authenticating user&#39;s company domain, without protocol (ex. <code>example.com</code>)</p>
152
152
  </li><li>
153
- <p><code>project_id</code> (string) — your application&#39;s WorkOS <a href="https://dashboard.workos.com/sso/configuration">Project ID</a> (ex. <code>project_01JG3BCPTRTSTTWQR4VSHXGWCQ</code>)</p>
153
+ <p><code>client_id</code> (string) — your application&#39;s WorkOS <a href="https://dashboard.workos.com/sso/configuration">Client ID</a> (ex. <code>project_01JG3BCPTRTSTTWQR4VSHXGWCQ</code>)</p>
154
154
  </li><li>
155
155
  <p><code>state</code> (optional, hash) — an optional hash used to manage state across authorization transactions (ex. <code>{ next_page: &#39;/docs&#39;}</code>)</p>
156
156
  </li><li>
157
- <p><code>redirect_uri</code> (string) — a callback URL where your application redirects the user-agent after an authorization code is granted (ex. <code>workos.dev/callback</code>). This must match one of your configured callback URLs for the associated project on your WorkOS dashboard.</p>
157
+ <p><code>redirect_uri</code> (string) — a callback URL where your application redirects the user-agent after an authorization code is granted (ex. <code>workos.dev/callback</code>). This must match one of your configured callback URLs for the associated environment on your WorkOS dashboard.</p>
158
158
  </li></ul>
159
159
 
160
160
  <p>This method will return an OAuth2 query string of the form:</p>
161
161
 
162
- <p><code>https://${domain}/sso/authorize?response_type=code&client_id=${projectID}&redirect_uri=${redirectURI}&state=${state}</code></p>
162
+ <p><code>https://${domain}/sso/authorize?response_type=code&client_id=${clientID}&redirect_uri=${redirectURI}&state=${state}</code></p>
163
163
 
164
164
  <p>For example, when used in a <a href="http://sinatrarb.com/">Sinatra app</a>:</p>
165
165
 
166
166
  <pre class="code ruby"><code class="ruby"><span class='const'>DOMAIN</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>example.com</span><span class='tstring_end'>&#39;</span></span>
167
- <span class='const'>PROJECT_ID</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>{projectId}</span><span class='tstring_end'>&#39;</span></span>
167
+ <span class='const'>CLIENT_ID</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>{clientId}</span><span class='tstring_end'>&#39;</span></span>
168
168
  <span class='const'>REDIRECT_URI</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>http://localhost:4567/callback</span><span class='tstring_end'>&#39;</span></span>
169
169
 
170
170
  <span class='id identifier rubyid_get'>get</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>/auth</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>do</span>
171
171
  <span class='id identifier rubyid_authorization_url'>authorization_url</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="WorkOS.html" title="WorkOS (module)">WorkOS</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="WorkOS/SSO.html" title="WorkOS::SSO (module)">SSO</a></span></span><span class='period'>.</span><span class='id identifier rubyid_authorization_url'><span class='object_link'><a href="WorkOS/SSO.html#authorization_url-class_method" title="WorkOS::SSO.authorization_url (method)">authorization_url</a></span></span><span class='lparen'>(</span>
172
172
  <span class='label'>domain:</span> <span class='const'>DOMAIN</span><span class='comma'>,</span>
173
- <span class='label'>project_id:</span> <span class='const'>PROJECT_ID</span><span class='comma'>,</span>
173
+ <span class='label'>client_id:</span> <span class='const'>CLIENT_ID</span><span class='comma'>,</span>
174
174
  <span class='label'>redirect_uri:</span> <span class='const'>REDIRECT_URI</span><span class='comma'>,</span>
175
175
  <span class='rparen'>)</span>
176
176
 
@@ -180,11 +180,11 @@
180
180
 
181
181
  <p>The user would be redirected to:</p>
182
182
 
183
- <p><code>https://api.workos.com/sso/authorize?response_type=code&client_id={projectID}&redirect_uri=http://localhost:4567/callback</code></p>
183
+ <p><code>https://api.workos.com/sso/authorize?response_type=code&client_id={clientID}&redirect_uri=http://localhost:4567/callback</code></p>
184
184
 
185
185
  <p>WorkOS takes over from here, sending the user to authenticate with their IDP, and on successful login, returns the user to your callback URL with a <code>code</code> parameter. You&#39;ll use <code>WorkOS::SSO.profile</code> to exchange the code for a <code>WorkOS::Profile</code>.</p>
186
186
 
187
- <pre class="code ruby"><code class="ruby">WorkOS::SSO.profile(code:, project_id:)&lt;/h4&gt;
187
+ <pre class="code ruby"><code class="ruby">WorkOS::SSO.profile(code:, client_id:)&lt;/h4&gt;
188
188
  </code></pre>
189
189
 
190
190
  <blockquote>
@@ -195,7 +195,7 @@
195
195
  <ul><li>
196
196
  <p><code>code</code> (string) — an opaque string provided by the authorization server; will be exchanged for an Access Token when the user&#39;s profile is sent</p>
197
197
  </li><li>
198
- <p><code>project_id</code> (string) — your application&#39;s WorkOS <a href="https://dashboard.workos.com/sso/configuration">Project ID</a> (ex. <code>project_01JG3BCPTRTSTTWQR4VSHXGWCQ</code>)</p>
198
+ <p><code>client_id</code> (string) — your application&#39;s WorkOS <a href="https://dashboard.workos.com/sso/configuration">Client ID</a> (ex. <code>project_01JG3BCPTRTSTTWQR4VSHXGWCQ</code>)</p>
199
199
  </li></ul>
200
200
 
201
201
  <p>This method will return an instance of a <code>WorkOS::Profile</code> with the following attributes:</p>
@@ -213,13 +213,13 @@
213
213
  <p>Our Sintatra app can be extended to use this method:</p>
214
214
 
215
215
  <pre class="code ruby"><code class="ruby"><span class='const'>DOMAIN</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>example.com</span><span class='tstring_end'>&#39;</span></span>
216
- <span class='const'>PROJECT_ID</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>{projectId}</span><span class='tstring_end'>&#39;</span></span>
216
+ <span class='const'>CLIENT_ID</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>{clientId}</span><span class='tstring_end'>&#39;</span></span>
217
217
  <span class='const'>REDIRECT_URI</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>http://localhost:4567/callback</span><span class='tstring_end'>&#39;</span></span>
218
218
 
219
219
  <span class='id identifier rubyid_get'>get</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>/auth</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>do</span>
220
220
  <span class='id identifier rubyid_authorization_url'>authorization_url</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="WorkOS.html" title="WorkOS (module)">WorkOS</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="WorkOS/SSO.html" title="WorkOS::SSO (module)">SSO</a></span></span><span class='period'>.</span><span class='id identifier rubyid_authorization_url'><span class='object_link'><a href="WorkOS/SSO.html#authorization_url-class_method" title="WorkOS::SSO.authorization_url (method)">authorization_url</a></span></span><span class='lparen'>(</span>
221
221
  <span class='label'>domain:</span> <span class='const'>DOMAIN</span><span class='comma'>,</span>
222
- <span class='label'>project_id:</span> <span class='const'>PROJECT_ID</span><span class='comma'>,</span>
222
+ <span class='label'>client_id:</span> <span class='const'>CLIENT_ID</span><span class='comma'>,</span>
223
223
  <span class='label'>redirect_uri:</span> <span class='const'>REDIRECT_URI</span><span class='comma'>,</span>
224
224
  <span class='rparen'>)</span>
225
225
 
@@ -229,7 +229,7 @@
229
229
  <span class='id identifier rubyid_get'>get</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>/callback</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>do</span>
230
230
  <span class='id identifier rubyid_profile'>profile</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="WorkOS.html" title="WorkOS (module)">WorkOS</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="WorkOS/SSO.html" title="WorkOS::SSO (module)">SSO</a></span></span><span class='period'>.</span><span class='id identifier rubyid_profile'><span class='object_link'><a href="WorkOS/SSO.html#profile-class_method" title="WorkOS::SSO.profile (method)">profile</a></span></span><span class='lparen'>(</span>
231
231
  <span class='label'>code:</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>code</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='comma'>,</span>
232
- <span class='label'>project_id:</span> <span class='const'>PROJECT_ID</span><span class='comma'>,</span>
232
+ <span class='label'>client_id:</span> <span class='const'>CLIENT_ID</span><span class='comma'>,</span>
233
233
  <span class='rparen'>)</span>
234
234
 
235
235
  <span class='id identifier rubyid_session'>session</span><span class='lbracket'>[</span><span class='symbol'>:user</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_profile'>profile</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span>
@@ -249,4 +249,4 @@
249
249
 
250
250
  </div>
251
251
  </body>
252
- </html>
252
+ </html>
data/lib/workos.rb CHANGED
@@ -32,11 +32,14 @@ module WorkOS
32
32
  autoload :AuditTrail, 'workos/audit_trail'
33
33
  autoload :Connection, 'workos/connection'
34
34
  autoload :DirectorySync, 'workos/directory_sync'
35
+ autoload :Directory, 'workos/directory'
36
+ autoload :DirectoryGroup, 'workos/directory_group'
35
37
  autoload :Organization, 'workos/organization'
36
38
  autoload :Passwordless, 'workos/passwordless'
37
39
  autoload :Portal, 'workos/portal'
38
40
  autoload :Profile, 'workos/profile'
39
41
  autoload :SSO, 'workos/sso'
42
+ autoload :DirectoryUser, 'workos/directory_user'
40
43
 
41
44
  # Errors
42
45
  autoload :APIError, 'workos/errors'
data/lib/workos/client.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ # typed: false
3
3
 
4
4
  module WorkOS
5
5
  # A Net::HTTP based API client for interacting with the WorkOS API
@@ -19,7 +19,7 @@ module WorkOS
19
19
 
20
20
  sig do
21
21
  params(
22
- request: T.any(Net::HTTP::Get, Net::HTTP::Post),
22
+ request: T.any(Net::HTTP::Get, Net::HTTP::Post, Net::HTTP::Delete),
23
23
  ).returns(::T.untyped)
24
24
  end
25
25
  def execute_request(request:)
@@ -69,6 +69,27 @@ module WorkOS
69
69
  request
70
70
  end
71
71
 
72
+ sig do
73
+ params(
74
+ path: String,
75
+ auth: T.nilable(T::Boolean),
76
+ params: T.nilable(Hash),
77
+ ).returns(Net::HTTP::Delete)
78
+ end
79
+ def delete_request(path:, auth: false, params: {})
80
+ uri = URI(path)
81
+ uri.query = URI.encode_www_form(params) if params
82
+
83
+ request = Net::HTTP::Delete.new(
84
+ uri.to_s,
85
+ 'Content-Type' => 'application/json',
86
+ )
87
+
88
+ request['Authorization'] = "Bearer #{WorkOS.key!}" if auth
89
+ request['User-Agent'] = user_agent
90
+ request
91
+ end
92
+
72
93
  sig { returns(String) }
73
94
  def user_agent
74
95
  engine = defined?(::RUBY_ENGINE) ? ::RUBY_ENGINE : 'Ruby'
@@ -81,7 +102,7 @@ module WorkOS
81
102
  ].join('; ')
82
103
  end
83
104
 
84
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity
105
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
85
106
  sig { params(response: ::T.untyped).void }
86
107
  def handle_error_response(response:)
87
108
  http_status = response.code.to_i
@@ -118,7 +139,7 @@ module WorkOS
118
139
  )
119
140
  end
120
141
  end
121
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity
142
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
122
143
 
123
144
  private
124
145
 
@@ -8,7 +8,8 @@ module WorkOS
8
8
  class Connection
9
9
  extend T::Sig
10
10
 
11
- attr_accessor :id, :name, :connection_type, :domains
11
+ attr_accessor :id, :name, :connection_type, :domains, :organization_id,
12
+ :status
12
13
 
13
14
  sig { params(json: String).void }
14
15
  def initialize(json)
@@ -18,6 +19,8 @@ module WorkOS
18
19
  @name = T.let(raw.name, String)
19
20
  @connection_type = T.let(raw.connection_type, String)
20
21
  @domains = T.let(raw.domains, Array)
22
+ @organization_id = T.let(raw.organization_id, String)
23
+ @status = T.let(raw.status, String)
21
24
  end
22
25
 
23
26
  def to_json(*)
@@ -26,6 +29,8 @@ module WorkOS
26
29
  name: name,
27
30
  connection_type: connection_type,
28
31
  domains: domains,
32
+ organization_id: organization_id,
33
+ status: status,
29
34
  }
30
35
  end
31
36
 
@@ -40,6 +45,8 @@ module WorkOS
40
45
  name: hash[:name],
41
46
  connection_type: hash[:connection_type],
42
47
  domains: hash[:domains],
48
+ organization_id: hash[:organization_id],
49
+ status: hash[:status],
43
50
  )
44
51
  end
45
52
  end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ module WorkOS
5
+ # The Directory class provides a lightweight wrapper around
6
+ # a WorkOS Directory resource. This class is not meant to be instantiated
7
+ # in user space, and is instantiated internally but exposed.
8
+ class Directory
9
+ extend T::Sig
10
+
11
+ attr_accessor :id, :domain, :name, :type, :state
12
+
13
+ sig { params(json: String).void }
14
+ def initialize(json)
15
+ raw = parse_json(json)
16
+
17
+ @id = T.let(raw.id, String)
18
+ @name = T.let(raw.name, String)
19
+ @domain = T.let(raw.domain, String)
20
+ @type = T.let(raw.type, String)
21
+ @state = T.let(raw.state, String)
22
+ end
23
+
24
+ def to_json(*)
25
+ {
26
+ id: id,
27
+ name: name,
28
+ domain: domain,
29
+ type: type,
30
+ state: state,
31
+ }
32
+ end
33
+
34
+ private
35
+
36
+ sig do
37
+ params(
38
+ json_string: String,
39
+ ).returns(WorkOS::Types::DirectoryStruct)
40
+ end
41
+ def parse_json(json_string)
42
+ hash = JSON.parse(json_string, symbolize_names: true)
43
+
44
+ WorkOS::Types::DirectoryStruct.new(
45
+ id: hash[:id],
46
+ name: hash[:name],
47
+ domain: hash[:domain],
48
+ type: hash[:type],
49
+ state: hash[:state],
50
+ )
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ module WorkOS
5
+ # The DirectoryGroup class provides a lightweight wrapper around
6
+ # a WorkOS DirectoryGroup resource. This class is not meant to be instantiated
7
+ # in user space, and is instantiated internally but exposed.
8
+ class DirectoryGroup
9
+ extend T::Sig
10
+
11
+ attr_accessor :id, :name
12
+
13
+ sig { params(json: String).void }
14
+ def initialize(json)
15
+ raw = parse_json(json)
16
+
17
+ @id = T.let(raw.id, String)
18
+ @name = T.let(raw.name, String)
19
+ end
20
+
21
+ def to_json(*)
22
+ {
23
+ id: id,
24
+ name: name,
25
+ }
26
+ end
27
+
28
+ private
29
+
30
+ sig do
31
+ params(
32
+ json_string: String,
33
+ ).returns(WorkOS::Types::DirectoryGroupStruct)
34
+ end
35
+ def parse_json(json_string)
36
+ hash = JSON.parse(json_string, symbolize_names: true)
37
+
38
+ WorkOS::Types::DirectoryGroupStruct.new(
39
+ id: hash[:id],
40
+ name: hash[:name],
41
+ )
42
+ end
43
+ end
44
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ # typed: strict
3
3
 
4
4
  require 'net/http'
5
5
 
@@ -21,12 +21,17 @@ module WorkOS
21
21
  # @option options [String] domain The domain of the directory to be
22
22
  # retrieved.
23
23
  # @option options [String] search A search term for direcory names.
24
+ # @option options [String] limit Maximum number of records to return.
25
+ # @option options [String] before Pagination cursor to receive records
26
+ # before a provided Directory ID.
27
+ # @option options [String] after Pagination cursor to receive records
28
+ # before a provided Directory ID.
24
29
  #
25
30
  # @return [Hash]
26
31
  sig do
27
32
  params(
28
33
  options: T::Hash[Symbol, String],
29
- ).returns(T::Array[T::Hash[String, T.nilable(String)]])
34
+ ).returns(WorkOS::Types::ListStruct)
30
35
  end
31
36
  def list_directories(options = {})
32
37
  response = execute_request(
@@ -37,7 +42,15 @@ module WorkOS
37
42
  ),
38
43
  )
39
44
 
40
- JSON.parse(response.body)['data']
45
+ parsed_response = JSON.parse(response.body)
46
+ directories = parsed_response['data'].map do |directory|
47
+ ::WorkOS::Directory.new(directory.to_json)
48
+ end
49
+
50
+ WorkOS::Types::ListStruct.new(
51
+ data: directories,
52
+ list_metadata: parsed_response['listMetadata'],
53
+ )
41
54
  end
42
55
 
43
56
  # Retrieve directory groups.
@@ -47,12 +60,17 @@ module WorkOS
47
60
  # directory groups will be retrieved.
48
61
  # @option options [String] user The ID of the directory user whose
49
62
  # directory groups will be retrieved.
63
+ # @option options [String] limit Maximum number of records to return.
64
+ # @option options [String] before Pagination cursor to receive records
65
+ # before a provided Directory Group ID.
66
+ # @option options [String] after Pagination cursor to receive records
67
+ # before a provided Directory Group ID.
50
68
  #
51
69
  # @return [Hash]
52
70
  sig do
53
71
  params(
54
72
  options: T::Hash[Symbol, String],
55
- ).returns(T::Array[T::Hash[String, T.nilable(String)]])
73
+ ).returns(WorkOS::Types::ListStruct)
56
74
  end
57
75
  def list_groups(options = {})
58
76
  response = execute_request(
@@ -63,7 +81,15 @@ module WorkOS
63
81
  ),
64
82
  )
65
83
 
66
- JSON.parse(response.body)['data']
84
+ parsed_response = JSON.parse(response.body)
85
+ groups = parsed_response['data'].map do |group|
86
+ ::WorkOS::DirectoryGroup.new(group.to_json)
87
+ end
88
+
89
+ WorkOS::Types::ListStruct.new(
90
+ data: groups,
91
+ list_metadata: parsed_response['listMetadata'],
92
+ )
67
93
  end
68
94
 
69
95
  # Retrieve directory users.
@@ -73,12 +99,17 @@ module WorkOS
73
99
  # directory users will be retrieved.
74
100
  # @option options [String] user The ID of the directory group whose
75
101
  # directory users will be retrieved.
102
+ # @option options [String] limit Maximum number of records to return.
103
+ # @option options [String] before Pagination cursor to receive records
104
+ # before a provided Directory User ID.
105
+ # @option options [String] after Pagination cursor to receive records
106
+ # before a provided Directory User ID.
76
107
  #
77
108
  # @return [Hash]
78
109
  sig do
79
110
  params(
80
111
  options: T::Hash[Symbol, String],
81
- ).returns(T::Array[T::Hash[String, T.untyped]])
112
+ ).returns(WorkOS::Types::ListStruct)
82
113
  end
83
114
  def list_users(options = {})
84
115
  response = execute_request(
@@ -89,7 +120,15 @@ module WorkOS
89
120
  ),
90
121
  )
91
122
 
92
- JSON.parse(response.body)['data']
123
+ parsed_response = JSON.parse(response.body)
124
+ users = parsed_response['data'].map do |user|
125
+ ::WorkOS::DirectoryUser.new(user.to_json)
126
+ end
127
+
128
+ WorkOS::Types::ListStruct.new(
129
+ data: users,
130
+ list_metadata: parsed_response['listMetadata'],
131
+ )
93
132
  end
94
133
 
95
134
  # Retrieve the directory group with the given ID.
@@ -125,6 +164,23 @@ module WorkOS
125
164
 
126
165
  JSON.parse(response.body)
127
166
  end
167
+
168
+ # Delete the directory with the given ID.
169
+ #
170
+ # @param [String] id The ID of the directory.
171
+ #
172
+ # @return Boolean
173
+ sig { params(id: String).returns(T::Boolean) }
174
+ def delete_directory(id)
175
+ request = delete_request(
176
+ auth: true,
177
+ path: "/directories/#{id}",
178
+ )
179
+
180
+ response = execute_request(request: request)
181
+
182
+ response.is_a? Net::HTTPSuccess
183
+ end
128
184
  end
129
185
  end
130
186
  end