Feature Requests: Browse | Submit New | Admin

[#16663] Batch REST Request Support

Date:
2007-12-28 07:19
Priority:
3
Submitted By:
James Blair (jbjamesblair)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
Batch REST Request Support

Detailed description
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).


Add A Comment: Notepad

Please login


Followup

No Followups Have Been Posted

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item