@ApiOperation(value = "Export recipe", response = UIRecipe.class, authorizations = @Authorization(value = "master_key") ) @GET @Path("/export") public void exportUIRecipe(@HeaderParam("Accept") String contentType, @Named("user_id") Project project, RakamHttpRequest request) throws JsonProcessingException { request.bodyHandler(s -> { UIRecipe export = installer.export(project.userId, project.project); ExportType exportType = Arrays.stream(ExportType.values()) .filter(f -> f.contentType.equals(contentType)) .findAny() .orElse(ExportType.YAML); ByteBuf buffer; try { buffer = Unpooled.wrappedBuffer(exportType.mapper.writeValueAsBytes(export)); } catch (JsonProcessingException e) { throw Throwables.propagate(e); } DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buffer); response.headers().add(CONTENT_TYPE, exportType.contentType); if (request.headers().contains(ORIGIN)) { response.headers().set(ACCESS_CONTROL_ALLOW_ORIGIN, request.headers().get(ORIGIN)); } request.response(response).end(); }); }
@ApiOperation(value = "Export recipe", response = Recipe.class, authorizations = @Authorization(value = "master_key") ) @GET @Path("/export") public void exportRecipe(@HeaderParam("Accept") String contentType, @Named("project") RequestContext context, RakamHttpRequest request) throws JsonProcessingException { request.bodyHandler(s -> { Recipe export = installer.export(context.project); ExportType exportType = Arrays.stream(ExportType.values()) .filter(f -> f.contentType.equals(contentType)) .findAny() .orElse(YAML); ByteBuf buffer; try { buffer = Unpooled.wrappedBuffer(exportType.mapper.writeValueAsBytes(export)); } catch (JsonProcessingException e) { throw Throwables.propagate(e); } DefaultFullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, buffer); response.headers().add(CONTENT_TYPE, exportType.contentType); if (request.headers().contains(ORIGIN)) { response.headers().set(ACCESS_CONTROL_ALLOW_ORIGIN, request.headers().get(ORIGIN)); } request.response(response).end(); }); }
@JsonRequest @ProtectEndpoint(writeOperation = true, requiresProject = false) @Path("/coupon") public RakamCoupon checkCoupon( @ApiParam("coupon") String coupon, @HeaderParam("X-Requested-With") String csrfHeader, @javax.inject.Named("user_id") UIPermissionParameterProvider.Project project) { if (!"XMLHttpRequest".equals(csrfHeader)) { throw new RakamException(FORBIDDEN); } Optional<WebUser> webUser = service.getUser(project.userId); if (!webUser.isPresent() || webUser.get().readOnly) { throw new RakamException("User is not allowed to perform this operation", UNAUTHORIZED); } try { Coupon retrieve = Coupon.retrieve(coupon, requestOptions); return new RakamCoupon(retrieve.getPercentOff(), retrieve.getAmountOff()); } catch (InvalidRequestException e) { if (e.getStatusCode() == 404) { throw new RakamException(NOT_FOUND); } throw Throwables.propagate(e); } catch (StripeException e) { throw Throwables.propagate(e); } }
@Path("/me") public List<UserSubscription> me( @HeaderParam("X-Requested-With") String csrfHeader, @javax.inject.Named("user_id") UIPermissionParameterProvider.Project project) { if (!"XMLHttpRequest".equals(csrfHeader)) {
@ApiParam("plan") String plan, @javax.inject.Named("user_id") UIPermissionParameterProvider.Project project, @HeaderParam("X-Requested-With") String csrfHeader) { if (!"XMLHttpRequest".equals(csrfHeader)) { throw new RakamException(FORBIDDEN);
public void test( RakamHttpRequest request, @HeaderParam(CONTENT_TYPE) String contentType, @Named("project") RequestContext context, @ApiParam("script") String script,