<commit_before>module TelphinApi
  # A low-level module which handles the requests to Telphin API and returns their results as mashes.
  #
  # It uses Faraday with middleware underneath the hood.
  module API
    class << self
      # API method call.
      # @param [String] full_method A full name of the method.
      # @param [Hash] args Method arguments.
      # @param [String] token The access token.
      # @return [Hashie::Mash] Mashed server response.
      def call(full_method, args = {}, token = nil)
        namespace = full_method.first
        action = full_method.last

        http_method = args.delete(:http_method)
        http_method ||= :get

        user_id = args.delete(:user_id)
        extension_number = args.delete(:extension_number)
        id = args.delete(:id)

        flat_arguments = Utils.flatten_arguments(args)
        url = [TelphinApi.site, namespace, user_id, extension_number, action].join('/')
        url = url + '/' + id unless id.nil?
        connection = connection(url: url, token: token)

        if flat_arguments.empty?
          connection.send(http_method).body
        else
          connection.send(http_method, flat_arguments).body
        end
      end

      # Faraday connection.
      # @param [Hash] options Connection options.
      # @option options [String] :url Connection URL (either full or just prefix).
      # @option options [String] :token OAuth2 access token (not used if omitted).
      # @return [Faraday::Connection] Created connection.
      def connection(options = {})
        url = options.delete(:url)
        token = options.delete(:token)
        url = url + '?accessRequestToken=' + token

        Faraday.new(url, TelphinApi.faraday_options) do |builder|
          builder.request :multipart
          builder.request :url_encoded
          builder.request :retry, TelphinApi.max_retries

          builder.response :telphin_logger
          builder.response :mashify
          builder.response :multi_json, preserve_raw: true

          builder.adapter TelphinApi.adapter
        end
      end
    end<commit_msg>fixes with api to send post request<commit_after>module TelphinApi
  # A low-level module which handles the requests to Telphin API and returns their results as mashes.
  #
  # It uses Faraday with middleware underneath the hood.
  module API
    class << self
      # API method call.
      # @param [String] full_method A full name of the method.
      # @param [Hash] args Method arguments.
      # @param [String] token The access token.
      # @return [Hashie::Mash] Mashed server response.
      def call(full_method, args = {}, token = nil)
        namespace = full_method.first
        action = full_method.last

        http_method = args.delete(:http_method)
        http_method ||= :get

        user_id = args.delete(:user_id)
        extension_number = args.delete(:extension_number)

        id = args.delete(:id)
        url = [namespace, user_id, extension_number, action].join('/')
        url = url + '/' + id unless id.nil?

        flat_arguments = Utils.flatten_arguments(args)
        flat_arguments = flat_arguments.to_json.to_s if http_method == :post

        connection(url: TelphinApi.site, token: token, method: http_method).send(http_method, url, flat_arguments).body
      end

      # Faraday connection.
      # @param [Hash] options Connection options.
      # @option options [String] :url Connection URL (either full or just prefix).
      # @option options [String] :token OAuth2 access token (not used if omitted).
      # @return [Faraday::Connection] Created connection.
      def connection(options = {})
        url = options.delete(:url)
        token = options.delete(:token)
        method = options.delete(:method)

        Faraday.new(url, TelphinApi.faraday_options) do |builder|
          builder.headers['Authorization'] = "Bearer #{token}"
          if method == :post
            builder.headers['Content-Type'] = 'application/json'
          end

          builder.request :multipart
          builder.request :url_encoded
          builder.request :retry, TelphinApi.max_retries

          builder.response :telphin_logger
          builder.response :mashify
          builder.response :multi_json, preserve_raw: true

          builder.adapter TelphinApi.adapter
        end
      end
    end
{'fraction_non_alphanumeric': 0.09316770186335403, 'fraction_numerical': 0.00046008741660915573, 'mean_word_length': 2.54071661237785, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4496511', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1189, 'n_words': 352}