Class: WorkOS::Organizations

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Organizations

Returns a new instance of Organizations.



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

def initialize(client)
  @client = client
end

Instance Method Details

#create_organization(name:, allow_profiles_outside_organization: nil, domains: nil, domain_data: nil, metadata: nil, external_id: nil, request_options: {}) ⇒ WorkOS::Organization

Create an Organization

Parameters:

  • name (String)

    The name of the organization.

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

    Whether the organization allows profiles from outside the organization to sign in.

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

    The domains associated with the organization. Deprecated in favor of ‘domain_data`.

  • domain_data (Array<WorkOS::OrganizationDomainData>, nil) (defaults to: nil)

    The domains associated with the organization, including verification state.

  • metadata (Hash{String => String}, nil) (defaults to: nil)

    Object containing [metadata](workos.com/docs/authkit/metadata) key/value pairs associated with the Organization.

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

    An external identifier for the Organization.

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

    (see WorkOS::Types::RequestOptions)

Returns:



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/workos/organizations.rb', line 74

def create_organization(
  name:,
  allow_profiles_outside_organization: nil,
  domains: nil,
  domain_data: nil,
  metadata: nil,
  external_id: nil,
  request_options: {}
)
  body = {
    "name" => name,
    "allow_profiles_outside_organization" => allow_profiles_outside_organization,
    "domains" => domains,
    "domain_data" => domain_data,
    "metadata" => ,
    "external_id" => external_id
  }.compact
  response = @client.request(
    method: :post,
    path: "/organizations",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::Organization.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_organization(id:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete an Organization

Parameters:

  • id (String)

    Unique identifier of the Organization.

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

    (see WorkOS::Types::RequestOptions)



188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/workos/organizations.rb', line 188

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

#get_audit_log_configuration(id:, request_options: {}) ⇒ WorkOS::AuditLogConfiguration

Get Audit Log Configuration

Parameters:

  • id (String)

    Unique identifier of the Organization.

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

    (see WorkOS::Types::RequestOptions)

Returns:



205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/workos/organizations.rb', line 205

def get_audit_log_configuration(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/organizations/#{WorkOS::Util.encode_path(id)}/audit_log_configuration",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::AuditLogConfiguration.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_organization(id:, request_options: {}) ⇒ WorkOS::Organization

Get an Organization

Parameters:

  • id (String)

    Unique identifier of the Organization.

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

    (see WorkOS::Types::RequestOptions)

Returns:



126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/workos/organizations.rb', line 126

def get_organization(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/organizations/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::Organization.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_organization_by_external_id(external_id:, request_options: {}) ⇒ WorkOS::Organization

Get an Organization by External ID

Parameters:

  • external_id (String)

    The external ID of the Organization.

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

    (see WorkOS::Types::RequestOptions)

Returns:



107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/workos/organizations.rb', line 107

def get_organization_by_external_id(
  external_id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/organizations/external_id/#{WorkOS::Util.encode_path(external_id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::Organization.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_organizations(before: nil, after: nil, limit: nil, order: "desc", domains: nil, search: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::Organization>

List Organizations

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::OrganizationsOrder, 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.

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

    The domains of an Organization. Any Organization with a matching domain will be returned.

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

    Searchable text for an Organization. Matches against the organization name.

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

    (see WorkOS::Types::RequestOptions)

Returns:



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
56
57
58
59
60
61
62
63
# File 'lib/workos/organizations.rb', line 22

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

#update_organization(id:, name: nil, allow_profiles_outside_organization: nil, domains: nil, domain_data: nil, stripe_customer_id: nil, metadata: nil, external_id: nil, request_options: {}) ⇒ WorkOS::Organization

Update an Organization

Parameters:

  • id (String)

    Unique identifier of the Organization.

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

    The name of the organization.

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

    Whether the organization allows profiles from outside the organization to sign in.

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

    (deprecated) The domains associated with the organization. Deprecated in favor of ‘domain_data`.

  • domain_data (Array<WorkOS::OrganizationDomainData>, nil) (defaults to: nil)

    The domains associated with the organization, including verification state.

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

    The Stripe customer ID associated with the organization.

  • metadata (Hash{String => String}, nil) (defaults to: nil)

    Object containing [metadata](workos.com/docs/authkit/metadata) key/value pairs associated with the Organization.

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

    An external identifier for the Organization.

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

    (see WorkOS::Types::RequestOptions)

Returns:



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/workos/organizations.rb', line 152

def update_organization(
  id:,
  name: nil,
  allow_profiles_outside_organization: nil,
  domains: nil,
  domain_data: nil,
  stripe_customer_id: nil,
  metadata: nil,
  external_id: nil,
  request_options: {}
)
  body = {
    "name" => name,
    "allow_profiles_outside_organization" => allow_profiles_outside_organization,
    "domains" => domains,
    "domain_data" => domain_data,
    "stripe_customer_id" => stripe_customer_id,
    "metadata" => ,
    "external_id" => external_id
  }.compact
  response = @client.request(
    method: :put,
    path: "/organizations/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::Organization.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