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[OPENCODE open_code],
  # aiAgents: The end of the section generated from our OpenAPI spec
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSystemProfiler

Returns a new instance of SystemProfiler.



1154
1155
1156
# File 'lib/stripe/api_requestor.rb', line 1154

def initialize
  @uname = self.class.uname
end

Class Method Details

.detect_ai_agent(env = ENV) ⇒ Object



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

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

.unameObject



1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
# File 'lib/stripe/api_requestor.rb', line 1101

def self.uname
  if ::File.exist?("/proc/version")
    ::File.read("/proc/version").strip
  else
    case RbConfig::CONFIG["host_os"]
    when /linux|darwin|bsd|sunos|solaris|cygwin/i
      uname_from_system
    when /mswin|mingw/i
      uname_from_system_ver
    else
      "unknown platform"
    end
  end
end

.uname_from_systemObject



1116
1117
1118
1119
1120
1121
1122
# File 'lib/stripe/api_requestor.rb', line 1116

def self.uname_from_system
  (`uname -a 2>/dev/null` || "").strip
rescue Errno::ENOENT
  "uname executable not found"
rescue Errno::ENOMEM # couldn't create subprocess
  "uname lookup failed"
end

.uname_from_system_verObject



1124
1125
1126
1127
1128
1129
1130
# File 'lib/stripe/api_requestor.rb', line 1124

def self.uname_from_system_ver
  (`ver` || "").strip
rescue Errno::ENOENT
  "ver executable not found"
rescue Errno::ENOMEM # couldn't create subprocess
  "uname lookup failed"
end

Instance Method Details

#user_agentObject



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

def 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,
    platform: RUBY_PLATFORM,
    engine: defined?(RUBY_ENGINE) ? RUBY_ENGINE : "",
    publisher: "stripe",
    uname: @uname,
    hostname: Socket.gethostname,
  }.delete_if { |_k, v| v.nil? }

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

  ua
end