Sha256: 29109476c17c8c8c4a60e406e5a517f10af97457e53daacc5a101a6e3622114e
Contents?: true
Size: 1.55 KB
Versions: 3
Compression:
Stored size: 1.55 KB
Contents
# frozen_string_literal: true module Motor class RunApiRequestsController < ApiBaseController JWT_TTL = 2.hours wrap_parameters :data def show respond_with_result end def create respond_with_result end private # rubocop:disable Metrics/AbcSize def respond_with_result response = Motor::ApiConfigs.run(find_or_initialize_api_config, method: request_params[:method], path: request_params[:path], body: request_params[:body], params: request_params[:params], headers: { 'Authorization' => "Bearer #{current_user_jwt}" }) response.to_hash.each do |key, (value)| next if key.casecmp('transfer-encoding').zero? headers[key] = value end self.response_body = response.body self.status = response.code.to_i end # rubocop:enable Metrics/AbcSize def find_or_initialize_api_config Motor::ApiConfig.find_by(name: request_params[:api_config_name]) || Motor::ApiConfig.new(url: request_params[:api_config_name]) end def current_user_jwt return '' unless defined?(JWT) return '' unless current_user payload = { uid: current_user.id, email: current_user.email, exp: JWT_TTL.from_now.to_i } JWT.encode(payload, Rails.application.secrets.secret_key_base) end def request_params params.require(:data).permit! end end end
Version data entries
3 entries across 3 versions & 2 rubygems