batch_api icon indicating copy to clipboard operation
batch_api copied to clipboard

Would you give me some examples of requests?

Open kissrobber opened this issue 10 years ago • 6 comments

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?

kissrobber avatar Dec 15 '13 11:12 kissrobber

I'm having this exact same issue with a small sinatra app. It seems the middleware is coercing the arrays into hashes.

For reference: https://github.com/jetaggart/batch-api-example

This is how I'm trying to make a request: https://github.com/jetaggart/batch-api-example/blob/master/public/batch.js#L31-L40

jetaggart avatar Jan 19 '14 14:01 jetaggart

I'm doing this same thing. Was there a solution for you guys?

ishields avatar Sep 17 '14 21:09 ishields

I'm having this same problem. It's quite concerning to me that there hasn't been any updates here since Dec, 2013. Is this project being maintained/supported?

jeremyhaile avatar Jun 10 '15 14:06 jeremyhaile

@jetaggart what did you end up doing? Are you still using this gem?

jeremyhaile avatar Jun 10 '15 14:06 jeremyhaile

I opened a pull request for the fix described by @kissrobber

jeremyhaile avatar Jun 10 '15 15:06 jeremyhaile

It's been so long I don't even remember. I don't use this gem.

jetaggart avatar Jun 10 '15 17:06 jetaggart