Class: Stripe::APIRequestor::SystemProfiler

Inherits:
Object
  • Object
show all
Defined in:
lib/stripe/api_requestor.rb

Overview

SystemProfiler extracts information about the system that we're running in so that we can generate a rich user agent header to help debug integrations.

Constant Summary collapse

AI_AGENTS =
[
  # aiAgents: The beginning of the section generated from our OpenAPI spec
  %w[ANTIGRAVITY_CLI_ALIAS antigravity],
  %w[CLAUDECODE claude_code],
  %w[CLINE_ACTIVE cline],
  %w[CODEX_SANDBOX codex_cli],
  %w[CODEX_THREAD_ID codex_cli],
  %w[CODEX_SANDBOX_NETWORK_DISABLED codex_cli],
  %w[CODEX_CI codex_cli],
  %w[CURSOR_AGENT cursor],
  %w[GEMINI_CLI gemini_cli],
  %w[OPENCLAW_SHELL openclaw],
  %w[OPENCODE open_code],
  # aiAgents: The end of the section generated from our OpenAPI spec
].freeze

Class Method Summary collapse

Class Method Details

.detect_ai_agent(env = ENV) ⇒ Object



1082
1083
1084
1085
1086
1087
# File 'lib/stripe/api_requestor.rb', line 1082

def self.detect_ai_agent(env = ENV)
  AI_AGENTS.each do |env_var, agent_name|
    return agent_name if env[env_var] && !env[env_var].empty?
  end
  ""
end

.user_agentObject



1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
# File 'lib/stripe/api_requestor.rb', line 1089

def self.user_agent
  lang_version = "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} " \
                 "(#{RUBY_RELEASE_DATE})"

  ua = {
    application: Stripe.app_info,
    bindings_version: Stripe::VERSION,
    lang: "ruby",
    lang_version: lang_version,
    engine: defined?(RUBY_ENGINE) ? RUBY_ENGINE : "",
  }.delete_if { |_k, v| v.nil? }

  ua[:platform] = RUBY_PLATFORM if Stripe.enable_telemetry?

  ai_agent = detect_ai_agent
  ua[:ai_agent] = ai_agent unless ai_agent.empty?

  ua
end