diff --git a/lib/google/api_client.rb b/lib/google/api_client.rb index 07f3a13ab..50c305b66 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 000000000..488604866 --- /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