public function testCreateUniqueKeyRequest()
 {
     $client = $this->getMock('Google_Client');
     $datastore = new DatastoreHelper($client, 'test-dataset-id');
     $key = $datastore->createUniqueKeyRequest();
     $this->assertInstanceOf('Google_Service_Datastore_AllocateIdsRequest', $key);
 }
Example #2
0
    return new JsonResponse($messages);
});
$app->post('/receive_message', function () use($app) {
    /** @var Google_Client $client */
    $client = $app['google_client'];
    $projectId = $app['project_id'];
    // pull the message from the post body
    $json = $app['request']->getContent();
    $request = json_decode($json, true);
    if (!isset($request['message']['data']) || !($message = base64_decode($request['message']['data']))) {
        return new Response('', 400);
    }
    // Store the received message in datastore
    // For a more complete demo of datastore,
    // @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/datastore
    $datastore = new DatastoreHelper($client, $projectId);
    $datastore->storeMessage($message);
    return new Response();
});
$app->post('/send_message', function () use($app) {
    // send the pubsub message
    if ($messageText = $app['request']->get('message')) {
        /** @var Google_Client $client */
        $client = $app['google_client'];
        $projectName = sprintf('projects/%s', $app['project_id']);
        $topicName = sprintf('%s/topics/%s', $projectName, $app['topic']);
        $pubsub = new Google_Service_Pubsub($client);
        // create pubsub message object
        $message = new Google_Service_Pubsub_PubsubMessage();
        $message->setData(base64_encode($messageText));
        // create pubsub request