@@ -35,7 +35,7 @@ class BatchedCallResponse
35
35
36
36
##
37
37
# Initialize the call response
38
- #
38
+ #
39
39
# @param [String] call_id
40
40
# UUID of the original call
41
41
# @param [Fixnum] status
@@ -48,7 +48,7 @@ def initialize(call_id, status = nil, headers = nil, body = nil)
48
48
@call_id , @status , @headers , @body = call_id , status , headers , body
49
49
end
50
50
end
51
-
51
+
52
52
# Wraps multiple API calls into a single over-the-wire HTTP request.
53
53
#
54
54
# @example
@@ -58,7 +58,7 @@ def initialize(call_id, status = nil, headers = nil, body = nil)
58
58
# batch = Google::APIClient::BatchRequest.new do |result|
59
59
# puts result.data
60
60
# end
61
- #
61
+ #
62
62
# batch.add(:api_method => urlshortener.url.insert, :body_object => { 'longUrl' => 'http://example.com/foo' })
63
63
# batch.add(:api_method => urlshortener.url.insert, :body_object => { 'longUrl' => 'http://example.com/bar' })
64
64
#
@@ -80,7 +80,7 @@ class BatchRequest < Request
80
80
# Callback for every call's response. Won't be called if a call defined
81
81
# a callback of its own.
82
82
#
83
- # @return [Google::APIClient::BatchRequest]
83
+ # @return [Google::APIClient::BatchRequest]
84
84
# The constructed object.
85
85
#
86
86
# @yield [Google::APIClient::Result]
@@ -89,7 +89,7 @@ def initialize(options = {}, &block)
89
89
@calls = [ ]
90
90
@global_callback = block if block_given?
91
91
@last_auto_id = 0
92
-
92
+
93
93
@base_id = SecureRandom . uuid
94
94
95
95
options [ :uri ] ||= 'https://www.googleapis.com/batch'
@@ -104,7 +104,7 @@ def initialize(options = {}, &block)
104
104
# automatically be generated, avoiding collisions. If duplicate call IDs
105
105
# are provided, an error will be thrown.
106
106
#
107
- # @param [Hash, Google::APIClient::Request] call
107
+ # @param [Hash, Google::APIClient::Request] call
108
108
# the call to be added.
109
109
# @param [String] call_id
110
110
# the ID to be used for this call. Must be unique
@@ -126,7 +126,7 @@ def add(call, call_id = nil, &block)
126
126
'A call with this ID already exists: %s' % call_id
127
127
end
128
128
callback = block_given? ? block : @global_callback
129
- @calls << [ call_id , call , callback ]
129
+ @calls << [ call_id , call , callback ]
130
130
return self
131
131
end
132
132
@@ -165,12 +165,12 @@ def to_http_request
165
165
if @calls . nil? || @calls . empty?
166
166
raise BatchError , 'Cannot make an empty batch request'
167
167
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 ) }
169
169
build_multipart ( parts , 'multipart/mixed' , BATCH_BOUNDARY )
170
170
super
171
171
end
172
-
173
-
172
+
173
+
174
174
protected
175
175
176
176
##
@@ -183,7 +183,7 @@ def to_http_request
183
183
# @param [Hash] headers
184
184
# the hash of headers and their values.
185
185
#
186
- # @return [String]
186
+ # @return [String]
187
187
# the value of the desired header.
188
188
def find_header ( name , headers )
189
189
_ , header = headers . detect do |h , v |
@@ -197,7 +197,7 @@ def find_header(name, headers)
197
197
#
198
198
# @api private
199
199
#
200
- # @return [String]
200
+ # @return [String]
201
201
# the new, unique ID.
202
202
def new_id
203
203
@last_auto_id += 1
@@ -216,15 +216,15 @@ def new_id
216
216
# @param [String] header
217
217
# Content-ID header value.
218
218
#
219
- # @return [String]
219
+ # @return [String]
220
220
# The extracted ID value.
221
221
def header_to_id ( header )
222
222
if !header . start_with? ( '<' ) || !header . end_with? ( '>' ) ||
223
223
!header . include? ( '+' )
224
224
raise BatchError , 'Invalid value for Content-ID: "%s"' % header
225
225
end
226
226
227
- base , call_id = header [ 1 ...-1 ] . split ( '+' )
227
+ _base , call_id = header [ 1 ...-1 ] . split ( '+' )
228
228
return Addressable ::URI . unencode ( call_id )
229
229
end
230
230
@@ -236,7 +236,7 @@ def header_to_id(header)
236
236
# @param [String] response
237
237
# the response to parse.
238
238
#
239
- # @return [Array<Hash>, String]
239
+ # @return [Array<Hash>, String]
240
240
# the headers and the body, separately.
241
241
def split_headers_and_body ( response )
242
242
headers = { }
@@ -263,12 +263,12 @@ def split_headers_and_body(response)
263
263
# @param [String] call_response
264
264
# the request to deserialize.
265
265
#
266
- # @return [Google::APIClient::BatchedCallResponse]
266
+ # @return [Google::APIClient::BatchedCallResponse]
267
267
# the parsed and converted response.
268
268
def deserialize_call_response ( call_response )
269
269
outer_headers , outer_body = split_headers_and_body ( call_response )
270
270
status_line , payload = outer_body . split ( "\n " , 2 )
271
- protocol , status , reason = status_line . split ( ' ' , 3 )
271
+ _protocol , status , _reason = status_line . split ( ' ' , 3 )
272
272
273
273
headers , body = split_headers_and_body ( payload )
274
274
content_id = find_header ( 'Content-ID' , outer_headers )
@@ -284,7 +284,7 @@ def deserialize_call_response(call_response)
284
284
# @param [Google::APIClient::Request] call
285
285
# the call to serialize.
286
286
#
287
- # @return [Faraday::UploadIO]
287
+ # @return [Faraday::UploadIO]
288
288
# the serialized request
289
289
def serialize_call ( call_id , call )
290
290
method , uri , headers , body = call . to_http_request
@@ -293,7 +293,7 @@ def serialize_call(call_id, call)
293
293
request << "\r \n %s: %s" % [ header , value ]
294
294
end
295
295
if body
296
- # TODO - CompositeIO if body is a stream
296
+ # TODO - CompositeIO if body is a stream
297
297
request << "\r \n \r \n "
298
298
if body . respond_to? ( :read )
299
299
request << body . read
@@ -303,7 +303,7 @@ def serialize_call(call_id, call)
303
303
end
304
304
Faraday ::UploadIO . new ( StringIO . new ( request ) , 'application/http' , 'ruby-api-request' , 'Content-ID' => id_to_header ( call_id ) )
305
305
end
306
-
306
+
307
307
##
308
308
# Convert an id to a Content-ID header value.
309
309
#
@@ -319,7 +319,7 @@ def serialize_call(call_id, call)
319
319
def id_to_header ( call_id )
320
320
return '<%s+%s>' % [ @base_id , Addressable ::URI . encode ( call_id ) ]
321
321
end
322
-
322
+
323
323
end
324
324
end
325
325
end
0 commit comments