Skip to content
Merged
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
52 changes: 28 additions & 24 deletions lib/requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,27 @@

module SSOReady
class RequestClient
# @return [Hash{String => String}]
attr_reader :headers
# @return [Faraday]
attr_reader :conn
# @return [String]
attr_reader :base_url
# @return [String]
attr_reader :api_key
# @return [String]
attr_reader :default_environment

# @param environment [SSOReady::Environment]
# @param base_url [String]
# @param environment [SSOReady::Environment]
# @param max_retries [Long] The number of times to retry a failed request, defaults to 2.
# @param timeout_in_seconds [Long]
# @param api_key [String]
# @return [SSOReady::RequestClient]
def initialize(environment: SSOReady::Environment::DEFAULT, base_url: nil, max_retries: nil,
timeout_in_seconds: nil, api_key: nil)
def initialize(base_url: nil, environment: SSOReady::Environment::DEFAULT, max_retries: nil,
timeout_in_seconds: nil, api_key: ENV["SSOREADY_API_KEY"])
@default_environment = environment
@base_url = environment || base_url
@headers = {
"X-Fern-Language": "Ruby",
"X-Fern-SDK-Name": "ssoready",
"X-Fern-SDK-Version": "0.1.0",
"Authorization": %(Bearer #{api_key || ENV["SSOREADY_API_KEY"]})
}
@conn = Faraday.new(headers: @headers) do |faraday|
@api_key = "Bearer #{api_key}"
@conn = Faraday.new do |faraday|
faraday.request :json
faraday.response :raise_error, include_request: true
faraday.request :retry, { max: max_retries } unless max_retries.nil?
Expand All @@ -45,35 +40,37 @@ def initialize(environment: SSOReady::Environment::DEFAULT, base_url: nil, max_r
def get_url(request_options: nil)
request_options&.base_url || @default_environment || @base_url
end

# @return [Hash{String => String}]
def get_headers
headers = { "X-Fern-Language": "Ruby", "X-Fern-SDK-Name": "ssoready", "X-Fern-SDK-Version": "1.0.0" }
headers["Authorization"] = ((@api_key.is_a? Method) ? @api_key.call : @api_key) unless @api_key.nil?
headers
end
end

class AsyncRequestClient
# @return [Hash{String => String}]
attr_reader :headers
# @return [Faraday]
attr_reader :conn
# @return [String]
attr_reader :base_url
# @return [String]
attr_reader :api_key
# @return [String]
attr_reader :default_environment

# @param environment [SSOReady::Environment]
# @param base_url [String]
# @param environment [SSOReady::Environment]
# @param max_retries [Long] The number of times to retry a failed request, defaults to 2.
# @param timeout_in_seconds [Long]
# @param api_key [String]
# @return [SSOReady::AsyncRequestClient]
def initialize(environment: SSOReady::Environment::DEFAULT, base_url: nil, max_retries: nil,
timeout_in_seconds: nil, api_key: nil)
def initialize(base_url: nil, environment: SSOReady::Environment::DEFAULT, max_retries: nil,
timeout_in_seconds: nil, api_key: ENV["SSOREADY_API_KEY"])
@default_environment = environment
@base_url = environment || base_url
@headers = {
"X-Fern-Language": "Ruby",
"X-Fern-SDK-Name": "ssoready",
"X-Fern-SDK-Version": "0.1.0",
"Authorization": %(Bearer #{api_key || ENV["SSOREADY_API_KEY"]})
}
@conn = Faraday.new(headers: @headers) do |faraday|
@api_key = "Bearer #{api_key}"
@conn = Faraday.new do |faraday|
faraday.request :json
faraday.response :raise_error, include_request: true
faraday.adapter :async_http
Expand All @@ -87,6 +84,13 @@ def initialize(environment: SSOReady::Environment::DEFAULT, base_url: nil, max_r
def get_url(request_options: nil)
request_options&.base_url || @default_environment || @base_url
end

# @return [Hash{String => String}]
def get_headers
headers = { "X-Fern-Language": "Ruby", "X-Fern-SDK-Name": "ssoready", "X-Fern-SDK-Version": "1.0.0" }
headers["Authorization"] = ((@api_key.is_a? Method) ? @api_key.call : @api_key) unless @api_key.nil?
headers
end
end

# Additional options for request-specific configuration when calling APIs via the
Expand Down
16 changes: 8 additions & 8 deletions lib/ssoready.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ class Client
# @return [SSOReady::Management::Client]
attr_reader :management

# @param environment [SSOReady::Environment]
# @param base_url [String]
# @param environment [SSOReady::Environment]
# @param max_retries [Long] The number of times to retry a failed request, defaults to 2.
# @param timeout_in_seconds [Long]
# @param api_key [String]
# @return [SSOReady::Client]
def initialize(environment: SSOReady::Environment::DEFAULT, base_url: nil, max_retries: nil,
timeout_in_seconds: nil, api_key: nil)
def initialize(base_url: nil, environment: SSOReady::Environment::DEFAULT, max_retries: nil,
timeout_in_seconds: nil, api_key: ENV["SSOREADY_API_KEY"])
@request_client = SSOReady::RequestClient.new(
environment: environment,
base_url: base_url,
environment: environment,
max_retries: max_retries,
timeout_in_seconds: timeout_in_seconds,
api_key: api_key
Expand All @@ -45,17 +45,17 @@ class AsyncClient
# @return [SSOReady::Management::AsyncClient]
attr_reader :management

# @param environment [SSOReady::Environment]
# @param base_url [String]
# @param environment [SSOReady::Environment]
# @param max_retries [Long] The number of times to retry a failed request, defaults to 2.
# @param timeout_in_seconds [Long]
# @param api_key [String]
# @return [SSOReady::AsyncClient]
def initialize(environment: SSOReady::Environment::DEFAULT, base_url: nil, max_retries: nil,
timeout_in_seconds: nil, api_key: nil)
def initialize(base_url: nil, environment: SSOReady::Environment::DEFAULT, max_retries: nil,
timeout_in_seconds: nil, api_key: ENV["SSOREADY_API_KEY"])
@async_request_client = SSOReady::AsyncRequestClient.new(
environment: environment,
base_url: base_url,
environment: environment,
max_retries: max_retries,
timeout_in_seconds: timeout_in_seconds,
api_key: api_key
Expand Down
94 changes: 78 additions & 16 deletions lib/ssoready/management/organizations/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,24 @@ def initialize(request_client:)
# @return [SSOReady::ListOrganizationsResponse]
# @example
# api = SSOReady::Client.new(
# environment: SSOReady::Environment::DEFAULT,
# base_url: "https://api.example.com",
# environment: SSOReady::Environment::DEFAULT,
# api_key: "YOUR_AUTH_TOKEN"
# )
# api.management.organizations.list_organizations
def list_organizations(page_token: nil, request_options: nil)
response = @request_client.conn.get do |req|
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
req.headers = {
**(req.headers || {}),
**@request_client.get_headers,
**(request_options&.additional_headers || {})
}.compact
req.params = { **(request_options&.additional_query_parameters || {}), "pageToken": page_token }.compact
unless request_options.nil? || request_options&.additional_body_parameters.nil?
req.body = { **(request_options&.additional_body_parameters || {}) }.compact
end
req.url "#{@request_client.get_url(request_options: request_options)}/v1/organizations"
end
SSOReady::ListOrganizationsResponse.from_json(json_object: response.body)
Expand All @@ -55,16 +62,23 @@ def list_organizations(page_token: nil, request_options: nil)
# @return [SSOReady::CreateOrganizationResponse]
# @example
# api = SSOReady::Client.new(
# environment: SSOReady::Environment::DEFAULT,
# base_url: "https://api.example.com",
# environment: SSOReady::Environment::DEFAULT,
# api_key: "YOUR_AUTH_TOKEN"
# )
# api.management.organizations.create_organization(request: { })
def create_organization(request:, request_options: nil)
response = @request_client.conn.post do |req|
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
req.headers = {
**(req.headers || {}),
**@request_client.get_headers,
**(request_options&.additional_headers || {})
}.compact
unless request_options.nil? || request_options&.additional_query_parameters.nil?
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
end
req.body = { **(request || {}), **(request_options&.additional_body_parameters || {}) }.compact
req.url "#{@request_client.get_url(request_options: request_options)}/v1/organizations"
end
Expand All @@ -78,16 +92,26 @@ def create_organization(request:, request_options: nil)
# @return [SSOReady::GetOrganizationResponse]
# @example
# api = SSOReady::Client.new(
# environment: SSOReady::Environment::DEFAULT,
# base_url: "https://api.example.com",
# environment: SSOReady::Environment::DEFAULT,
# api_key: "YOUR_AUTH_TOKEN"
# )
# api.management.organizations.get_organization(id: "id")
def get_organization(id:, request_options: nil)
response = @request_client.conn.get do |req|
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
req.headers = {
**(req.headers || {}),
**@request_client.get_headers,
**(request_options&.additional_headers || {})
}.compact
unless request_options.nil? || request_options&.additional_query_parameters.nil?
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
end
unless request_options.nil? || request_options&.additional_body_parameters.nil?
req.body = { **(request_options&.additional_body_parameters || {}) }.compact
end
req.url "#{@request_client.get_url(request_options: request_options)}/v1/organizations/#{id}"
end
SSOReady::GetOrganizationResponse.from_json(json_object: response.body)
Expand All @@ -106,16 +130,23 @@ def get_organization(id:, request_options: nil)
# @return [SSOReady::UpdateOrganizationResponse]
# @example
# api = SSOReady::Client.new(
# environment: SSOReady::Environment::DEFAULT,
# base_url: "https://api.example.com",
# environment: SSOReady::Environment::DEFAULT,
# api_key: "YOUR_AUTH_TOKEN"
# )
# api.management.organizations.update_organization(id: "id", request: { })
def update_organization(id:, request:, request_options: nil)
response = @request_client.conn.patch do |req|
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
req.headers = {
**(req.headers || {}),
**@request_client.get_headers,
**(request_options&.additional_headers || {})
}.compact
unless request_options.nil? || request_options&.additional_query_parameters.nil?
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
end
req.body = { **(request || {}), **(request_options&.additional_body_parameters || {}) }.compact
req.url "#{@request_client.get_url(request_options: request_options)}/v1/organizations/#{id}"
end
Expand All @@ -140,8 +171,8 @@ def initialize(request_client:)
# @return [SSOReady::ListOrganizationsResponse]
# @example
# api = SSOReady::Client.new(
# environment: SSOReady::Environment::DEFAULT,
# base_url: "https://api.example.com",
# environment: SSOReady::Environment::DEFAULT,
# api_key: "YOUR_AUTH_TOKEN"
# )
# api.management.organizations.list_organizations
Expand All @@ -150,8 +181,15 @@ def list_organizations(page_token: nil, request_options: nil)
response = @request_client.conn.get do |req|
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
req.headers = {
**(req.headers || {}),
**@request_client.get_headers,
**(request_options&.additional_headers || {})
}.compact
req.params = { **(request_options&.additional_query_parameters || {}), "pageToken": page_token }.compact
unless request_options.nil? || request_options&.additional_body_parameters.nil?
req.body = { **(request_options&.additional_body_parameters || {}) }.compact
end
req.url "#{@request_client.get_url(request_options: request_options)}/v1/organizations"
end
SSOReady::ListOrganizationsResponse.from_json(json_object: response.body)
Expand All @@ -170,8 +208,8 @@ def list_organizations(page_token: nil, request_options: nil)
# @return [SSOReady::CreateOrganizationResponse]
# @example
# api = SSOReady::Client.new(
# environment: SSOReady::Environment::DEFAULT,
# base_url: "https://api.example.com",
# environment: SSOReady::Environment::DEFAULT,
# api_key: "YOUR_AUTH_TOKEN"
# )
# api.management.organizations.create_organization(request: { })
Expand All @@ -180,7 +218,14 @@ def create_organization(request:, request_options: nil)
response = @request_client.conn.post do |req|
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
req.headers = {
**(req.headers || {}),
**@request_client.get_headers,
**(request_options&.additional_headers || {})
}.compact
unless request_options.nil? || request_options&.additional_query_parameters.nil?
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
end
req.body = { **(request || {}), **(request_options&.additional_body_parameters || {}) }.compact
req.url "#{@request_client.get_url(request_options: request_options)}/v1/organizations"
end
Expand All @@ -195,8 +240,8 @@ def create_organization(request:, request_options: nil)
# @return [SSOReady::GetOrganizationResponse]
# @example
# api = SSOReady::Client.new(
# environment: SSOReady::Environment::DEFAULT,
# base_url: "https://api.example.com",
# environment: SSOReady::Environment::DEFAULT,
# api_key: "YOUR_AUTH_TOKEN"
# )
# api.management.organizations.get_organization(id: "id")
Expand All @@ -205,7 +250,17 @@ def get_organization(id:, request_options: nil)
response = @request_client.conn.get do |req|
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
req.headers = {
**(req.headers || {}),
**@request_client.get_headers,
**(request_options&.additional_headers || {})
}.compact
unless request_options.nil? || request_options&.additional_query_parameters.nil?
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
end
unless request_options.nil? || request_options&.additional_body_parameters.nil?
req.body = { **(request_options&.additional_body_parameters || {}) }.compact
end
req.url "#{@request_client.get_url(request_options: request_options)}/v1/organizations/#{id}"
end
SSOReady::GetOrganizationResponse.from_json(json_object: response.body)
Expand All @@ -225,8 +280,8 @@ def get_organization(id:, request_options: nil)
# @return [SSOReady::UpdateOrganizationResponse]
# @example
# api = SSOReady::Client.new(
# environment: SSOReady::Environment::DEFAULT,
# base_url: "https://api.example.com",
# environment: SSOReady::Environment::DEFAULT,
# api_key: "YOUR_AUTH_TOKEN"
# )
# api.management.organizations.update_organization(id: "id", request: { })
Expand All @@ -235,7 +290,14 @@ def update_organization(id:, request:, request_options: nil)
response = @request_client.conn.patch do |req|
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
req.headers = {
**(req.headers || {}),
**@request_client.get_headers,
**(request_options&.additional_headers || {})
}.compact
unless request_options.nil? || request_options&.additional_query_parameters.nil?
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
end
req.body = { **(request || {}), **(request_options&.additional_body_parameters || {}) }.compact
req.url "#{@request_client.get_url(request_options: request_options)}/v1/organizations/#{id}"
end
Expand Down
Loading