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

UNAME_HASH =
begin
  parts = []
  parts << if RUBY_PLATFORM.match?(/mswin|mingw|cygwin/)
             begin
               `ver 2>NUL`.strip
             rescue StandardError
               ""
             end
           else
             begin
               `uname -a 2>/dev/null`.strip
             rescue StandardError
               ""
             end
           end
  parts << begin
    Socket.gethostname
  rescue StandardError
    ""
  end
  Digest::MD5.hexdigest(parts.join(" "))
rescue StandardError
  ""
end
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



1148
1149
1150
1151
1152
1153
# File 'lib/stripe/api_requestor.rb', line 1148

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



1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
# File 'lib/stripe/api_requestor.rb', line 1155

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? }

  if Stripe.enable_telemetry?
    ua[:platform] = RUBY_PLATFORM
    ua[:source] = UNAME_HASH unless UNAME_HASH.empty?
  end

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

  ua
end