Skip to content

Would you give me some examples of requests? #25

Description

@kjosk

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions