-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add WorkOS::Portal.create_organization
* Adds the ability to create an organization via the SDK for use with the Admin Portal.
- Loading branch information
1 parent
0d05476
commit 71523db
Showing
8 changed files
with
289 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
# typed: true | ||
|
||
require 'json' | ||
|
||
module WorkOS | ||
# The Organization class provides a lightweight wrapper around | ||
# a WorkOS Organization resource. This class is not meant to be instantiated | ||
# in user space, and is instantiated internally but exposed. | ||
class Organization | ||
extend T::Sig | ||
|
||
attr_accessor :id, :domains, :name | ||
|
||
sig { params(json: String).void } | ||
def initialize(json) | ||
raw = parse_json(json) | ||
|
||
@id = T.let(raw.id, String) | ||
@name = T.let(raw.name, String) | ||
@domains = T.let(raw.domains, Array) | ||
end | ||
|
||
def to_json(*) | ||
{ | ||
id: id, | ||
name: name, | ||
domains: domains, | ||
} | ||
end | ||
|
||
private | ||
|
||
sig do | ||
params( | ||
json_string: String, | ||
).returns(WorkOS::Types::OrganizationStruct) | ||
end | ||
def parse_json(json_string) | ||
hash = JSON.parse(json_string, symbolize_names: true) | ||
|
||
WorkOS::Types::OrganizationStruct.new( | ||
id: hash[:id], | ||
name: hash[:name], | ||
domains: hash[:domains], | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
# typed: strict | ||
|
||
module WorkOS | ||
module Types | ||
# This OrganizationStruct acts as a typed interface | ||
# for the Organization class | ||
class OrganizationStruct < T::Struct | ||
const :id, String | ||
const :name, String | ||
const :domains, T::Array[T.untyped] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
spec/support/fixtures/vcr_cassettes/organization/create.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
--- | ||
http_interactions: | ||
- request: | ||
method: post | ||
uri: https://api.workos.com/organizations | ||
body: | ||
encoding: UTF-8 | ||
string: '{"domains":["example.com"],"name":"Test Organization"}' | ||
headers: | ||
Content-Type: | ||
- application/json | ||
Accept-Encoding: | ||
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3 | ||
Accept: | ||
- "*/*" | ||
User-Agent: | ||
- WorkOS; ruby/2.7.1; x86_64-darwin19; v0.5.0 | ||
Authorization: | ||
- Bearer <API_KEY> | ||
response: | ||
status: | ||
code: 201 | ||
message: Created | ||
headers: | ||
Server: | ||
- Cowboy | ||
Connection: | ||
- keep-alive | ||
Vary: | ||
- Origin, Accept-Encoding | ||
Access-Control-Allow-Credentials: | ||
- 'true' | ||
Content-Security-Policy: | ||
- 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self'' | ||
https: data:;frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src | ||
''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests' | ||
X-Dns-Prefetch-Control: | ||
- 'off' | ||
Expect-Ct: | ||
- max-age=0 | ||
X-Frame-Options: | ||
- SAMEORIGIN | ||
Strict-Transport-Security: | ||
- max-age=15552000; includeSubDomains | ||
X-Download-Options: | ||
- noopen | ||
X-Content-Type-Options: | ||
- nosniff | ||
X-Permitted-Cross-Domain-Policies: | ||
- none | ||
Referrer-Policy: | ||
- no-referrer | ||
X-Xss-Protection: | ||
- '0' | ||
X-Request-Id: | ||
- bcddfa8b-3a12-4d48-b265-6094a26225a4 | ||
Content-Type: | ||
- application/json; charset=utf-8 | ||
Content-Length: | ||
- '203' | ||
Etag: | ||
- W/"cb-T4+GTGrJeuAmC0PAjcaSX5ZXL18" | ||
Date: | ||
- Wed, 09 Sep 2020 20:17:53 GMT | ||
Via: | ||
- 1.1 vegur | ||
body: | ||
encoding: UTF-8 | ||
string: '{"name":"Test Organization","object":"organization","id":"org_01EHT88Z8J8795GZNQ4ZP1J81T","domains":[{"domain":"example.com","object":"organization_domain","id":"org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8"}]}' | ||
http_version: | ||
recorded_at: Wed, 09 Sep 2020 20:17:54 GMT | ||
recorded_with: VCR 5.0.0 |
72 changes: 72 additions & 0 deletions
72
spec/support/fixtures/vcr_cassettes/organization/create_invalid.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
--- | ||
http_interactions: | ||
- request: | ||
method: post | ||
uri: https://api.workos.com/organizations | ||
body: | ||
encoding: UTF-8 | ||
string: '{"domains":["example.com"],"name":"Test Organization 2"}' | ||
headers: | ||
Content-Type: | ||
- application/json | ||
Accept-Encoding: | ||
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3 | ||
Accept: | ||
- "*/*" | ||
User-Agent: | ||
- WorkOS; ruby/2.7.1; x86_64-darwin19; v0.5.0 | ||
Authorization: | ||
- Bearer <API_KEY> | ||
response: | ||
status: | ||
code: 409 | ||
message: Conflict | ||
headers: | ||
Server: | ||
- Cowboy | ||
Connection: | ||
- keep-alive | ||
Vary: | ||
- Origin, Accept-Encoding | ||
Access-Control-Allow-Credentials: | ||
- 'true' | ||
Content-Security-Policy: | ||
- 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self'' | ||
https: data:;frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src | ||
''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests' | ||
X-Dns-Prefetch-Control: | ||
- 'off' | ||
Expect-Ct: | ||
- max-age=0 | ||
X-Frame-Options: | ||
- SAMEORIGIN | ||
Strict-Transport-Security: | ||
- max-age=15552000; includeSubDomains | ||
X-Download-Options: | ||
- noopen | ||
X-Content-Type-Options: | ||
- nosniff | ||
X-Permitted-Cross-Domain-Policies: | ||
- none | ||
Referrer-Policy: | ||
- no-referrer | ||
X-Xss-Protection: | ||
- '0' | ||
X-Request-Id: | ||
- 929940d6-33dd-404c-9856-eca6cc606d28 | ||
Content-Type: | ||
- application/json; charset=utf-8 | ||
Content-Length: | ||
- '73' | ||
Etag: | ||
- W/"49-8i1S2EtfSciiA8rvGWbYFNlSlhw" | ||
Date: | ||
- Wed, 09 Sep 2020 21:26:03 GMT | ||
Via: | ||
- 1.1 vegur | ||
body: | ||
encoding: UTF-8 | ||
string: '{"message":"An Organization with the domain example.com already exists."}' | ||
http_version: | ||
recorded_at: Wed, 09 Sep 2020 21:26:03 GMT | ||
recorded_with: VCR 5.0.0 |