-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Description
For example, I tried this request by reference to https://developers.facebook.com/docs/graph-api/making-multiple-requests/
curl -F 'ops=[{"method":"GET", "url":"/api/tags"},{"method":"GET", "url":"/api/notes"}]' -F 'sequential=1' http://localhost:3000/batch
Then, I got this error
"Only 50 operations can be submitted at once, 77 were provided"
By changing like this, it works well.
module BatchApi
class Processor
.....
def process_ops
ops = @request.params.delete("ops")
ops = JSON.parse(ops) # ← json parse
if !ops || ops.empty?
raise Errors::NoOperationsError, "No operations provided"
elsif ops.length > BatchApi.config.limit
raise Errors::OperationLimitExceeded,
"Only #{BatchApi.config.limit} operations can be submitted at once, " +
"#{ops.length} were provided"
else
ops.map do |op|
self.class.operation_klass.new(op, @env, @app)
end
end
end
Sending a request by using jQuery post method to my rails app as below.
$.post('/batch',
{ops:[
{method: "get", url: "/api/tags"},
{method: "get", url: "/api/notes"}
],
sequential: true
},
function(){
console.log(arguments)
});
Then, I got this error
{"error":{"message":"can't convert String into Integer","backtrace":[" .... /batch_api/lib/batch_api/operation/rack.rb:16:in `[]' ...
By changing like this, it works well.
module BatchApi
class Processor
.....
def process_ops
ops = @request.params.delete("ops")
if !ops || ops.empty?
raise Errors::NoOperationsError, "No operations provided"
elsif ops.length > BatchApi.config.limit
raise Errors::OperationLimitExceeded,
"Only #{BatchApi.config.limit} operations can be submitted at once, " +
"#{ops.length} were provided"
else
ops.values.map do |op| # ← call values before map
self.class.operation_klass.new(op, @env, @app)
end
end
end
But it should work without any changes.
Would you give me some examples of requests?
Metadata
Metadata
Assignees
Labels
No labels