From 4d56bb8b1b49a48b2d9f8c06e6c1c566f739ebfb Mon Sep 17 00:00:00 2001 From: Bob Aman Date: Wed, 4 May 2011 22:43:33 +0000 Subject: [PATCH] Added User-Agent improvements. git-svn-id: https://google-api-ruby-client.googlecode.com/svn/trunk@133 c1d61fac-ed7f-fcc1-18f7-ff78120a04ef --- lib/google/api_client.rb | 10 +++++++--- lib/google/api_client/environment.rb | 13 +++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 lib/google/api_client/environment.rb diff --git a/lib/google/api_client.rb b/lib/google/api_client.rb index 07f3a13ab8..50c305b668 100644 --- a/lib/google/api_client.rb +++ b/lib/google/api_client.rb @@ -18,6 +18,7 @@ require 'json' require 'stringio' require 'google/api_client/errors' +require 'google/api_client/environment' require 'google/api_client/discovery' module Google @@ -54,10 +55,13 @@ module Google end # Almost all API usage will have a host of 'www.googleapis.com'. self.host = options["host"] || 'www.googleapis.com' - # Most developers will want to leave this value alone. + # Most developers will want to leave this value alone and use the + # application_name option. self.user_agent = options["user_agent"] || ( - 'google-api-ruby-client/' + Google::APIClient::VERSION::STRING - ) + (options["application_name"] || '') + 'google-api-ruby-client/' + VERSION::STRING + + ' ' + ENV::OS_VERSION + ).strip # This is mostly a default for the sake of convenience. # Unlike most other options, this one may be nil, so we check for # the presence of the key rather than checking the value. diff --git a/lib/google/api_client/environment.rb b/lib/google/api_client/environment.rb new file mode 100644 index 0000000000..4886048668 --- /dev/null +++ b/lib/google/api_client/environment.rb @@ -0,0 +1,13 @@ +module Google + class APIClient + module ENV + OS_VERSION = if RUBY_PLATFORM =~ /win32/ + `ver`.sub(/\s*\[Version\s*/, '/').sub(']', '') + elsif RUBY_PLATFORM =~ /darwin/i + "Mac OS X/#{`sw_vers -productVersion`}" + else + `uname -sr`.sub(' ', '/') + end + end + end +end -- 2.30.2