Class: Stripe::StripeClient::SystemProfiler

Inherits:
Object
  • Object
show all
Defined in:
lib/stripe/stripe_client.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



1019
1020
1021
# File 'lib/stripe/stripe_client.rb', line 1019

def initialize
  @uname = self.class.uname
end

Class Method Details

.unameObject



988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
# File 'lib/stripe/stripe_client.rb', line 988

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



1003
1004
1005
1006
1007
1008
1009
# File 'lib/stripe/stripe_client.rb', line 1003

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



1011
1012
1013
1014
1015
1016
1017
# File 'lib/stripe/stripe_client.rb', line 1011

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



1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
# File 'lib/stripe/stripe_client.rb', line 1023

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