From d046a876f9303f5bbb41e13a0cbc7a367e3b13a1 Mon Sep 17 00:00:00 2001 From: Andy Brody Date: Sun, 2 Nov 2014 18:54:09 -0800 Subject: [PATCH] Prefer reading /proc/version over calling uname. This will be way faster on linux systems than shelling out to uname. Also add hostname from Socket.gethostname since that information is provided by `uname -a` but not /proc/version. --- lib/stripe.rb | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/stripe.rb b/lib/stripe.rb index 16249753..aeeb11ed 100644 --- a/lib/stripe.rb +++ b/lib/stripe.rb @@ -1,9 +1,11 @@ # Stripe Ruby bindings # API spec at https://stripe.com/docs/api require 'cgi' -require 'set' require 'openssl' -require 'rest_client' +require 'set' +require 'socket' + +require 'rest-client' require 'json' # Version @@ -159,15 +161,22 @@ module Stripe :lang_version => lang_version, :platform => RUBY_PLATFORM, :publisher => 'stripe', - :uname => @uname + :uname => @uname, + :hostname => Socket.gethostname, } end def self.get_uname - `uname -a 2>/dev/null`.strip if RUBY_PLATFORM =~ /linux|darwin/i - rescue Errno::ENOMEM => ex # couldn't create subprocess - "uname lookup failed" + begin + 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" + end + end end def self.uri_encode(params)