CloudObjects / Directory / Firebase Integration / FCM Register API 1.0
Sign in

FCM Register API 1.0

a phpmae:ControllerClass, agws:WebAPI & phpmae:Class in Firebase Integration

The FCM Register API is used to store a device registration for Firebase Cloud Messaging on the Account Gateway. This API needs to be mounted for Android, iOS, Chrome or web applications that want to use FCM via CloudObjects.

Public PHP Methods
  • connect(Application $app)

    No documentation available.

Source Code
<?php

use Silex\Application, Silex\Api\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;

/**
 * Implementation for coid://firebase.cloudobjects.io/FCMRegisterAPI/1.0
 */
class FCMRegisterAPI implements ControllerProviderInterface {

  public function connect(Application $app) {
    $controllers = $app['controllers_factory'];

    $controllers->post('/storeRegistrationId', function(Request $r) use ($app) {
      if (!$r->request->has('registration_id'))
        $app->abort(400, "Parameter 'registration_id' required.");

      // Add attributes to account connection
      $connection = $app['context']->getAccountConnection($app['context']->getInstallQualifier());
      if (!isset($connection))
        $app->abort(500, "API was called without install qualifier.");

      $connection->setProperty('coid://firebase.cloudobjects.io/FCMEnabled', 'true');
      $connection->setProperty('coid://firebase.cloudobjects.io/FCMRegistrationId', $r->request->get('registration_id'));

      // Store data
      $app['context']->pushGraphUpdates();

      return $app->json(array(
        'ok' => true
      ));
    });

    return $controllers;
  }
}
Meta
URI / COID
coid://firebase.cloudobjects.io/FCMRegisterAPI/1.0 content_copy
Revision
6-ea01ed2965c9d018657194ef9f3deb4b content_copy
Last updated
2017-02-14 11:34 (UTC)
Usage permission
co:Public