From 349c26fa8bf0de53d915c81a03da65d99c53de0c Mon Sep 17 00:00:00 2001 From: Mike Moore Date: Wed, 25 Mar 2015 17:03:20 -0600 Subject: [PATCH] Fix warning: assigned but unused variable There are several places where varaibles are assigned but not used. The variables can be replaced with _, or prepended with _ to avoid a warning. In one case the variable was removed because it was at the end of the method. Addresses the following warnings: lib/google/api_client.rb:493: warning: assigned but unused variable - key lib/google/api_client/batch.rb:168: warning: assigned but unused variable - callback lib/google/api_client/batch.rb:227: warning: assigned but unused variable - base lib/google/api_client/batch.rb:271: warning: assigned but unused variable - protocol lib/google/api_client/batch.rb:271: warning: assigned but unused variable - reason lib/google/api_client/request.rb:247: warning: assigned but unused variable - request_env --- lib/google/api_client.rb | 2 +- lib/google/api_client/batch.rb | 42 ++++++++++++++++---------------- lib/google/api_client/request.rb | 6 ++--- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/google/api_client.rb b/lib/google/api_client.rb index 367b1e040..ef3c2b1d3 100644 --- a/lib/google/api_client.rb +++ b/lib/google/api_client.rb @@ -490,7 +490,7 @@ module Google else check_cached_certs = lambda do valid = false - for key, cert in @certificates + for _key, cert in @certificates begin self.authorization.decoded_id_token(cert.public_key) valid = true diff --git a/lib/google/api_client/batch.rb b/lib/google/api_client/batch.rb index f7b1e096b..627b7680a 100644 --- a/lib/google/api_client/batch.rb +++ b/lib/google/api_client/batch.rb @@ -35,7 +35,7 @@ module Google ## # Initialize the call response - # + # # @param [String] call_id # UUID of the original call # @param [Fixnum] status @@ -48,7 +48,7 @@ module Google @call_id, @status, @headers, @body = call_id, status, headers, body end end - + # Wraps multiple API calls into a single over-the-wire HTTP request. # # @example @@ -58,7 +58,7 @@ module Google # batch = Google::APIClient::BatchRequest.new do |result| # puts result.data # end - # + # # batch.add(:api_method => urlshortener.url.insert, :body_object => { 'longUrl' => 'http://example.com/foo' }) # batch.add(:api_method => urlshortener.url.insert, :body_object => { 'longUrl' => 'http://example.com/bar' }) # @@ -80,7 +80,7 @@ module Google # Callback for every call's response. Won't be called if a call defined # a callback of its own. # - # @return [Google::APIClient::BatchRequest] + # @return [Google::APIClient::BatchRequest] # The constructed object. # # @yield [Google::APIClient::Result] @@ -89,7 +89,7 @@ module Google @calls = [] @global_callback = block if block_given? @last_auto_id = 0 - + @base_id = SecureRandom.uuid options[:uri] ||= 'https://www.googleapis.com/batch' @@ -104,7 +104,7 @@ module Google # automatically be generated, avoiding collisions. If duplicate call IDs # are provided, an error will be thrown. # - # @param [Hash, Google::APIClient::Request] call + # @param [Hash, Google::APIClient::Request] call # the call to be added. # @param [String] call_id # the ID to be used for this call. Must be unique @@ -126,7 +126,7 @@ module Google 'A call with this ID already exists: %s' % call_id end callback = block_given? ? block : @global_callback - @calls << [call_id, call, callback] + @calls << [call_id, call, callback] return self end @@ -165,12 +165,12 @@ module Google if @calls.nil? || @calls.empty? raise BatchError, 'Cannot make an empty batch request' end - parts = @calls.map {|(call_id, call, callback)| serialize_call(call_id, call)} + parts = @calls.map {|(call_id, call, _callback)| serialize_call(call_id, call)} build_multipart(parts, 'multipart/mixed', BATCH_BOUNDARY) super end - - + + protected ## @@ -183,7 +183,7 @@ module Google # @param [Hash] headers # the hash of headers and their values. # - # @return [String] + # @return [String] # the value of the desired header. def find_header(name, headers) _, header = headers.detect do |h, v| @@ -197,7 +197,7 @@ module Google # # @api private # - # @return [String] + # @return [String] # the new, unique ID. def new_id @last_auto_id += 1 @@ -216,7 +216,7 @@ module Google # @param [String] header # Content-ID header value. # - # @return [String] + # @return [String] # The extracted ID value. def header_to_id(header) if !header.start_with?('<') || !header.end_with?('>') || @@ -224,7 +224,7 @@ module Google raise BatchError, 'Invalid value for Content-ID: "%s"' % header end - base, call_id = header[1...-1].split('+') + _base, call_id = header[1...-1].split('+') return Addressable::URI.unencode(call_id) end @@ -236,7 +236,7 @@ module Google # @param [String] response # the response to parse. # - # @return [Array, String] + # @return [Array, String] # the headers and the body, separately. def split_headers_and_body(response) headers = {} @@ -263,12 +263,12 @@ module Google # @param [String] call_response # the request to deserialize. # - # @return [Google::APIClient::BatchedCallResponse] + # @return [Google::APIClient::BatchedCallResponse] # the parsed and converted response. def deserialize_call_response(call_response) outer_headers, outer_body = split_headers_and_body(call_response) status_line, payload = outer_body.split("\n", 2) - protocol, status, reason = status_line.split(' ', 3) + _protocol, status, _reason = status_line.split(' ', 3) headers, body = split_headers_and_body(payload) content_id = find_header('Content-ID', outer_headers) @@ -284,7 +284,7 @@ module Google # @param [Google::APIClient::Request] call # the call to serialize. # - # @return [Faraday::UploadIO] + # @return [Faraday::UploadIO] # the serialized request def serialize_call(call_id, call) method, uri, headers, body = call.to_http_request @@ -293,7 +293,7 @@ module Google request << "\r\n%s: %s" % [header, value] end if body - # TODO - CompositeIO if body is a stream + # TODO - CompositeIO if body is a stream request << "\r\n\r\n" if body.respond_to?(:read) request << body.read @@ -303,7 +303,7 @@ module Google end Faraday::UploadIO.new(StringIO.new(request), 'application/http', 'ruby-api-request', 'Content-ID' => id_to_header(call_id)) end - + ## # Convert an id to a Content-ID header value. # @@ -319,7 +319,7 @@ module Google def id_to_header(call_id) return '<%s+%s>' % [@base_id, Addressable::URI.encode(call_id)] end - + end end end \ No newline at end of file diff --git a/lib/google/api_client/request.rb b/lib/google/api_client/request.rb index 8dc7aa617..d043e0016 100644 --- a/lib/google/api_client/request.rb +++ b/lib/google/api_client/request.rb @@ -27,7 +27,7 @@ module Google # Represents an API request. class Request include Google::APIClient::Logging - + MULTIPART_BOUNDARY = "-----------RubyApiMultipartPost".freeze # @return [Hash] Request parameters @@ -157,7 +157,7 @@ module Google # @return [Google::APIClient::Result] # result of API request def send(connection, is_retry = false) - self.body.rewind if is_retry && self.body.respond_to?(:rewind) + self.body.rewind if is_retry && self.body.respond_to?(:rewind) env = self.to_env(connection) logger.debug { "#{self.class} Sending API request #{env[:method]} #{env[:url].to_s} #{env[:request_headers]}" } http_response = connection.app.call(env) @@ -244,7 +244,7 @@ module Google ) end - request_env = http_request.to_env(connection) + http_request.to_env(connection) end ##