# Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. # typed: true # frozen_string_literal: true require 'faraday' require 'faraday/multipart' require 'sorbet-runtime' module SpeakeasyClientSDK extend T::Sig SERVER_PROD = 'prod' SERVERS = { SERVER_PROD: 'https://api.prod.speakeasyapi.dev' }.freeze class SDK extend T::Sig attr_accessor :api_endpoints, :apis, :embeds, :metadata, :plugins, :requests, :schemas attr_accessor :security, :language, :sdk_version, :gen_version sig do params(security: Shared::Security, server: String, server_url: String, url_params: T::Hash[Symbol, String], client: Faraday::Request).void end def initialize(security: nil, server: nil, server_url: nil, url_params: nil, client: nil) ## Instantiates the SDK configuring it with the provided parameters. # @param [Shared::Security] security The security details required for authentication # @param [String] server The server by name to use for all operations # @param [String] server_url The server URL to use for all operations # @param [Hash] url_params Parameters to optionally template the server URL with # @param [Faraday::Request] client The faraday HTTP client to use for all operations @client = Faraday.new(request: { params_encoder: Faraday::FlatParamsEncoder }) do |f| f.request :multipart, {} # f.response :logger end @security = nil @server_url = SERVERS[SERVER_PROD] @language = 'ruby' @sdk_version = '1.0.1' @gen_version = '2.35.9' init_sdks end sig { params(server_url: String, params: T.nilable(T::Hash[Symbol, String])).void } def config_server_url(server_url, params) if params.nil? @server_url = server_url else @server_url = Utils.template_url(server_url, params) end init_sdks end sig { params(server: String, params: T.nilable(T::Hash[Symbol, String])).void } def config_server(server, params) raise StandardError, 'Invalid server' if !SERVERS.include? server config_server_url(SERVERS[server], params) init_sdks end sig { params(security: Shared::Security).void } def config_security(security) @security = security end sig { void } def init_sdks @api_endpoints = ApiEndpoints.new( self, @client, @server_url, @language, @sdk_version, @gen_version ) @apis = Apis.new( self, @client, @server_url, @language, @sdk_version, @gen_version ) @embeds = Embeds.new( self, @client, @server_url, @language, @sdk_version, @gen_version ) @metadata = Metadata.new( self, @client, @server_url, @language, @sdk_version, @gen_version ) @plugins = Plugins.new( self, @client, @server_url, @language, @sdk_version, @gen_version ) @requests = Requests.new( self, @client, @server_url, @language, @sdk_version, @gen_version ) @schemas = Schemas.new( self, @client, @server_url, @language, @sdk_version, @gen_version ) end sig { returns(Utils::FieldAugmented) } def validate_api_key # validate_api_key - Validate the current api key. base_url = @server_url url = "#{base_url.delete_suffix('/')}/v1/auth/validate" headers = {} headers['Accept'] = 'application/json' headers['user-agent'] = "speakeasy-sdk/#{@language} #{@sdk_version} #{@gen_version}" r = @client.get(url) do |req| req.headers = headers Utils.configure_request_security(req, @sdk.security) if !@sdk.nil? && !@sdk.security.nil? end content_type = r.headers.fetch('Content-Type', 'application/octet-stream') res = Operations::ValidateApiKeyResponse.new( status_code: r.status, content_type: content_type, raw_response: r ) if r.status == 200 else if Utils.match_content_type(content_type, 'application/json') out = Utils.unmarshal_complex(r.env.response_body, Shared::Error) res.error = out end end res end end end