Sha256: 2fa1a3375dc01100a3c855d4d9b1fb298b647a02245e96d51d3f6de88aeaa766

Contents?: true

Size: 881 Bytes

Versions: 42

Compression:

Stored size: 881 Bytes

Contents

require 'jwt'
require_dependency "panda_pal/application_controller"

module PandaPal
  class ApiCallController < ApplicationController
    rescue_from StandardError do |err|
      render json: { status: 'error' }, status: 500
    end
    rescue_from ::JWT::DecodeError do |err|
      render json: { status: 'error', error: "Invalid JWT" }, status: 403
    end

    around_action do |blk|
      payload = ApiCall.decode_jwt(params[:token])
      org_id = payload['organization_id']
      if org_id
        PandaPal::Organization.find(org_id).switch_tenant do
          blk.call
        end
      else
        blk.call
      end
    end

    def call
      ac = ApiCall.from_jwt(params.require(:token))
      result = ac.call(params.to_unsafe_h)

      render json: {
        status: 'ok',
        uses_remaining: ac.uses_remaining,
        result: result,
      }
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
panda_pal-5.12.7 app/controllers/panda_pal/api_call_controller.rb
panda_pal-5.12.6 app/controllers/panda_pal/api_call_controller.rb
panda_pal-5.12.5 app/controllers/panda_pal/api_call_controller.rb
panda_pal-5.12.4 app/controllers/panda_pal/api_call_controller.rb
panda_pal-5.12.3 app/controllers/panda_pal/api_call_controller.rb
panda_pal-5.12.2 app/controllers/panda_pal/api_call_controller.rb
panda_pal-5.12.1 app/controllers/panda_pal/api_call_controller.rb
panda_pal-5.12.0 app/controllers/panda_pal/api_call_controller.rb
panda_pal-5.11.0 app/controllers/panda_pal/api_call_controller.rb
panda_pal-5.10.1 app/controllers/panda_pal/api_call_controller.rb
panda_pal-5.10.0 app/controllers/panda_pal/api_call_controller.rb
panda_pal-5.9.8.beta1 app/controllers/panda_pal/api_call_controller.rb
panda_pal-5.9.7 app/controllers/panda_pal/api_call_controller.rb
panda_pal-5.9.6 app/controllers/panda_pal/api_call_controller.rb
panda_pal-5.9.5 app/controllers/panda_pal/api_call_controller.rb
panda_pal-5.9.4 app/controllers/panda_pal/api_call_controller.rb
panda_pal-5.9.3 app/controllers/panda_pal/api_call_controller.rb
panda_pal-5.9.1 app/controllers/panda_pal/api_call_controller.rb
panda_pal-5.9.0 app/controllers/panda_pal/api_call_controller.rb
panda_pal-5.8.5 app/controllers/panda_pal/api_call_controller.rb