Search in sources :

Example 51 with ApiMethod

use of com.google.api.server.spi.config.ApiMethod in project iosched by google.

the class FcmSendEndpoint method sendSelfSync.

/**
 * Clients can initiate a sync on all of a user's devices. This will usually be called
 * when a client pushes a user data update to the server and wants other clients to
 * sync that change.
 *
 * @param context Servlet context (injected by Endpoints)
 * @param user User requesting the sync (injected by Endpoints)
 */
@ApiMethod(name = "sendSelfSync", path = "self")
public void sendSelfSync(ServletContext context, User user) throws UnauthorizedException {
    if (user == null) {
        throw new UnauthorizedException(INVALID_CREDENTIALS_MSG);
    }
    MessageSender sender = new MessageSender(context);
    String userId = user.getId();
    List<Device> devices = DeviceStore.findDevicesByUserId(userId);
    sender.multicastSend(devices, ACTION_SYNC_USER, null);
}
Also used : MessageSender(com.google.samples.apps.iosched.server.gcm.device.MessageSender) Device(com.google.samples.apps.iosched.server.gcm.db.models.Device) UnauthorizedException(com.google.api.server.spi.response.UnauthorizedException) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 52 with ApiMethod

use of com.google.api.server.spi.config.ApiMethod in project iosched by google.

the class FcmSendEndpoint method sendSessionDataSync.

/**
 * Ping all users' devices to sync session data.
 *
 * @param context Servlet context (injected by Endpoints)
 * @param user User making the request (injected by Endpoints)
 */
@ApiMethod(name = "sendSessionDataSync", path = "sessions", clientIds = { Ids.SERVICE_ACCOUNT_ANONOMYOUS_CLIENT_ID })
public void sendSessionDataSync(ServletContext context, User user) throws UnauthorizedException {
    validateServiceAccount(user);
    MessageSender sender = new MessageSender(context);
    List<Device> devices = DeviceStore.getAllDevices();
    sender.multicastSend(devices, ACTION_SYNC_SCHEDULE, null);
}
Also used : MessageSender(com.google.samples.apps.iosched.server.gcm.device.MessageSender) Device(com.google.samples.apps.iosched.server.gcm.db.models.Device) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 53 with ApiMethod

use of com.google.api.server.spi.config.ApiMethod in project iosched by google.

the class FcmSendEndpoint method sendUserSync.

/**
 * Ping a user's devices to sync user data. This is likely called when the server makes
 * a change to user data and wants the corresponding user's clients to sync.
 *
 * @param context Servlet context (injected by Endpoints)
 * @param user User making the request (injected by Endpoints)
 * @param userId ID of the user whose devices should sync.
 * @return SendUserSyncResult which contains the number of devices pinged.
 */
@ApiMethod(name = "sendUserSync", path = "users/{userId}", clientIds = { Ids.SERVICE_ACCOUNT_ANONOMYOUS_CLIENT_ID })
public SendUserSyncResult sendUserSync(ServletContext context, User user, @Named("userId") String userId) throws UnauthorizedException, NotFoundException {
    validateServiceAccount(user);
    MessageSender sender = new MessageSender(context);
    List<Device> devices = DeviceStore.findDevicesByUserId(userId);
    if (devices.isEmpty()) {
        throw new NotFoundException("No devices for user found");
    }
    sender.multicastSend(devices, ACTION_SYNC_USER, null);
    return new SendUserSyncResult(devices.size());
}
Also used : MessageSender(com.google.samples.apps.iosched.server.gcm.device.MessageSender) Device(com.google.samples.apps.iosched.server.gcm.db.models.Device) NotFoundException(com.google.api.server.spi.response.NotFoundException) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 54 with ApiMethod

use of com.google.api.server.spi.config.ApiMethod in project iosched by google.

the class FcmSendEndpoint method sendUserDataSync.

/**
 * Ping all users' devices to sync user data.
 *
 * @param context Servlet context (injected by Endpoints)
 * @param user User making the request (injected by Endpoints)
 */
@ApiMethod(name = "sendUserDataSync", path = "users", clientIds = { com.google.api.server.spi.Constant.API_EXPLORER_CLIENT_ID })
public void sendUserDataSync(ServletContext context, User user) throws UnauthorizedException {
    if (user == null) {
        throw new UnauthorizedException(INVALID_CREDENTIALS_MSG);
    }
    MessageSender sender = new MessageSender(context);
    List<Device> devices = DeviceStore.getAllDevices();
    sender.multicastSend(devices, ACTION_SYNC_USER, null);
}
Also used : MessageSender(com.google.samples.apps.iosched.server.gcm.device.MessageSender) Device(com.google.samples.apps.iosched.server.gcm.db.models.Device) UnauthorizedException(com.google.api.server.spi.response.UnauthorizedException) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Aggregations

ApiMethod (com.google.api.server.spi.config.ApiMethod)54 CryptonomicaUser (net.cryptonomica.entities.CryptonomicaUser)19 Gson (com.google.gson.Gson)16 UserData (com.google.samples.apps.iosched.server.userdata.db.UserData)10 PGPPublicKeyData (net.cryptonomica.entities.PGPPublicKeyData)10 ArrayList (java.util.ArrayList)9 StringWrapperObject (net.cryptonomica.returns.StringWrapperObject)9 NotFoundException (com.google.api.server.spi.response.NotFoundException)8 BadRequestException (com.google.api.server.spi.response.BadRequestException)7 UnauthorizedException (com.google.api.server.spi.response.UnauthorizedException)7 Queue (com.google.appengine.api.taskqueue.Queue)7 HTTPResponse (com.google.appengine.api.urlfetch.HTTPResponse)6 Device (com.google.samples.apps.iosched.server.gcm.db.models.Device)6 MessageSender (com.google.samples.apps.iosched.server.gcm.device.MessageSender)5 AppSettings (net.cryptonomica.entities.AppSettings)5 PGPPublicKeyGeneralView (net.cryptonomica.returns.PGPPublicKeyGeneralView)5 UserProfileGeneralView (net.cryptonomica.returns.UserProfileGeneralView)5 BookmarkedSession (com.google.samples.apps.iosched.server.userdata.db.BookmarkedSession)4 BooleanWrapperObject (net.cryptonomica.returns.BooleanWrapperObject)4 PGPPublicKey (org.bouncycastle.openpgp.PGPPublicKey)4