Fixed some YARD documentation issues and changed how the user-agent is built.
[arvados.git] / lib / google / api_client.rb
index e12a9d637194d1f979f36e6a4cd52893beeb6b03..f01a8d93ec619b56718ea972a3f9712df4f1fd4d 100644 (file)
@@ -17,12 +17,14 @@ require 'httpadapter'
 require 'json'
 require 'stringio'
 
+require 'google/api_client/version'
 require 'google/api_client/errors'
 require 'google/api_client/environment'
 require 'google/api_client/discovery'
 require 'google/api_client/reference'
 require 'google/api_client/result'
 
+
 module Google
   # TODO(bobaman): Document all this stuff.
 
@@ -46,8 +48,9 @@ module Google
     # @option options [String] :host ("www.googleapis.com")
     #   The API hostname used by the client.  This rarely needs to be changed.
     # @option options [String] :application_name
-    #   The name and version of the application using the client. This should
-    #   be given in the form `"{name}/{version}"`.
+    #   The name of the application using the client.
+    # @option options [String] :application_version
+    #   The version number of the application using the client.
     # @option options [String] :user_agent
     #   ("{app_name} google-api-ruby-client/{version} {os_name}/{os_version}")
     #   The user agent used by the client.  Most developers will want to
@@ -62,10 +65,16 @@ module Google
       self.host = options["host"] || 'www.googleapis.com'
       # Most developers will want to leave this value alone and use the
       # application_name option.
+      application_string = (
+        options["application_name"] ? (
+          "#{options["application_name"]}/" +
+          "#{options["application_version"] || '0.0.0'}"
+        ) : ""
+      )
       self.user_agent = options["user_agent"] || (
-        (options["application_name"] || '')
-        'google-api-ruby-client/' + VERSION::STRING +
-        ' ' + ENV::OS_VERSION
+        "#{application_string} " +
+        "google-api-ruby-client/#{VERSION::STRING} " +
+         ENV::OS_VERSION
       ).strip
       # The writer method understands a few Symbols and will generate useful
       # default authentication mechanisms.
@@ -147,7 +156,7 @@ module Google
     ##
     # The application's API key issued by the API console.
     #
-    # @return [String] The API key..
+    # @return [String] The API key.
     attr_accessor :key
 
     ##
@@ -594,10 +603,13 @@ module Google
     def execute!(*params)
       result = self.execute(*params)
       status, _, _ = result.response
-      if result.data.respond_to?(:error)
+      if result.data.respond_to?(:error) &&
+          result.data.error.respond_to?(:message)
         # You're going to get a terrible error message if the response isn't
         # parsed successfully as an error.
-        error_message = result.data.error
+        error_message = result.data.error.message
+      elsif result.data['error'] && result.data['error']['message']
+        error_message = result.data['error']['message']
       end
       if status >= 400 && status < 500
         raise ClientError,