From 743c4e3ee1f04b394c4b1cc2af46901eff7480f4 Mon Sep 17 00:00:00 2001 From: Andy Brody Date: Thu, 9 Apr 2015 18:19:05 -0700 Subject: [PATCH] Also handle uname on jruby, windows, bsd. And add RUBY_ENGINE to the reported information if it exists. --- lib/stripe.rb | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/stripe.rb b/lib/stripe.rb index aeeb11ed..7af50e74 100644 --- a/lib/stripe.rb +++ b/lib/stripe.rb @@ -2,6 +2,7 @@ # API spec at https://stripe.com/docs/api require 'cgi' require 'openssl' +require 'rbconfig' require 'set' require 'socket' @@ -160,6 +161,7 @@ module Stripe :lang => 'ruby', :lang_version => lang_version, :platform => RUBY_PLATFORM, + :engine => defined?(RUBY_ENGINE) ? RUBY_ENGINE : '', :publisher => 'stripe', :uname => @uname, :hostname => Socket.gethostname, @@ -168,17 +170,33 @@ module Stripe end def self.get_uname - begin + if File.exist?('/proc/version') File.read('/proc/version').strip - rescue SystemCallError - begin - `uname -a 2>/dev/null`.strip if RUBY_PLATFORM =~ /linux|darwin/i - rescue Errno::ENOMEM # couldn't create subprocess - "uname lookup failed" + else + case RbConfig::CONFIG['host_os'] + when /linux|darwin|bsd|sunos|solaris|cygwin/i + _uname_uname + when /mswin|mingw/i + _uname_ver + else + "unknown platform" end end end + def self._uname_uname + (`uname -a 2>/dev/null` || '').strip + rescue Errno::ENOMEM + "uname lookup failed" + end + + def self._uname_ver + (`ver` || '').strip + rescue Errno::ENOMEM + "uname lookup failed" + end + + def self.uri_encode(params) Util.flatten_params(params). map { |k,v| "#{k}=#{Util.url_encode(v)}" }.join('&')