deliveries_controller.rb 691 B

123456789101112131415161718192021222324252627282930
  1. # frozen_string_literal: true
  2. class Api::V1::Crypto::DeliveriesController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :crypto }
  4. before_action :require_user!
  5. before_action :set_current_device
  6. def create
  7. devices.each do |device_params|
  8. DeliverToDeviceService.new.call(current_account, @current_device, device_params)
  9. end
  10. render_empty
  11. end
  12. private
  13. def set_current_device
  14. @current_device = Device.find_by!(access_token: doorkeeper_token)
  15. end
  16. def resource_params
  17. params.require(:device)
  18. params.permit(device: [:account_id, :device_id, :type, :body, :hmac])
  19. end
  20. def devices
  21. Array(resource_params[:device])
  22. end
  23. end