Class: WorkOS::Pipes

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Pipes

Returns a new instance of Pipes.



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

def initialize(client)
  @client = client
end

Instance Method Details

#authorize_data_integration(slug:, user_id:, organization_id: nil, return_to: nil, request_options: {}) ⇒ WorkOS::DataIntegrationAuthorizeUrlResponse

Get authorization URL

Parameters:

  • slug (String)

    The slug identifier of the provider (e.g., github, slack, notion).

  • user_id (String)

    The ID of the user to authorize.

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

    An organization ID to scope the authorization to a specific organization.

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

    The URL to redirect the user to after authorization.

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

    (see WorkOS::Types::RequestOptions)

Returns:



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/workos/pipes.rb', line 206

def authorize_data_integration(
  slug:,
  user_id:,
  organization_id: nil,
  return_to: nil,
  request_options: {}
)
  body = {
    "user_id" => user_id,
    "organization_id" => organization_id,
    "return_to" => return_to
  }.compact
  response = @client.request(
    method: :post,
    path: "/data-integrations/#{WorkOS::Util.encode_path(slug)}/authorize",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::DataIntegrationAuthorizeUrlResponse.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

#create_data_integration(provider:, description: nil, enabled: nil, scopes: nil, credentials: nil, custom_provider: nil, request_options: {}) ⇒ WorkOS::DataIntegration

Create a data integration

Parameters:

  • provider (String)

    The provider to create a Data Integration for. For a built-in provider use its slug (e.g. github, slack). For a custom provider, this is the new provider slug and custom_provider must be supplied. A custom provider slug cannot shadow an existing global provider slug.

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

    An optional description of the Data Integration.

  • enabled (Boolean, nil) (defaults to: nil)

    Whether the Data Integration is enabled. Defaults to false.

  • scopes (Array<String>, nil) (defaults to: nil)

    The OAuth scopes to request for the Data Integration. Defaults to the provider's configured scopes when omitted.

  • credentials (WorkOS::DataIntegrationCredentialsDto, nil) (defaults to: nil)

    The credentials to configure for the Data Integration. Required for both built-in and custom providers.

  • custom_provider (WorkOS::CustomProviderDefinition, nil) (defaults to: nil)

    The OAuth definition for a custom provider. Supply this to define a custom provider; omit it to create an integration for a built-in provider.

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

    (see WorkOS::Types::RequestOptions)

Returns:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/workos/pipes.rb', line 66

def create_data_integration(
  provider:,
  description: nil,
  enabled: nil,
  scopes: nil,
  credentials: nil,
  custom_provider: nil,
  request_options: {}
)
  body = {
    "provider" => provider,
    "description" => description,
    "enabled" => enabled,
    "scopes" => scopes,
    "credentials" => credentials,
    "custom_provider" => custom_provider
  }.compact
  response = @client.request(
    method: :post,
    path: "/data-integrations",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::DataIntegration.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

#create_data_integration_credential(slug:, user_id:, organization_id: nil, request_options: {}) ⇒ WorkOS::DataIntegrationCredentialsResponse

Vend credentials for a connected account

Parameters:

  • slug (String)

    The identifier of the integration.

  • user_id (String)

    A User identifier.

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

    An Organization identifier. Optional parameter to scope the connection to a specific organization.

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

    (see WorkOS::Types::RequestOptions)

Returns:



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/workos/pipes.rb', line 236

def create_data_integration_credential(
  slug:,
  user_id:,
  organization_id: nil,
  request_options: {}
)
  body = {
    "user_id" => user_id,
    "organization_id" => organization_id
  }.compact
  response = @client.request(
    method: :post,
    path: "/data-integrations/#{WorkOS::Util.encode_path(slug)}/credentials",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::DataIntegrationCredentialsResponse.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

#create_user_connected_account(user_id:, slug:, access_token: nil, refresh_token: nil, expires_at: nil, scopes: nil, state: nil, organization_id: nil, request_options: {}) ⇒ WorkOS::ConnectedAccount

Import a connected account

Parameters:

  • user_id (String)

    A User identifier.

  • slug (String)

    The slug identifier of the provider (e.g., github, slack, notion).

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

    The OAuth access token for the connected account.

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

    The OAuth refresh token for the connected account.

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

    The ISO-8601 timestamp when the access token expires. Required when access_token is provided for tokens that expire.

  • scopes (Array<String>, nil) (defaults to: nil)

    The OAuth scopes granted for this connection.

  • state (WorkOS::Types::ConnectedAccountState, nil) (defaults to: nil)

    Explicitly set the state of the connected account. When omitted, the state is derived from the token combination provided.

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

    An Organization identifier. Optional parameter if the connection is scoped to an organization.

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

    (see WorkOS::Types::RequestOptions)

Returns:



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/workos/pipes.rb', line 324

def (
  user_id:,
  slug:,
  access_token: nil,
  refresh_token: nil,
  expires_at: nil,
  scopes: nil,
  state: nil,
  organization_id: nil,
  request_options: {}
)
  params = {
    "organization_id" => organization_id
  }.compact
  body = {
    "access_token" => access_token,
    "refresh_token" => refresh_token,
    "expires_at" => expires_at,
    "scopes" => scopes,
    "state" => state
  }.compact
  response = @client.request(
    method: :post,
    path: "/user_management/users/#{WorkOS::Util.encode_path(user_id)}/connected_accounts/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    params: params,
    body: body,
    request_options: request_options
  )
  result = WorkOS::ConnectedAccount.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_data_integration(slug:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete a data integration

Parameters:

  • slug (String)

    The slug identifier of the data integration.

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

    (see WorkOS::Types::RequestOptions)



155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/workos/pipes.rb', line 155

def delete_data_integration(
  slug:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/data-integrations/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#delete_user_connected_account(user_id:, slug:, organization_id: nil, request_options: {}) ⇒ void

This method returns an undefined value.

Delete a connected account

Parameters:

  • user_id (String)

    A User identifier.

  • slug (String)

    The slug identifier of the provider (e.g., github, slack, notion).

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

    An Organization identifier. Optional parameter if the connection is scoped to an organization.

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

    (see WorkOS::Types::RequestOptions)



409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
# File 'lib/workos/pipes.rb', line 409

def (
  user_id:,
  slug:,
  organization_id: nil,
  request_options: {}
)
  params = {
    "organization_id" => organization_id
  }.compact
  @client.request(
    method: :delete,
    path: "/user_management/users/#{WorkOS::Util.encode_path(user_id)}/connected_accounts/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    params: params,
    request_options: request_options
  )
  nil
end

#get_access_token(provider:, user_id:, organization_id: nil, request_options: {}) ⇒ WorkOS::DataIntegrationAccessTokenResponse

Get an access token for a connected account

Parameters:

  • provider (String)

    The identifier of the integration.

  • user_id (String)

    A User identifier.

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

    An Organization identifier. Optional parameter to scope the connection to a specific organization.

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

    (see WorkOS::Types::RequestOptions)

Returns:



264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/workos/pipes.rb', line 264

def get_access_token(
  provider:,
  user_id:,
  organization_id: nil,
  request_options: {}
)
  body = {
    "user_id" => user_id,
    "organization_id" => organization_id
  }.compact
  response = @client.request(
    method: :post,
    path: "/data-integrations/#{WorkOS::Util.encode_path(provider)}/token",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::DataIntegrationAccessTokenResponse.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_data_integration(slug:, request_options: {}) ⇒ WorkOS::DataIntegration

Get a data integration

Parameters:

  • slug (String)

    The slug identifier of the data integration.

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

    (see WorkOS::Types::RequestOptions)

Returns:



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/workos/pipes.rb', line 99

def get_data_integration(
  slug:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/data-integrations/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::DataIntegration.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_connected_account(user_id:, slug:, organization_id: nil, request_options: {}) ⇒ WorkOS::ConnectedAccount

Get a connected account

Parameters:

  • user_id (String)

    A User identifier.

  • slug (String)

    The slug identifier of the provider (e.g., github, slack, notion).

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

    An Organization identifier. Optional parameter if the connection is scoped to an organization.

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

    (see WorkOS::Types::RequestOptions)

Returns:



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/workos/pipes.rb', line 292

def (
  user_id:,
  slug:,
  organization_id: nil,
  request_options: {}
)
  params = {
    "organization_id" => organization_id
  }.compact
  response = @client.request(
    method: :get,
    path: "/user_management/users/#{WorkOS::Util.encode_path(user_id)}/connected_accounts/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    params: params,
    request_options: request_options
  )
  result = WorkOS::ConnectedAccount.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_data_integrations(before: nil, after: nil, limit: 10, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::DataIntegration>

List data integrations

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

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

    (see WorkOS::Types::RequestOptions)

Returns:



20
21
22
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
# File 'lib/workos/pipes.rb', line 20

def list_data_integrations(
  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: "/data-integrations",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_data_integrations(
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::DataIntegration,
    filters: {before: before, limit: limit, order: order},
    fetch_next: fetch_next
  )
end

#list_user_data_providers(user_id:, organization_id: nil, request_options: {}) ⇒ WorkOS::DataIntegrationsListResponse

List providers for a user

Parameters:

  • user_id (String)

    A User identifier to list providers and connected accounts for.

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

    An Organization identifier. Optional parameter to filter connections for a specific organization.

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

    (see WorkOS::Types::RequestOptions)

Returns:



433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/workos/pipes.rb', line 433

def list_user_data_providers(
  user_id:,
  organization_id: nil,
  request_options: {}
)
  params = {
    "organization_id" => organization_id
  }.compact
  response = @client.request(
    method: :get,
    path: "/user_management/users/#{WorkOS::Util.encode_path(user_id)}/data_providers",
    auth: true,
    params: params,
    request_options: request_options
  )
  result = WorkOS::DataIntegrationsListResponse.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_data_integration(slug:, description: nil, enabled: nil, scopes: nil, credentials: nil, custom_provider: nil, request_options: {}) ⇒ WorkOS::DataIntegration

Update a data integration

Parameters:

  • slug (String)

    The slug identifier of the data integration.

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

    An optional description of the Data Integration.

  • enabled (Boolean, nil) (defaults to: nil)

    Whether the Data Integration is enabled.

  • scopes (Array<String>, nil) (defaults to: nil)

    The OAuth scopes to request for the Data Integration. Pass null to reset to the provider's configured scopes.

  • credentials (WorkOS::DataIntegrationCredentialsDto, nil) (defaults to: nil)

    New credentials for the Data Integration. When provided, rotates the stored client secret.

  • custom_provider (WorkOS::UpdateCustomProviderDefinition, nil) (defaults to: nil)

    Updates to a custom provider's OAuth definition. Only valid for custom-provider integrations.

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

    (see WorkOS::Types::RequestOptions)

Returns:



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
# File 'lib/workos/pipes.rb', line 123

def update_data_integration(
  slug:,
  description: nil,
  enabled: nil,
  scopes: nil,
  credentials: nil,
  custom_provider: nil,
  request_options: {}
)
  body = {
    "description" => description,
    "enabled" => enabled,
    "scopes" => scopes,
    "credentials" => credentials,
    "custom_provider" => custom_provider
  }.compact
  response = @client.request(
    method: :put,
    path: "/data-integrations/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::DataIntegration.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_data_integration_api_key(slug:, user_id:, secret:, organization_id: nil, request_options: {}) ⇒ WorkOS::ConnectedAccount

Upsert an API key for a connected account

Parameters:

  • slug (String)

    The identifier of the integration.

  • user_id (String)

    A User identifier.

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

    An Organization identifier. Optional parameter to scope the connection to a specific organization.

  • secret (String)

    The API key secret to store for this integration.

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

    (see WorkOS::Types::RequestOptions)

Returns:



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/workos/pipes.rb', line 175

def update_data_integration_api_key(
  slug:,
  user_id:,
  secret:,
  organization_id: nil,
  request_options: {}
)
  body = {
    "user_id" => user_id,
    "organization_id" => organization_id,
    "secret" => secret
  }.compact
  response = @client.request(
    method: :put,
    path: "/data-integrations/#{WorkOS::Util.encode_path(slug)}/api-key",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::ConnectedAccount.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_user_connected_account(user_id:, slug:, access_token: nil, refresh_token: nil, expires_at: nil, scopes: nil, state: nil, organization_id: nil, request_options: {}) ⇒ WorkOS::ConnectedAccount

Update a connected account

Parameters:

  • user_id (String)

    A User identifier.

  • slug (String)

    The slug identifier of the provider (e.g., github, slack, notion).

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

    The OAuth access token for the connected account.

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

    The OAuth refresh token for the connected account.

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

    The ISO-8601 timestamp when the access token expires. Required when access_token is provided for tokens that expire.

  • scopes (Array<String>, nil) (defaults to: nil)

    The OAuth scopes granted for this connection.

  • state (WorkOS::Types::ConnectedAccountState, nil) (defaults to: nil)

    Explicitly set the state of the connected account. When omitted, the state is derived from the token combination provided.

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

    An Organization identifier. Optional parameter if the connection is scoped to an organization.

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

    (see WorkOS::Types::RequestOptions)

Returns:



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
# File 'lib/workos/pipes.rb', line 369

def (
  user_id:,
  slug:,
  access_token: nil,
  refresh_token: nil,
  expires_at: nil,
  scopes: nil,
  state: nil,
  organization_id: nil,
  request_options: {}
)
  params = {
    "organization_id" => organization_id
  }.compact
  body = {
    "access_token" => access_token,
    "refresh_token" => refresh_token,
    "expires_at" => expires_at,
    "scopes" => scopes,
    "state" => state
  }.compact
  response = @client.request(
    method: :put,
    path: "/user_management/users/#{WorkOS::Util.encode_path(user_id)}/connected_accounts/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    params: params,
    body: body,
    request_options: request_options
  )
  result = WorkOS::ConnectedAccount.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