Class: Stripe::APIRequestor::SystemProfiler
- Inherits:
-
Object
- Object
- Stripe::APIRequestor::SystemProfiler
- 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
- .detect_ai_agent(env = ENV) ⇒ Object
- .uname ⇒ Object
- .uname_from_system ⇒ Object
- .uname_from_system_ver ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ SystemProfiler
constructor
A new instance of SystemProfiler.
- #user_agent ⇒ Object
Constructor Details
#initialize ⇒ SystemProfiler
Returns a new instance of SystemProfiler.
1118 1119 1120 |
# File 'lib/stripe/api_requestor.rb', line 1118 def initialize @uname = self.class.uname end |
Class Method Details
.detect_ai_agent(env = ENV) ⇒ Object
1111 1112 1113 1114 1115 1116 |
# File 'lib/stripe/api_requestor.rb', line 1111 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 |
.uname ⇒ Object
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 |
# File 'lib/stripe/api_requestor.rb', line 1065 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_system ⇒ Object
1080 1081 1082 1083 1084 1085 1086 |
# File 'lib/stripe/api_requestor.rb', line 1080 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_ver ⇒ Object
1088 1089 1090 1091 1092 1093 1094 |
# File 'lib/stripe/api_requestor.rb', line 1088 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_agent ⇒ Object
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 |
# File 'lib/stripe/api_requestor.rb', line 1122 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 |