@ApiOperation(value = "Specify sharing details for a given connector – the structure of the specification object is connector specific")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Saved shared connector filter object")})
public Response saveSharedConnectorSettingsFilter(@ApiParam(value="ID of a connector instance", required=true) @PathParam("apiKeyId") long apiKeyId,
@ApiParam(value="The buddy's username", required=true) @PathParam("username") String username,
@ApiParam(value="Custom connector sharing specification", required=true) @FormParam("json") String json) {
final ApiKey apiKey = guestService.getApiKey(apiKeyId);
final long guestId = AuthHelper.getGuestId();
final long buddyId = guestService.getGuest(username).getId();
try {
if (apiKey.getGuestId()!=guestId)
throw new RuntimeException("attempt to retrieve ApiKey from another guest!");
final SharedConnector sharedConnector = buddiesService.getSharedConnector(apiKeyId, buddyId);
buddiesService.setSharedConnectorFilter(sharedConnector.getId(), json);
} catch (Throwable e) {
return Response.serverError().entity(e.getMessage()).build();