Would be great to support batching of requests via REST. In fact, enabling this is fairly trivial (though isn't directly
supported by the SDK's response validation). Here's needs to be changed to make request batching work:
1) To actually create batched requests:
params = {}
hits = [ "1ZDZY7Y7E2XMSJZYJWS0", "TW2ZZTY9422ZZ68YWKK0" ]
hits.each_with_index do |h, i|
params.store("GetHIT.#{i}.HITId", h )
end
@@mturk.GetHIT( params )
2) By default, 1) will generate a successful request but will bail on validating the results. To take care of that,
you must add the following code to mechanical_turk_error_handler.rb. Change this line (line 127 for me):
raise Util::ValidationException.new(response) unless result[:Request][:Errors].nil?
raise Util::ValidationException.new(response) unless resultHasErrors(result)
3) Add the following code to mechanical_turk_error_handler.rb immediately following the validateResponse(response) method
(for me, that's line 132):
def resultHasErrors(result)
this_result = [result].flatten
this_result.each do |r|
return true if r[:Request][:Errors].nil?
end
end
4) You will now be able to batch requests, and will receive a validation error if ANY of the requests fail. By changing
the behavior in resultHasErrors above you can adjust this behavior (if you'd prefer to have validation error thrown
only if ALL fail, for instance).
|