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.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSystemProfiler

Returns a new instance of SystemProfiler.



1126
1127
1128
# File 'lib/stripe/api_requestor.rb', line 1126

def initialize
  @uname = self.class.uname
end

Class Method Details

.unameObject



1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
# File 'lib/stripe/api_requestor.rb', line 1095

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



1110
1111
1112
1113
1114
1115
1116
# File 'lib/stripe/api_requestor.rb', line 1110

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



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

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



1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
# File 'lib/stripe/api_requestor.rb', line 1130

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

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