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);
}
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);
}
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());
}
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);
}
Aggregations