def create(request:, timeout_ms: nil, http_headers: nil)
def create(request:, timeout_ms: nil, http_headers: nil)
# create - Create Organization
# Create an organization.
#
# **Scopes**: `organizations:write`
url, params = @sdk_configuration.get_server_details
base_url = Utils.template_url(url, params)
url = "#{base_url}/v1/organizations/"
headers = {}
headers = T.cast(headers, T::Hash[String, String])
req_content_type, data, form = Utils.serialize_request_body(request, false, false, :request, :json)
headers["content-type"] = req_content_type
raise StandardError, "request body is required" if data.nil? && form.nil?
if form && !form.empty?
body = Utils.encode_form(form)
elsif Utils.match_content_type(req_content_type, "application/x-www-form-urlencoded")
body = URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
else
body = data
end
headers["Accept"] = "application/json"
headers["user-agent"] = @sdk_configuration.user_agent
security = @sdk_configuration.security_source&.call
timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
timeout ||= @sdk_configuration.timeout
connection = @sdk_configuration.client
hook_ctx = SDKHooks::HookContext.new(
config: @sdk_configuration,
base_url: base_url,
oauth2_scopes: nil,
operation_id: "organizations:create",
security_source: @sdk_configuration.security_source
)
error = T.let(nil, T.nilable(StandardError))
http_response = T.let(nil, T.nilable(Faraday::Response))
begin
http_response = T.must(connection).post(url) do |req|
req.body = body
req.headers.merge!(headers)
req.options.timeout = timeout unless timeout.nil?
Utils.configure_request_security(req, security)
http_headers&.each do |key, value|
req.headers[key.to_s] = value
end
@sdk_configuration.hooks.before_request(
hook_ctx: SDKHooks::BeforeRequestHookContext.new(
hook_ctx: hook_ctx
),
request: req
)
end
rescue StandardError => e
error = e
ensure
if http_response.nil? || Utils.error_status?(http_response.status)
http_response = @sdk_configuration.hooks.after_error(
error: error,
hook_ctx: SDKHooks::AfterErrorHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
else
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
end
if http_response.nil?
raise error if !error.nil?
raise "no response"
end
end
content_type = http_response.headers.fetch("Content-Type", "application/octet-stream")
if Utils.match_status_code(http_response.status, ["201"])
if Utils.match_content_type(content_type, "application/json")
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
response_data = http_response.env.response_body
obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Components::Organization)
response = Models::Operations::OrganizationsCreateResponse.new(
status_code: http_response.status,
content_type: content_type,
raw_response: http_response,
organization: T.unsafe(obj)
)
return response
else
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"Unknown content type received"
)
end
elsif Utils.match_status_code(http_response.status, ["422"])
if Utils.match_content_type(content_type, "application/json")
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
response_data = http_response.env.response_body
obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::HTTPValidationError)
raise obj
else
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"Unknown content type received"
)
end
elsif Utils.match_status_code(http_response.status, ["4XX"])
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"API error occurred"
)
elsif Utils.match_status_code(http_response.status, ["5XX"])
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"API error occurred"
)
else
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"Unknown status code received"
)
end
end
def get(id:, timeout_ms: nil, http_headers: nil)
def get(id:, timeout_ms: nil, http_headers: nil)
# get - Get Organization
# Get an organization by ID.
#
# **Scopes**: `organizations:read` `organizations:write`
request = Models::Operations::OrganizationsGetRequest.new(
id: id
)
url, params = @sdk_configuration.get_server_details
base_url = Utils.template_url(url, params)
url = Utils.generate_url(
Models::Operations::OrganizationsGetRequest,
base_url,
"/v1/organizations/{id}",
request
)
headers = {}
headers = T.cast(headers, T::Hash[String, String])
headers["Accept"] = "application/json"
headers["user-agent"] = @sdk_configuration.user_agent
security = @sdk_configuration.security_source&.call
timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
timeout ||= @sdk_configuration.timeout
connection = @sdk_configuration.client
hook_ctx = SDKHooks::HookContext.new(
config: @sdk_configuration,
base_url: base_url,
oauth2_scopes: nil,
operation_id: "organizations:get",
security_source: @sdk_configuration.security_source
)
error = T.let(nil, T.nilable(StandardError))
http_response = T.let(nil, T.nilable(Faraday::Response))
begin
http_response = T.must(connection).get(url) do |req|
req.headers.merge!(headers)
req.options.timeout = timeout unless timeout.nil?
Utils.configure_request_security(req, security)
http_headers&.each do |key, value|
req.headers[key.to_s] = value
end
@sdk_configuration.hooks.before_request(
hook_ctx: SDKHooks::BeforeRequestHookContext.new(
hook_ctx: hook_ctx
),
request: req
)
end
rescue StandardError => e
error = e
ensure
if http_response.nil? || Utils.error_status?(http_response.status)
http_response = @sdk_configuration.hooks.after_error(
error: error,
hook_ctx: SDKHooks::AfterErrorHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
else
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
end
if http_response.nil?
raise error if !error.nil?
raise "no response"
end
end
content_type = http_response.headers.fetch("Content-Type", "application/octet-stream")
if Utils.match_status_code(http_response.status, ["200"])
if Utils.match_content_type(content_type, "application/json")
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
response_data = http_response.env.response_body
obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Components::Organization)
response = Models::Operations::OrganizationsGetResponse.new(
status_code: http_response.status,
content_type: content_type,
raw_response: http_response,
organization: T.unsafe(obj)
)
return response
else
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"Unknown content type received"
)
end
elsif Utils.match_status_code(http_response.status, ["404"])
if Utils.match_content_type(content_type, "application/json")
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
response_data = http_response.env.response_body
obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::ResourceNotFound)
raise obj
else
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"Unknown content type received"
)
end
elsif Utils.match_status_code(http_response.status, ["422"])
if Utils.match_content_type(content_type, "application/json")
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
response_data = http_response.env.response_body
obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::HTTPValidationError)
raise obj
else
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"Unknown content type received"
)
end
elsif Utils.match_status_code(http_response.status, ["4XX"])
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"API error occurred"
)
elsif Utils.match_status_code(http_response.status, ["5XX"])
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"API error occurred"
)
else
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"Unknown status code received"
)
end
end
def list(slug: nil, page: nil, limit: nil, sorting: nil, timeout_ms: nil, http_headers: nil)
def list(slug: nil, page: nil, limit: nil, sorting: nil, timeout_ms: nil, http_headers: nil)
# list - List Organizations
# List organizations.
#
# **Scopes**: `organizations:read` `organizations:write`
request = Models::Operations::OrganizationsListRequest.new(
slug: slug,
page: page,
limit: limit,
sorting: sorting
)
url, params = @sdk_configuration.get_server_details
base_url = Utils.template_url(url, params)
url = "#{base_url}/v1/organizations/"
headers = {}
headers = T.cast(headers, T::Hash[String, String])
query_params = Utils.get_query_params(Models::Operations::OrganizationsListRequest, request, nil)
headers["Accept"] = "application/json"
headers["user-agent"] = @sdk_configuration.user_agent
security = @sdk_configuration.security_source&.call
timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
timeout ||= @sdk_configuration.timeout
connection = @sdk_configuration.client
hook_ctx = SDKHooks::HookContext.new(
config: @sdk_configuration,
base_url: base_url,
oauth2_scopes: nil,
operation_id: "organizations:list",
security_source: @sdk_configuration.security_source
)
error = T.let(nil, T.nilable(StandardError))
http_response = T.let(nil, T.nilable(Faraday::Response))
begin
http_response = T.must(connection).get(url) do |req|
req.headers.merge!(headers)
req.options.timeout = timeout unless timeout.nil?
req.params = query_params
Utils.configure_request_security(req, security)
http_headers&.each do |key, value|
req.headers[key.to_s] = value
end
@sdk_configuration.hooks.before_request(
hook_ctx: SDKHooks::BeforeRequestHookContext.new(
hook_ctx: hook_ctx
),
request: req
)
end
rescue StandardError => e
error = e
ensure
if http_response.nil? || Utils.error_status?(http_response.status)
http_response = @sdk_configuration.hooks.after_error(
error: error,
hook_ctx: SDKHooks::AfterErrorHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
else
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
end
if http_response.nil?
raise error if !error.nil?
raise "no response"
end
end
content_type = http_response.headers.fetch("Content-Type", "application/octet-stream")
if Utils.match_status_code(http_response.status, ["200"])
if Utils.match_content_type(content_type, "application/json")
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
response_data = http_response.env.response_body
obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Components::ListResourceOrganization)
response = Models::Operations::OrganizationsListResponse.new(
status_code: http_response.status,
content_type: content_type,
raw_response: http_response,
list_resource_organization: T.unsafe(obj)
)
sdk = self
response.next_page = proc do
request_page = T.must(!request.page.nil? ? request.page : 1)
next_page = request_page + 1
num_pages = Janeway.enum_for("$.pagination.max_page", JSON.parse(response_data)).search
if num_pages.nil? || num_pages[0] <= request_page
next nil
end
if !response_data
next nil
end
results = Janeway.enum_for("$.items", JSON.parse(response_data)).search
if results.is_a?(Array)
results = results[0]
end
if results.count.zero?
next nil
end
request_limit = !request.limit.nil? ? request.limit : 1
if results.count < request_limit
next nil
end
sdk.list(
slug: request.slug,
page: next_page,
limit: request.limit,
sorting: request.sorting,
http_headers: http_headers
)
end
return response
else
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"Unknown content type received"
)
end
elsif Utils.match_status_code(http_response.status, ["422"])
if Utils.match_content_type(content_type, "application/json")
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
response_data = http_response.env.response_body
obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::HTTPValidationError)
raise obj
else
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"Unknown content type received"
)
end
elsif Utils.match_status_code(http_response.status, ["4XX"])
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"API error occurred"
)
elsif Utils.match_status_code(http_response.status, ["5XX"])
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"API error occurred"
)
else
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"Unknown status code received"
)
end
end
def update(body:, id:, timeout_ms: nil, http_headers: nil)
def update(body:, id:, timeout_ms: nil, http_headers: nil)
# update - Update Organization
# Update an organization.
#
# **Scopes**: `organizations:write`
request = Models::Operations::OrganizationsUpdateRequest.new(
id: id,
body: body
)
url, params = @sdk_configuration.get_server_details
base_url = Utils.template_url(url, params)
url = Utils.generate_url(
Models::Operations::OrganizationsUpdateRequest,
base_url,
"/v1/organizations/{id}",
request
)
headers = {}
headers = T.cast(headers, T::Hash[String, String])
req_content_type, data, form = Utils.serialize_request_body(request, false, false, :body, :json)
headers["content-type"] = req_content_type
raise StandardError, "request body is required" if data.nil? && form.nil?
if form && !form.empty?
body = Utils.encode_form(form)
elsif Utils.match_content_type(req_content_type, "application/x-www-form-urlencoded")
body = URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
else
body = data
end
headers["Accept"] = "application/json"
headers["user-agent"] = @sdk_configuration.user_agent
security = @sdk_configuration.security_source&.call
timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
timeout ||= @sdk_configuration.timeout
connection = @sdk_configuration.client
hook_ctx = SDKHooks::HookContext.new(
config: @sdk_configuration,
base_url: base_url,
oauth2_scopes: nil,
operation_id: "organizations:update",
security_source: @sdk_configuration.security_source
)
error = T.let(nil, T.nilable(StandardError))
http_response = T.let(nil, T.nilable(Faraday::Response))
begin
http_response = T.must(connection).patch(url) do |req|
req.body = body
req.headers.merge!(headers)
req.options.timeout = timeout unless timeout.nil?
Utils.configure_request_security(req, security)
http_headers&.each do |key, value|
req.headers[key.to_s] = value
end
@sdk_configuration.hooks.before_request(
hook_ctx: SDKHooks::BeforeRequestHookContext.new(
hook_ctx: hook_ctx
),
request: req
)
end
rescue StandardError => e
error = e
ensure
if http_response.nil? || Utils.error_status?(http_response.status)
http_response = @sdk_configuration.hooks.after_error(
error: error,
hook_ctx: SDKHooks::AfterErrorHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
else
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
end
if http_response.nil?
raise error if !error.nil?
raise "no response"
end
end
content_type = http_response.headers.fetch("Content-Type", "application/octet-stream")
if Utils.match_status_code(http_response.status, ["200"])
if Utils.match_content_type(content_type, "application/json")
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
response_data = http_response.env.response_body
obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Components::Organization)
response = Models::Operations::OrganizationsUpdateResponse.new(
status_code: http_response.status,
content_type: content_type,
raw_response: http_response,
organization: T.unsafe(obj)
)
return response
else
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"Unknown content type received"
)
end
elsif Utils.match_status_code(http_response.status, ["403"])
if Utils.match_content_type(content_type, "application/json")
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
response_data = http_response.env.response_body
obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::NotPermitted)
raise obj
else
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"Unknown content type received"
)
end
elsif Utils.match_status_code(http_response.status, ["404"])
if Utils.match_content_type(content_type, "application/json")
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
response_data = http_response.env.response_body
obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::ResourceNotFound)
raise obj
else
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"Unknown content type received"
)
end
elsif Utils.match_status_code(http_response.status, ["422"])
if Utils.match_content_type(content_type, "application/json")
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
response_data = http_response.env.response_body
obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::HTTPValidationError)
raise obj
else
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"Unknown content type received"
)
end
elsif Utils.match_status_code(http_response.status, ["4XX"])
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"API error occurred"
)
elsif Utils.match_status_code(http_response.status, ["5XX"])
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"API error occurred"
)
else
raise(
::OpenApiSDK::Models::Errors::APIError.new(
status_code: http_response.status,
body: http_response.env.response_body,
raw_response: http_response
),
"Unknown status code received"
)
end
end