Module: WorkOS::Organizations
- Extended by:
- Client, Deprecation
- Defined in:
- lib/workos/organizations.rb
Overview
The Organizations module provides resource methods for working with Organizations
Class Method Summary collapse
-
.create_organization(domain_data: nil, domains: nil, name:, allow_profiles_outside_organization: nil, idempotency_key: nil) ⇒ Object
Create an organization.
-
.delete_organization(id:) ⇒ Bool
Delete an Organization.
-
.get_organization(id:) ⇒ WorkOS::Organization
Get an Organization.
-
.list_organization_roles(organization_id:) ⇒ Object
Retrieve a list of roles for the given organization.
-
.list_organizations(options = {}) ⇒ Object
Retrieve a list of organizations that have connections configured within your WorkOS dashboard.
-
.update_organization(organization:, stripe_customer_id: nil, domain_data: nil, domains: nil, name: nil, allow_profiles_outside_organization: nil) ⇒ Object
Update an organization.
Methods included from Deprecation
Methods included from Client
client, delete_request, execute_request, get_request, handle_error_response, post_request, put_request, user_agent
Class Method Details
.create_organization(domain_data: nil, domains: nil, name:, allow_profiles_outside_organization: nil, idempotency_key: nil) ⇒ Object
Create an organization
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/workos/organizations.rb', line 84 def create_organization( domain_data: nil, domains: nil, name:, allow_profiles_outside_organization: nil, idempotency_key: nil ) body = { name: name } body[:domain_data] = domain_data if domain_data if domains warn_deprecation '`domains` is deprecated. Use `domain_data` instead.' body[:domains] = domains end unless allow_profiles_outside_organization.nil? warn_deprecation '`allow_profiles_outside_organization` is deprecated. ' \ 'If you need to allow sign-ins from any email domain, contact [email protected].' body[:allow_profiles_outside_organization] = allow_profiles_outside_organization end request = post_request( auth: true, body: body, path: '/organizations', idempotency_key: idempotency_key, ) response = execute_request(request: request) check_and_raise_organization_error(response: response) WorkOS::Organization.new(response.body) end |
.delete_organization(id:) ⇒ Bool
Delete an Organization
175 176 177 178 179 180 181 182 183 184 |
# File 'lib/workos/organizations.rb', line 175 def delete_organization(id:) request = delete_request( auth: true, path: "/organizations/#{id}", ) response = execute_request(request: request) response.is_a? Net::HTTPSuccess end |
.get_organization(id:) ⇒ WorkOS::Organization
Get an Organization
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/workos/organizations.rb', line 61 def get_organization(id:) request = get_request( auth: true, path: "/organizations/#{id}", ) response = execute_request(request: request) WorkOS::Organization.new(response.body) end |
.list_organization_roles(organization_id:) ⇒ Object
Retrieve a list of roles for the given organization.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/workos/organizations.rb', line 189 def list_organization_roles(organization_id:) response = execute_request( request: get_request( path: "/organizations/#{organization_id}/roles", auth: true, ), ) parsed_response = JSON.parse(response.body) roles = parsed_response['data'].map do |role| WorkOS::Role.new(role.to_json) end WorkOS::Types::ListStruct.new( data: roles, list_metadata: { after: nil, before: nil, }, ) end |
.list_organizations(options = {}) ⇒ Object
Retrieve a list of organizations that have connections configured within your WorkOS dashboard.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/workos/organizations.rb', line 24 def list_organizations( = {}) [:order] ||= 'desc' response = execute_request( request: get_request( path: '/organizations', auth: true, params: , ), ) parsed_response = JSON.parse(response.body) organizations = parsed_response['data'].map do |organization| ::WorkOS::Organization.new(organization.to_json) end WorkOS::Types::ListStruct.new( data: organizations, list_metadata: parsed_response['listMetadata'], ) end |
.update_organization(organization:, stripe_customer_id: nil, domain_data: nil, domains: nil, name: nil, allow_profiles_outside_organization: nil) ⇒ Object
Update an organization
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 156 157 158 159 160 161 162 163 164 |
# File 'lib/workos/organizations.rb', line 131 def update_organization( organization:, stripe_customer_id: nil, domain_data: nil, domains: nil, name: nil, allow_profiles_outside_organization: nil ) body = { name: name } body[:domain_data] = domain_data if domain_data body[:stripe_customer_id] = stripe_customer_id if stripe_customer_id if domains warn_deprecation '`domains` is deprecated. Use `domain_data` instead.' body[:domains] = domains end unless allow_profiles_outside_organization.nil? warn_deprecation '`allow_profiles_outside_organization` is deprecated. ' \ 'If you need to allow sign-ins from any email domain, contact [email protected].' body[:allow_profiles_outside_organization] = allow_profiles_outside_organization end request = put_request( auth: true, body: body, path: "/organizations/#{organization}", ) response = execute_request(request: request) check_and_raise_organization_error(response: response) WorkOS::Organization.new(response.body) end |