Skip to content

Commit 349c26f

Browse files
committed
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
1 parent fb3fc46 commit 349c26f

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

lib/google/api_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ def verify_id_token!
490490
else
491491
check_cached_certs = lambda do
492492
valid = false
493-
for key, cert in @certificates
493+
for _key, cert in @certificates
494494
begin
495495
self.authorization.decoded_id_token(cert.public_key)
496496
valid = true

lib/google/api_client/batch.rb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class BatchedCallResponse
3535

3636
##
3737
# Initialize the call response
38-
#
38+
#
3939
# @param [String] call_id
4040
# UUID of the original call
4141
# @param [Fixnum] status
@@ -48,7 +48,7 @@ def initialize(call_id, status = nil, headers = nil, body = nil)
4848
@call_id, @status, @headers, @body = call_id, status, headers, body
4949
end
5050
end
51-
51+
5252
# Wraps multiple API calls into a single over-the-wire HTTP request.
5353
#
5454
# @example
@@ -58,7 +58,7 @@ def initialize(call_id, status = nil, headers = nil, body = nil)
5858
# batch = Google::APIClient::BatchRequest.new do |result|
5959
# puts result.data
6060
# end
61-
#
61+
#
6262
# batch.add(:api_method => urlshortener.url.insert, :body_object => { 'longUrl' => 'http://example.com/foo' })
6363
# batch.add(:api_method => urlshortener.url.insert, :body_object => { 'longUrl' => 'http://example.com/bar' })
6464
#
@@ -80,7 +80,7 @@ class BatchRequest < Request
8080
# Callback for every call's response. Won't be called if a call defined
8181
# a callback of its own.
8282
#
83-
# @return [Google::APIClient::BatchRequest]
83+
# @return [Google::APIClient::BatchRequest]
8484
# The constructed object.
8585
#
8686
# @yield [Google::APIClient::Result]
@@ -89,7 +89,7 @@ def initialize(options = {}, &block)
8989
@calls = []
9090
@global_callback = block if block_given?
9191
@last_auto_id = 0
92-
92+
9393
@base_id = SecureRandom.uuid
9494

9595
options[:uri] ||= 'https://www.googleapis.com/batch'
@@ -104,7 +104,7 @@ def initialize(options = {}, &block)
104104
# automatically be generated, avoiding collisions. If duplicate call IDs
105105
# are provided, an error will be thrown.
106106
#
107-
# @param [Hash, Google::APIClient::Request] call
107+
# @param [Hash, Google::APIClient::Request] call
108108
# the call to be added.
109109
# @param [String] call_id
110110
# the ID to be used for this call. Must be unique
@@ -126,7 +126,7 @@ def add(call, call_id = nil, &block)
126126
'A call with this ID already exists: %s' % call_id
127127
end
128128
callback = block_given? ? block : @global_callback
129-
@calls << [call_id, call, callback]
129+
@calls << [call_id, call, callback]
130130
return self
131131
end
132132

@@ -165,12 +165,12 @@ def to_http_request
165165
if @calls.nil? || @calls.empty?
166166
raise BatchError, 'Cannot make an empty batch request'
167167
end
168-
parts = @calls.map {|(call_id, call, callback)| serialize_call(call_id, call)}
168+
parts = @calls.map {|(call_id, call, _callback)| serialize_call(call_id, call)}
169169
build_multipart(parts, 'multipart/mixed', BATCH_BOUNDARY)
170170
super
171171
end
172-
173-
172+
173+
174174
protected
175175

176176
##
@@ -183,7 +183,7 @@ def to_http_request
183183
# @param [Hash] headers
184184
# the hash of headers and their values.
185185
#
186-
# @return [String]
186+
# @return [String]
187187
# the value of the desired header.
188188
def find_header(name, headers)
189189
_, header = headers.detect do |h, v|
@@ -197,7 +197,7 @@ def find_header(name, headers)
197197
#
198198
# @api private
199199
#
200-
# @return [String]
200+
# @return [String]
201201
# the new, unique ID.
202202
def new_id
203203
@last_auto_id += 1
@@ -216,15 +216,15 @@ def new_id
216216
# @param [String] header
217217
# Content-ID header value.
218218
#
219-
# @return [String]
219+
# @return [String]
220220
# The extracted ID value.
221221
def header_to_id(header)
222222
if !header.start_with?('<') || !header.end_with?('>') ||
223223
!header.include?('+')
224224
raise BatchError, 'Invalid value for Content-ID: "%s"' % header
225225
end
226226

227-
base, call_id = header[1...-1].split('+')
227+
_base, call_id = header[1...-1].split('+')
228228
return Addressable::URI.unencode(call_id)
229229
end
230230

@@ -236,7 +236,7 @@ def header_to_id(header)
236236
# @param [String] response
237237
# the response to parse.
238238
#
239-
# @return [Array<Hash>, String]
239+
# @return [Array<Hash>, String]
240240
# the headers and the body, separately.
241241
def split_headers_and_body(response)
242242
headers = {}
@@ -263,12 +263,12 @@ def split_headers_and_body(response)
263263
# @param [String] call_response
264264
# the request to deserialize.
265265
#
266-
# @return [Google::APIClient::BatchedCallResponse]
266+
# @return [Google::APIClient::BatchedCallResponse]
267267
# the parsed and converted response.
268268
def deserialize_call_response(call_response)
269269
outer_headers, outer_body = split_headers_and_body(call_response)
270270
status_line, payload = outer_body.split("\n", 2)
271-
protocol, status, reason = status_line.split(' ', 3)
271+
_protocol, status, _reason = status_line.split(' ', 3)
272272

273273
headers, body = split_headers_and_body(payload)
274274
content_id = find_header('Content-ID', outer_headers)
@@ -284,7 +284,7 @@ def deserialize_call_response(call_response)
284284
# @param [Google::APIClient::Request] call
285285
# the call to serialize.
286286
#
287-
# @return [Faraday::UploadIO]
287+
# @return [Faraday::UploadIO]
288288
# the serialized request
289289
def serialize_call(call_id, call)
290290
method, uri, headers, body = call.to_http_request
@@ -293,7 +293,7 @@ def serialize_call(call_id, call)
293293
request << "\r\n%s: %s" % [header, value]
294294
end
295295
if body
296-
# TODO - CompositeIO if body is a stream
296+
# TODO - CompositeIO if body is a stream
297297
request << "\r\n\r\n"
298298
if body.respond_to?(:read)
299299
request << body.read
@@ -303,7 +303,7 @@ def serialize_call(call_id, call)
303303
end
304304
Faraday::UploadIO.new(StringIO.new(request), 'application/http', 'ruby-api-request', 'Content-ID' => id_to_header(call_id))
305305
end
306-
306+
307307
##
308308
# Convert an id to a Content-ID header value.
309309
#
@@ -319,7 +319,7 @@ def serialize_call(call_id, call)
319319
def id_to_header(call_id)
320320
return '<%s+%s>' % [@base_id, Addressable::URI.encode(call_id)]
321321
end
322-
322+
323323
end
324324
end
325325
end

lib/google/api_client/request.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class APIClient
2727
# Represents an API request.
2828
class Request
2929
include Google::APIClient::Logging
30-
30+
3131
MULTIPART_BOUNDARY = "-----------RubyApiMultipartPost".freeze
3232

3333
# @return [Hash] Request parameters
@@ -157,7 +157,7 @@ def uri=(new_uri)
157157
# @return [Google::APIClient::Result]
158158
# result of API request
159159
def send(connection, is_retry = false)
160-
self.body.rewind if is_retry && self.body.respond_to?(:rewind)
160+
self.body.rewind if is_retry && self.body.respond_to?(:rewind)
161161
env = self.to_env(connection)
162162
logger.debug { "#{self.class} Sending API request #{env[:method]} #{env[:url].to_s} #{env[:request_headers]}" }
163163
http_response = connection.app.call(env)
@@ -244,7 +244,7 @@ def to_env(connection)
244244
)
245245
end
246246

247-
request_env = http_request.to_env(connection)
247+
http_request.to_env(connection)
248248
end
249249

250250
##

0 commit comments

Comments
 (0)