public function testInvalidBatchRequest() { $client = $this->getClient(); $batch = new Postman_Google_Http_Batch($client); $this->plus = new Postman_Google_Service_Plus($client); $client->setUseBatch(true); $batch->add($this->plus->people->get('123456789987654321'), 'key1'); $batch->add($this->plus->people->get('+LarryPage'), 'key2'); $result = $batch->execute(); $this->assertTrue(isset($result['response-key2'])); $this->assertInstanceOf('Postman_Google_Service_Exception', $result['response-key1']); }
To actually make the batch call we need to enable batching on the client - this will apply globally until we set it to false. This causes call to the service methods to return the query rather than immediately executing. ************************************************/ $client->setUseBatch(true); /************************************************ We then create a batch, and add each query we want to execute with keys of our choice - these keys will be reflected in the returned array. ************************************************/ $batch = new Postman_Google_Http_Batch($client); $optParams = array('filter' => 'free-ebooks'); $req1 = $service->volumes->listVolumes('Henry David Thoreau', $optParams); $batch->add($req1, "thoreau"); $req2 = $service->volumes->listVolumes('George Bernard Shaw', $optParams); $batch->add($req2, "shaw"); /************************************************ Executing the batch will send all requests off at once. ************************************************/ $results = $batch->execute(); echo "<h3>Results Of Call 1:</h3>"; foreach ($results['response-thoreau'] as $item) { echo $item['volumeInfo']['title'], "<br /> \n"; } echo "<h3>Results Of Call 2:</h3>"; foreach ($results['response-shaw'] as $item) { echo $item['volumeInfo']['title'], "<br /> \n"; }