<commit_before>module Paasal
  module API
    module V1
      class Calls < Grape::API
        helpers Paasal::SharedParamsHelper

        # TODO: define tests for both methods and some calls with varying http_methods
        # TODO: test with post, or anything else

        resource :endpoints do
          params do
            use :endpoint_id
          end
          resource ':endpoint_id/call' do
            route :any, '*path' do
              log.debug("Native endpoint call with params: #{params}")
              call_path = params.delete :path
              call_method = env['REQUEST_METHOD'].to_sym
              with_authentication { adapter.endpoint_call call_method, call_path, params }
            end
          end

          params do
            use :application_context
          end
          resource ':endpoint_id/applications/:application_id/call' do
            route :any, '*path' do
              log.debug("Native application call with params: #{params}")
              call_path = params.delete :path
              call_method = env['REQUEST_METHOD'].to_sym
              with_authentication do
                adapter.application_call(params[:application_id], call_method, call_path, params)
              end
            end<commit_msg>Updated native API call declarations to better fit the swagger-ui<commit_after>module Paasal
  module API
    module V1
      class Calls < Grape::API
        helpers Paasal::SharedParamsHelper

        helpers do
          params :api_call_path do
            requires :path, type: String, desc: 'The URL path to call at the endpoint'
          end
        end

        # TODO: test with post, or anything that requires a body

        resource :endpoints do
          %w(get post patch put delete).each do |http_method|
            desc "Execute a native #{http_method.upcase} API call against the endpoint"
            params do
              use :endpoint_id
              use :api_call_path
            end
            route http_method.to_sym, ':endpoint_id/call/*path' do
              log.debug("Native endpoint call with params: #{params}")
              call_path = params.delete :path
              call_method = env['REQUEST_METHOD'].to_sym
              with_authentication { adapter.endpoint_call call_method, call_path, params }
            end
          end

          %w(get post patch put delete).each do |http_method|
            desc "Execute a native #{http_method.upcase} API call against an endpoint's application"
            params do
              use :application_context
              use :api_call_path
            end
            route http_method.to_sym, ':endpoint_id/applications/:application_id/call/*path' do
              log.debug("Native application call with params: #{params}")
              call_path = params.delete :path
              call_method = env['REQUEST_METHOD'].to_sym
              with_authentication do
                adapter.application_call(params[:application_id], call_method, call_path, params)
              end
            end
{'fraction_non_alphanumeric': 0.06736429038587312, 'fraction_numerical': 0.0006540222367560497, 'mean_word_length': 1.8940397350993377, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '959841', 'n_tokens_mistral': 764, 'n_tokens_neox': 750, 'n_words': 240}