Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/workos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
require "zeitwerk"

module WorkOS
# Sentinel default for nullable optional parameters. Distinguishes an
# omitted argument ("leave unchanged") from an explicit `nil`, which
# clears the field by sending JSON `null`.
OMIT = Object.new

def OMIT.inspect
"WorkOS::OMIT"
end

OMIT.freeze
end

loader = Zeitwerk::Loader.for_gem
Expand Down
7 changes: 3 additions & 4 deletions lib/workos/api_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,11 @@ def delete_api_key(
# @return [WorkOS::ApiKey]
def create_api_key_expire(
id:,
expires_at: nil,
expires_at: WorkOS::OMIT,
request_options: {}
)
body = {
"expires_at" => expires_at
}.compact
body = {}
body["expires_at"] = expires_at unless expires_at.equal?(WorkOS::OMIT)
response = @client.request(
method: :post,
path: "/api_keys/#{WorkOS::Util.encode_path(id)}/expire",
Expand Down
48 changes: 24 additions & 24 deletions lib/workos/authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -615,16 +615,16 @@ def create_organization_role(
organization_id:,
name:,
slug: nil,
description: nil,
description: WorkOS::OMIT,
resource_type_slug: nil,
request_options: {}
)
body = {
"slug" => slug,
"name" => name,
"description" => description,
"resource_type_slug" => resource_type_slug
}.compact
body["description"] = description unless description.equal?(WorkOS::OMIT)
response = @client.request(
method: :post,
path: "/authorization/organizations/#{WorkOS::Util.encode_path(organization_id)}/roles",
Expand Down Expand Up @@ -669,13 +669,13 @@ def update_organization_role(
organization_id:,
slug:,
name: nil,
description: nil,
description: WorkOS::OMIT,
request_options: {}
)
body = {
"name" => name,
"description" => description
"name" => name
}.compact
body["description"] = description unless description.equal?(WorkOS::OMIT)
response = @client.request(
method: :patch,
path: "/authorization/organizations/#{WorkOS::Util.encode_path(organization_id)}/roles/#{WorkOS::Util.encode_path(slug)}",
Expand Down Expand Up @@ -821,14 +821,14 @@ def update_resource_by_external_id(
resource_type_slug:,
external_id:,
name: nil,
description: nil,
description: WorkOS::OMIT,
parent_resource: nil,
request_options: {}
)
body = {
"name" => name,
"description" => description
"name" => name
}.compact
body["description"] = description unless description.equal?(WorkOS::OMIT)
if parent_resource
case parent_resource
when WorkOS::Authorization::ParentResourceById
Expand Down Expand Up @@ -1081,17 +1081,17 @@ def create_resource(
name:,
resource_type_slug:,
organization_id:,
description: nil,
description: WorkOS::OMIT,
parent_resource: nil,
request_options: {}
)
body = {
"external_id" => external_id,
"name" => name,
"description" => description,
"resource_type_slug" => resource_type_slug,
"organization_id" => organization_id
}.compact
}
body["description"] = description unless description.equal?(WorkOS::OMIT)
if parent_resource
case parent_resource
when WorkOS::Authorization::ParentResourceById
Expand Down Expand Up @@ -1144,14 +1144,14 @@ def get_resource(
def update_resource(
resource_id:,
name: nil,
description: nil,
description: WorkOS::OMIT,
parent_resource: nil,
request_options: {}
)
body = {
"name" => name,
"description" => description
"name" => name
}.compact
body["description"] = description unless description.equal?(WorkOS::OMIT)
if parent_resource
case parent_resource
when WorkOS::Authorization::ParentResourceById
Expand Down Expand Up @@ -1329,16 +1329,16 @@ def list_environment_roles(request_options: {})
def create_environment_role(
slug:,
name:,
description: nil,
description: WorkOS::OMIT,
resource_type_slug: nil,
request_options: {}
)
body = {
"slug" => slug,
"name" => name,
"description" => description,
"resource_type_slug" => resource_type_slug
}.compact
body["description"] = description unless description.equal?(WorkOS::OMIT)
response = @client.request(
method: :post,
path: "/authorization/roles",
Expand Down Expand Up @@ -1379,13 +1379,13 @@ def get_environment_role(
def update_environment_role(
slug:,
name: nil,
description: nil,
description: WorkOS::OMIT,
request_options: {}
)
body = {
"name" => name,
"description" => description
"name" => name
}.compact
body["description"] = description unless description.equal?(WorkOS::OMIT)
response = @client.request(
method: :patch,
path: "/authorization/roles/#{WorkOS::Util.encode_path(slug)}",
Expand Down Expand Up @@ -1502,16 +1502,16 @@ def list_permissions(
def create_permission(
slug:,
name:,
description: nil,
description: WorkOS::OMIT,
resource_type_slug: nil,
request_options: {}
)
body = {
"slug" => slug,
"name" => name,
"description" => description,
"resource_type_slug" => resource_type_slug
}.compact
body["description"] = description unless description.equal?(WorkOS::OMIT)
response = @client.request(
method: :post,
path: "/authorization/permissions",
Expand Down Expand Up @@ -1552,13 +1552,13 @@ def get_permission(
def update_permission(
slug:,
name: nil,
description: nil,
description: WorkOS::OMIT,
request_options: {}
)
body = {
"name" => name,
"description" => description
"name" => name
}.compact
body["description"] = description unless description.equal?(WorkOS::OMIT)
response = @client.request(
method: :patch,
path: "/authorization/permissions/#{WorkOS::Util.encode_path(slug)}",
Expand Down
8 changes: 4 additions & 4 deletions lib/workos/base_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_request(path:, auth: false, params: {}, request_options: nil)
def post_request(path:, auth: false, body: {}, params: {}, request_options: nil)
req = build_request(Net::HTTP::Post, append_query(path, params),
auth: auth, request_options: request_options)
req.body = body.nil? ? "" : body.compact.to_json
req.body = body.nil? ? "" : body.to_json
req["Content-Type"] = "application/json"
inject_idempotency_key(req, request_options)
req
Expand All @@ -75,7 +75,7 @@ def post_request(path:, auth: false, body: {}, params: {}, request_options: nil)
def put_request(path:, auth: false, body: {}, params: {}, request_options: nil)
req = build_request(Net::HTTP::Put, append_query(path, params),
auth: auth, request_options: request_options)
req.body = body.nil? ? "" : body.compact.to_json
req.body = body.nil? ? "" : body.to_json
req["Content-Type"] = "application/json"
inject_idempotency_key(req, request_options)
req
Expand All @@ -84,7 +84,7 @@ def put_request(path:, auth: false, body: {}, params: {}, request_options: nil)
def patch_request(path:, auth: false, body: {}, params: {}, request_options: nil)
req = build_request(Net::HTTP::Patch, append_query(path, params),
auth: auth, request_options: request_options)
req.body = body.nil? ? "" : body.compact.to_json
req.body = body.nil? ? "" : body.to_json
req["Content-Type"] = "application/json"
inject_idempotency_key(req, request_options)
req
Expand All @@ -94,7 +94,7 @@ def delete_request(path:, auth: false, body: nil, params: {}, request_options: n
req = build_request(Net::HTTP::Delete, append_query(path, params),
auth: auth, request_options: request_options)
if body
req.body = body.compact.to_json
req.body = body.to_json
req["Content-Type"] = "application/json"
Comment thread
greptile-apps[bot] marked this conversation as resolved.
end
req
Expand Down
36 changes: 18 additions & 18 deletions lib/workos/connect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,24 @@ def list_applications(
def create_application(
name:,
application_type:,
description: nil,
scopes: nil,
redirect_uris: nil,
uses_pkce: nil,
description: WorkOS::OMIT,
scopes: WorkOS::OMIT,
redirect_uris: WorkOS::OMIT,
uses_pkce: WorkOS::OMIT,
is_first_party: nil,
organization_id: nil,
organization_id: WorkOS::OMIT,
request_options: {}
)
body = {
"name" => name,
"application_type" => application_type,
"description" => description,
"scopes" => scopes,
"redirect_uris" => redirect_uris,
"uses_pkce" => uses_pkce,
"is_first_party" => is_first_party,
"organization_id" => organization_id
"is_first_party" => is_first_party
}.compact
body["description"] = description unless description.equal?(WorkOS::OMIT)
body["scopes"] = scopes unless scopes.equal?(WorkOS::OMIT)
body["redirect_uris"] = redirect_uris unless redirect_uris.equal?(WorkOS::OMIT)
body["uses_pkce"] = uses_pkce unless uses_pkce.equal?(WorkOS::OMIT)
body["organization_id"] = organization_id unless organization_id.equal?(WorkOS::OMIT)
response = @client.request(
method: :post,
path: "/connect/applications",
Expand Down Expand Up @@ -232,17 +232,17 @@ def get_application(
def update_application(
id:,
name: nil,
description: nil,
scopes: nil,
redirect_uris: nil,
description: WorkOS::OMIT,
scopes: WorkOS::OMIT,
redirect_uris: WorkOS::OMIT,
request_options: {}
)
body = {
"name" => name,
"description" => description,
"scopes" => scopes,
"redirect_uris" => redirect_uris
"name" => name
}.compact
body["description"] = description unless description.equal?(WorkOS::OMIT)
body["scopes"] = scopes unless scopes.equal?(WorkOS::OMIT)
body["redirect_uris"] = redirect_uris unless redirect_uris.equal?(WorkOS::OMIT)
response = @client.request(
method: :put,
path: "/connect/applications/#{WorkOS::Util.encode_path(id)}",
Expand Down
14 changes: 7 additions & 7 deletions lib/workos/groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ def list_organization_groups(
def create_organization_group(
organization_id:,
name:,
description: nil,
description: WorkOS::OMIT,
request_options: {}
)
body = {
"name" => name,
"description" => description
}.compact
"name" => name
}
body["description"] = description unless description.equal?(WorkOS::OMIT)
response = @client.request(
method: :post,
path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/groups",
Expand Down Expand Up @@ -117,13 +117,13 @@ def update_organization_group(
organization_id:,
group_id:,
name: nil,
description: nil,
description: WorkOS::OMIT,
request_options: {}
)
body = {
"name" => name,
"description" => description
"name" => name
}.compact
body["description"] = description unless description.equal?(WorkOS::OMIT)
response = @client.request(
method: :patch,
path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/groups/#{WorkOS::Util.encode_path(group_id)}",
Expand Down
20 changes: 10 additions & 10 deletions lib/workos/organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ def create_organization(
allow_profiles_outside_organization: nil,
domains: nil,
domain_data: nil,
metadata: nil,
external_id: nil,
metadata: WorkOS::OMIT,
external_id: WorkOS::OMIT,
request_options: {}
)
body = {
"name" => name,
"allow_profiles_outside_organization" => allow_profiles_outside_organization,
"domains" => domains,
"domain_data" => domain_data,
"metadata" => metadata,
"external_id" => external_id
"domain_data" => domain_data
}.compact
body["metadata"] = metadata unless metadata.equal?(WorkOS::OMIT)
body["external_id"] = external_id unless external_id.equal?(WorkOS::OMIT)
response = @client.request(
method: :post,
path: "/organizations",
Expand Down Expand Up @@ -156,19 +156,19 @@ def update_organization(
domains: nil,
domain_data: nil,
stripe_customer_id: nil,
metadata: nil,
external_id: nil,
metadata: WorkOS::OMIT,
external_id: WorkOS::OMIT,
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" => metadata,
"external_id" => external_id
"stripe_customer_id" => stripe_customer_id
}.compact
body["metadata"] = metadata unless metadata.equal?(WorkOS::OMIT)
body["external_id"] = external_id unless external_id.equal?(WorkOS::OMIT)
response = @client.request(
method: :put,
path: "/organizations/#{WorkOS::Util.encode_path(id)}",
Expand Down
Loading
Loading