google-api-nodejs-client icon indicating copy to clipboard operation
google-api-nodejs-client copied to clipboard

batch commands in 0.4.1

Open afirstenberg opened this issue 13 years ago • 4 comments

Commands that are called using a direct command work, while using the same command with the batch commands fail.

For example, this function sets up a client mirror subscription command (in a module later required as "glass"):

exports.subscribeGlassCallbacksCmd = function( user ){
  var baseUrl = exports.BASE_URL;
  var subscribeUrl = baseUrl+"/incoming/callback";
  if( subscribeUrl.indexOf("http:") === 0 ){
    subscribeUrl = "https://mirrornotifications.appspot.com/forward?url="+subscribeUrl;
  }

  // Subscribe to updates from Glass
  var subscription = {
    collection: "timeline",
    callbackUrl: subscribeUrl,
    userToken: user.id
  };
  console.log( 'subscribeGlassCallbacksCmd', subscription );

  var cmd = client.mirror.subscriptions.insert(subscription);
  return cmd;
};

Calling it directly using these commands appear to work:

    var subc = glass.subscribeGlassCallbacksCmd(req.user);
    subc.withAuthClient(req.user.auth).execute(function(err,result){
      console.log( 'subc', err, result );
    });

err is null and result is set to the JSON representing the subscription:

subc null { kind: 'mirror#subscription',
  id: 'timeline',
  updated: '2013-08-06T11:33:56.772Z',
  collection: 'timeline',
  callbackUrl: 'https://prisoner.com/dev/glass-drive/incoming/callback',
  userToken: '101852559274654726533' }

Calling it using the following batch commands, however, don't:

    var batch = client.newBatchRequest();
    batch.add( glass.subscribeGlassCallbacksCmd(req.user) );
    batch.withAuthClient(req.user.auth).execute(cb);

the error that gets returned is

{ errors: 
   [ { domain: 'global',
       reason: 'required',
       message: 'collection field is required for Subscription' },
     { domain: 'global',
       reason: 'required',
       message: 'callbackUrl field is required for Subscription' } ],
  code: 400,
  message: 'collection field is required for Subscription' }

I've tried other combinations of the parameters to the call to list, but they don't appear to work any better.

afirstenberg avatar Aug 06 '13 17:08 afirstenberg

@afirstenberg, batch is experimental at the moment is not faster than making individual requests alone. Could you use async.parallel or github.com/visionmedia/batch instead of clien'ts OData batch implementation while this is being fixed?

rakyll avatar Aug 06 '13 17:08 rakyll

Yup, I'll probably be trying to implement it with async.parallel instead. I knew batch was a work in progress, but wanted to document the issue in case it helped document how to improve it.

afirstenberg avatar Aug 06 '13 19:08 afirstenberg

any progress on this issue?

travischoma avatar Apr 11 '14 21:04 travischoma

We've removed support for batch requests in version 1.0.0 so this is now a WONTFIX.

ryanseys avatar Jul 22 '14 20:07 ryanseys